diff options
author | James E. Blair <corvus@gnu.org> | 2009-08-10 21:39:55 -0700 |
---|---|---|
committer | James E. Blair <corvus@gnu.org> | 2009-08-10 21:39:55 -0700 |
commit | e839b8f71b5353339b354ea78248bd5c74ab348a (patch) | |
tree | bd625e2cb0ba1d104667bb38a30478b96ca54c8e | |
parent | 55234867a38b0ade58691560987e4b9d18e522a4 (diff) |
Remove separate linkback table (just variants of comments now).
Add function to generate trackback RDF.
-rw-r--r-- | quoins/controllers.py | 42 | ||||
-rw-r--r-- | quoins/model/blog.py | 38 |
2 files changed, 37 insertions, 43 deletions
diff --git a/quoins/controllers.py b/quoins/controllers.py index 5605c61..ac3cef7 100644 --- a/quoins/controllers.py +++ b/quoins/controllers.py | |||
@@ -294,13 +294,15 @@ class Pingback(TGController): | |||
294 | return xmlrpclib.Fault(0x20, 'Post not found.') | 294 | return xmlrpclib.Fault(0x20, 'Post not found.') |
295 | elif not post.allow_comments: | 295 | elif not post.allow_comments: |
296 | return xmlrpclib.Fault(0x31, 'Comments are closed on this post.') | 296 | return xmlrpclib.Fault(0x31, 'Comments are closed on this post.') |
297 | for lb in post.linkbacks: | 297 | for lb in post.comments: |
298 | if lb.url == sourceURI: | 298 | if lb.url and lb.url == sourceURI: |
299 | return xmlrpclib.Fault(0x30, 'Pingback already registered.') | 299 | return xmlrpclib.Fault(0x30, 'Pingback already registered.') |
300 | lb = LinkBack() | 300 | lb = Comment() |
301 | DBSession.add(lb) | 301 | lb.approved = True |
302 | lb.type = 'pingback' | ||
302 | lb.post = post | 303 | lb.post = post |
303 | lb.url = sourceURI | 304 | lb.url = sourceURI |
305 | post.comments.append(lb) | ||
304 | return 'Linkback recorded.' | 306 | return 'Linkback recorded.' |
305 | 307 | ||
306 | def post_paginate(start, posts, size): | 308 | def post_paginate(start, posts, size): |
@@ -360,6 +362,25 @@ class BlogController(TGController): | |||
360 | def get_html(self, data): | 362 | def get_html(self, data): |
361 | return HTML(data) | 363 | return HTML(data) |
362 | 364 | ||
365 | def get_trackback_rdf(self, post, comment=True): | ||
366 | rdf = """ | ||
367 | <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | ||
368 | xmlns:dc="http://purl.org/dc/elements/1.1/" | ||
369 | xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"> | ||
370 | <rdf:Description | ||
371 | rdf:about="%s" | ||
372 | dc:identifier="%s" | ||
373 | dc:title="%s" | ||
374 | trackback:ping="%s" | ||
375 | </rdf:RDF>\n""" | ||
376 | rdf = rdf % (self.absolute_url('/'), | ||
377 | self.absolute_url(post), | ||
378 | post.title, | ||
379 | self.absolute_url('/trackback/%s'%post.id)) | ||
380 | if comment: | ||
381 | rdf = "<!-- "+rdf+" -->" | ||
382 | return HTML(rdf) | ||
383 | |||
363 | def send_comment_email(self, comment): | 384 | def send_comment_email(self, comment): |
364 | post = comment.post | 385 | post = comment.post |
365 | blog = post.blog | 386 | blog = post.blog |
@@ -480,6 +501,7 @@ Comment: | |||
480 | def post(self, id): | 501 | def post(self, id): |
481 | post = DBSession.query(Post).get(id) | 502 | post = DBSession.query(Post).get(id) |
482 | if not post: abort(404) | 503 | if not post: abort(404) |
504 | print pylons.request.headers | ||
483 | pylons.response.headers['X-Pingback']=self.absolute_url('/pingback/') | 505 | pylons.response.headers['X-Pingback']=self.absolute_url('/pingback/') |
484 | return dict(quoins = self, | 506 | return dict(quoins = self, |
485 | blog = post.blog, | 507 | blog = post.blog, |
@@ -550,8 +572,8 @@ Comment: | |||
550 | pass | 572 | pass |
551 | 573 | ||
552 | c = Comment() | 574 | c = Comment() |
553 | c.post = post | ||
554 | post.comments.append(c) | 575 | post.comments.append(c) |
576 | c.post = post | ||
555 | c.body = body | 577 | c.body = body |
556 | if request.identity: | 578 | if request.identity: |
557 | c.author=request.identity['user'] | 579 | c.author=request.identity['user'] |
@@ -869,17 +891,19 @@ Comment: | |||
869 | message = 'Post not found.' | 891 | message = 'Post not found.' |
870 | elif not post.allow_comments: | 892 | elif not post.allow_comments: |
871 | message = 'Comments are closed on this post.' | 893 | message = 'Comments are closed on this post.' |
872 | for lb in post.linkbacks: | 894 | for lb in post.comments: |
873 | if lb.url == url: | 895 | if lb.url and lb.url == url: |
874 | message = 'Trackback already registered.' | 896 | message = 'Trackback already registered.' |
875 | if not message: | 897 | if not message: |
876 | lb = LinkBack() | 898 | lb = Comment() |
877 | DBSession.add(lb) | 899 | lb.approved = True |
900 | lb.type = 'trackback' | ||
878 | lb.post = post | 901 | lb.post = post |
879 | lb.url = url | 902 | lb.url = url |
880 | lb.title = title | 903 | lb.title = title |
881 | lb.name = blog_name | 904 | lb.name = blog_name |
882 | lb.body = excerpt | 905 | lb.body = excerpt |
906 | post.comments.append(lb) | ||
883 | if message: | 907 | if message: |
884 | error = 1 | 908 | error = 1 |
885 | message = "<message>%s</message>\n" % message | 909 | message = "<message>%s</message>\n" % message |
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 | |||
94 | linkback_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 | ||
105 | class Blog(object): | 95 | class 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 | |||
189 | class Media(object): | 169 | class Media(object): |
190 | pass | 170 | pass |
191 | 171 | ||
192 | class Tag(object): | 172 | class Tag(object): |
193 | pass | 173 | pass |
194 | 174 | ||
195 | class BaseComment(object): | 175 | class 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 | |||
206 | class Comment(BaseComment): | ||
207 | comment_type = 'comment' | ||
208 | |||
209 | class LinkBack(BaseComment): | ||
210 | comment_type = 'linkback' | ||
211 | 185 | ||
212 | mapper(Blog, blog_table, | 186 | mapper(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 | ||
249 | mapper(Comment, comment_table, | 222 | mapper(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 | |||
254 | mapper(LinkBack, linkback_table, | ||
255 | properties=dict(post=relation(Post))) | ||