+\r
+\r
+class ActivityNode(template.Node):\r
+ template = template.loader.get_template('users/activity.html')\r
+\r
+ def __init__(self, activity):\r
+ self.activity = template.Variable(activity)\r
+\r
+ def render(self, context):\r
+ activity = self.activity.resolve(context)\r
+\r
+ context = {\r
+ 'active_at': activity.active_at,\r
+ 'description': activity.type_as_string,\r
+ 'type': activity.activity_type,\r
+ }\r
+\r
+ try:\r
+ if activity.activity_type == const.TYPE_ACTIVITY_PRIZE:\r
+ context['badge'] = True\r
+ context['title'] = activity.content_object.badge.name\r
+ context['url'] = activity.content_object.badge.get_absolute_url()\r
+ context['badge_type'] = activity.content_object.badge.type\r
+ else:\r
+ context['title'] = activity.node.headline\r
+ context['url'] = activity.node.get_absolute_url()\r
+\r
+ if activity.activity_type in (const.TYPE_ACTIVITY_UPDATE_ANSWER, const.TYPE_ACTIVITY_UPDATE_QUESTION):\r
+ context['revision'] = True\r
+ context['summary'] = activity.content_object.summary or \\r
+ _('Revision n. %(rev_number)d') % {'rev_number': activity.content_object.revision}\r
+ except Exception, e:\r
+ import sys, traceback\r
+ traceback.print_exc(file=sys.stdout)\r
+ pass\r
+\r
+\r
+ return self.template.render(template.Context(context))\r
+\r
+@register.tag\r
+def activity_item(parser, token):\r
+ try:\r
+ tag_name, activity = token.split_contents()\r
+ except ValueError:\r
+ raise template.TemplateSyntaxError, "%r tag requires exactly one arguments" % token.contents.split()[0]\r
+\r
+ return ActivityNode(activity)\r