summaryrefslogtreecommitdiff
path: root/quoins/model/blog.py
diff options
context:
space:
mode:
Diffstat (limited to 'quoins/model/blog.py')
-rw-r--r--quoins/model/blog.py38
1 files changed, 4 insertions, 34 deletions
diff --git a/quoins/model/blog.py b/quoins/model/blog.py
index fb1fa27..a7415d6 100644
--- a/quoins/model/blog.py
+++ b/quoins/model/blog.py
@@ -89,17 +89,7 @@ comment_table = Table('comment', metadata,
89 Column('body', TEXT), 89 Column('body', TEXT),
90 Column('created', DateTime, nullable=False, default=datetime.now), 90 Column('created', DateTime, nullable=False, default=datetime.now),
91 Column('approved', Boolean, nullable=False, default=False, index=True), 91 Column('approved', Boolean, nullable=False, default=False, index=True),
92) 92 Column('type', String(16), nullable=False, default='comment', index=True),
93
94linkback_table = Table('linkback', metadata,
95 Column('id', Integer, primary_key=True),
96 Column('post_id', Integer, ForeignKey('post.id',
97 onupdate="CASCADE", ondelete="CASCADE"), nullable=False, index=True),
98 Column('url', String(255)),
99 Column('title', Unicode(255)),
100 Column('body', Unicode(255)),
101 Column('name', Unicode(255)),
102 Column('created', DateTime, nullable=False, default=datetime.now),
103) 93)
104 94
105class Blog(object): 95class Blog(object):
@@ -176,25 +166,15 @@ class Post(object):
176 DBSession.delete(t) 166 DBSession.delete(t)
177 self.tags.remove(t) 167 self.tags.remove(t)
178 168
179 def get_comments_and_linkbacks(self, trackbacks=1, pingbacks=1):
180 objects = self.approved_comments[:]
181 for x in self.linkbacks:
182 if (trackbacks and x.body) or (pingbacks and not x.body):
183 objects.append(x)
184 objects.sort(lambda a,b: cmp(a.created, b.created))
185 return objects
186 comments_and_links = property(get_comments_and_linkbacks)
187
188
189class Media(object): 169class Media(object):
190 pass 170 pass
191 171
192class Tag(object): 172class Tag(object):
193 pass 173 pass
194 174
195class BaseComment(object): 175class Comment(object):
196 def get_author_name(self): 176 def get_author_name(self):
197 if hasattr(self, 'author') and self.author: 177 if self.author:
198 return self.author.display_name 178 return self.author.display_name
199 if self.name: 179 if self.name:
200 return self.name 180 return self.name
@@ -202,12 +182,6 @@ class BaseComment(object):
202 return self.url 182 return self.url
203 return 'Anonymous' 183 return 'Anonymous'
204 author_name = property(get_author_name) 184 author_name = property(get_author_name)
205
206class Comment(BaseComment):
207 comment_type = 'comment'
208
209class LinkBack(BaseComment):
210 comment_type = 'linkback'
211 185
212mapper(Blog, blog_table, 186mapper(Blog, blog_table,
213 properties=dict(posts=relation(Post, 187 properties=dict(posts=relation(Post,
@@ -243,13 +217,9 @@ mapper(Post, post_table,
243 unapproved_comments=relation(Comment, 217 unapproved_comments=relation(Comment,
244 primaryjoin=and_(comment_table.c.post_id==post_table.c.id, 218 primaryjoin=and_(comment_table.c.post_id==post_table.c.id,
245 comment_table.c.approved==False)), 219 comment_table.c.approved==False)),
246 media=relation(Media), 220 media=relation(Media)))
247 linkbacks=relation(LinkBack)))
248 221
249mapper(Comment, comment_table, 222mapper(Comment, comment_table,
250 order_by=comment_table.c.created, 223 order_by=comment_table.c.created,
251 properties=dict(post=relation(Post), 224 properties=dict(post=relation(Post),
252 author=relation(TGUser))) 225 author=relation(TGUser)))
253
254mapper(LinkBack, linkback_table,
255 properties=dict(post=relation(Post)))