]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/templatetags/user_tags.py
ALteration of the schema to a single content model. As a bonus there is a complete...
[osqa.git] / forum / templatetags / user_tags.py
index c880c231d36e7a0e0641a126f117d3f37b573b78..f50917a161304c6924ee8dd6ed307c22eab09c93 100644 (file)
@@ -1,4 +1,6 @@
 from django import template\r
+from django.utils.translation import ugettext as _\r
+from forum import const\r
 \r
 register = template.Library()\r
 \r
@@ -23,3 +25,50 @@ def user_signature(parser, token):
         raise template.TemplateSyntaxError, "%r tag requires exactly two arguments" % token.contents.split()[0]\r
 \r
     return UserSignatureNode(user, format)\r
+\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