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
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
</%def>
<%def name="single_comment(comment)">
+% if hasattr(comment, 'indent'):
<div class="comment" style="margin-left: ${comment.indent}em;">
+% else:
+<div class="comment">
+% endif
<div class="header">
<div class="user">${comment.user.name}</div>
<div class="time">${comment.time}</div>
- <div class="link"><a href="${url(controller='comments', action='thread', id=comment.id, owner_url=h.get_comment_owner_url(**c.route))}">Link</a></div>
+ <div class="links">
+ <a href="${url(controller='comments', action='thread', id=comment.id, owner_url=h.get_comment_owner_url(**c.route))}">Link</a>
+ <a href="${url(controller='comments', action='reply', id=comment.id, owner_url=h.get_comment_owner_url(**c.route))}">Reply</a>
+ % if comment.parent:
+ <a href="${url(controller='comments', action='thread', id=comment.parent.id, owner_url=h.get_comment_owner_url(**c.route))}">Parent</a>
+ % endif
+ </div>
</div>
<p>${comment.text}</p>
</div>
<%inherit file="/base.mako" />
<%namespace name="comments" file="/comments/lib.mako" />
+<p><a href="/${c.owner_url}">« Return</a></p>
+
% if c.root_comment:
${comments.single_comment(c.root_comment)}
% endif