From 29dee9e8c20f4fe1a9e0ec91bc8ae64ed4115761 Mon Sep 17 00:00:00 2001 From: hernani Date: Sat, 17 Apr 2010 01:28:20 +0000 Subject: [PATCH] added comment headline property git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@45 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/models/comment.py | 4 +++ forum/templatetags/user_tags.py | 49 +++++++++++++++++---------------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/forum/models/comment.py b/forum/models/comment.py index 2bf2824..15049b2 100644 --- a/forum/models/comment.py +++ b/forum/models/comment.py @@ -15,6 +15,10 @@ class Comment(Node): def comment(self): return self.body + @property + def headline(self): + return self.absolute_parent.headline + @property def content_object(self): return self.parent.leaf diff --git a/forum/templatetags/user_tags.py b/forum/templatetags/user_tags.py index 0e9ae27..cf35a2e 100644 --- a/forum/templatetags/user_tags.py +++ b/forum/templatetags/user_tags.py @@ -34,29 +34,32 @@ class ActivityNode(template.Node): self.activity = template.Variable(activity) def render(self, context): - activity = self.activity.resolve(context) - - context = { - 'active_at': activity.active_at, - 'description': activity.type_as_string, - 'type': activity.activity_type, - } - - if activity.activity_type == const.TYPE_ACTIVITY_PRIZE: - context['badge'] = True - context['title'] = activity.content_object.badge.name - context['url'] = activity.content_object.badge.get_absolute_url() - context['badge_type'] = activity.content_object.badge.type - else: - context['title'] = activity.node.headline - context['url'] = activity.node.get_absolute_url() - - if activity.activity_type in (const.TYPE_ACTIVITY_UPDATE_ANSWER, const.TYPE_ACTIVITY_UPDATE_QUESTION): - context['revision'] = True - context['summary'] = activity.content_object.summary or \ - _('Revision n. %(rev_number)d') % {'rev_number': activity.content_object.revision} - - return self.template.render(template.Context(context)) + try: + activity = self.activity.resolve(context) + + context = { + 'active_at': activity.active_at, + 'description': activity.type_as_string, + 'type': activity.activity_type, + } + + if activity.activity_type == const.TYPE_ACTIVITY_PRIZE: + context['badge'] = True + context['title'] = activity.content_object.badge.name + context['url'] = activity.content_object.badge.get_absolute_url() + context['badge_type'] = activity.content_object.badge.type + else: + context['title'] = activity.node.headline + context['url'] = activity.node.get_absolute_url() + + if activity.activity_type in (const.TYPE_ACTIVITY_UPDATE_ANSWER, const.TYPE_ACTIVITY_UPDATE_QUESTION): + context['revision'] = True + context['summary'] = activity.content_object.summary or \ + _('Revision n. %(rev_number)d') % {'rev_number': activity.content_object.revision} + + return self.template.render(template.Context(context)) + except Exception, e: + return '' @register.tag def activity_item(parser, token): -- 2.39.5