1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 from mediagoblin
.db
.base
import Base
20 from mediagoblin
.db
.models
import Collection
, User
, MediaEntry
21 from mediagoblin
.db
.mixin
import GenerateSlugMixin
23 from mediagoblin
.media_types
.blog
.lib
import check_blog_slug_used
25 from mediagoblin
.tools
.text
import cleaned_markdown_conversion
27 from sqlalchemy
import (
28 Column
, Integer
, ForeignKey
, Unicode
, UnicodeText
, DateTime
)
29 from sqlalchemy
.orm
import relationship
, backref
32 class BlogMixin(GenerateSlugMixin
):
33 def check_slug_used(self
, slug
):
34 return check_blog_slug_used(self
.author
, slug
, self
.id)
36 class Blog(Base
, BlogMixin
):
37 __tablename__
= "mediatype__blogs"
38 id = Column(Integer
, primary_key
=True)
39 title
= Column(Unicode
)
40 description
= Column(UnicodeText
)
41 author
= Column(Integer
, ForeignKey(User
.id), nullable
=False, index
=True) #similar to uploader
42 created
= Column(DateTime
, nullable
=False, default
=datetime
.datetime
.now
, index
=True)
43 slug
= Column(Unicode
)
46 BACKREF_NAME
= "blogpost__media_data"
48 class BlogPostData(Base
):
49 __tablename__
= "blogpost__mediadata"
51 # The primary key *and* reference to the main media_entry
52 media_entry
= Column(Integer
, ForeignKey('core__media_entries.id'), primary_key
=True)
53 blog
= Column(Integer
, ForeignKey('mediatype__blogs.id'), nullable
=False)
54 get_media_entry
= relationship("MediaEntry",
55 backref
=backref(BACKREF_NAME
, uselist
=False,
56 cascade
="all, delete-orphan"))
59 DATA_MODEL
= BlogPostData
60 MODELS
= [BlogPostData
, Blog
]