From: Eevee Date: Fri, 23 Oct 2009 02:27:57 +0000 (-0700) Subject: Added parent property/links for comments, and a Return link on comment threads. X-Git-Url: http://git.veekun.com/zzz-floof.git/commitdiff_plain/dc9ecbad36153af00773b4951120b4697b33193e?ds=sidebyside;hp=-c Added parent property/links for comments, and a Return link on comment threads. --- dc9ecbad36153af00773b4951120b4697b33193e diff --git a/floof/model/comments.py b/floof/model/comments.py index bcfee9f..5e57c14 100644 --- a/floof/model/comments.py +++ b/floof/model/comments.py @@ -12,6 +12,8 @@ def indent_comments(comments): The first comment's indent level is 0. The comments must be a complete subtree, ordered by their `left` property. + + This function will also cache the `parent` property for each comment. """ last_comment = None @@ -103,3 +105,16 @@ class Comment(Entity): self.left = max_right + 1 self.right = max_right + 2 + @property + def parent(self): + """Returns this comment's parent. This is cached, hence its being a + property and not a method. + """ + if not hasattr(self, '_parent'): + self._parent = Comment.query \ + .filter(Comment.discussion_id == self.discussion_id) \ + .filter(Comment.left < self.left) \ + .filter(Comment.right > self.right) \ + .order_by(Comment.left.desc()) \ + .first() + return self._parent diff --git a/floof/templates/comments/lib.mako b/floof/templates/comments/lib.mako index 0c8ebfb..e822a17 100644 --- a/floof/templates/comments/lib.mako +++ b/floof/templates/comments/lib.mako @@ -13,11 +13,21 @@ ${single_comment(comment)} <%def name="single_comment(comment)"> +% if hasattr(comment, 'indent'):
+% else: +
+% endif
${comment.user.name}
${comment.time}
- +

${comment.text}

diff --git a/floof/templates/comments/thread.mako b/floof/templates/comments/thread.mako index 359c296..947c500 100644 --- a/floof/templates/comments/thread.mako +++ b/floof/templates/comments/thread.mako @@ -1,6 +1,8 @@ <%inherit file="/base.mako" /> <%namespace name="comments" file="/comments/lib.mako" /> +

« Return

+ % if c.root_comment: ${comments.single_comment(c.root_comment)} % endif