1 from django import template
\r
2 from django.utils.translation import ugettext as _
\r
3 from forum import const
\r
5 register = template.Library()
\r
7 class UserSignatureNode(template.Node):
\r
8 template = template.loader.get_template('users/signature.html')
\r
10 def __init__(self, user, format):
\r
11 self.user = template.Variable(user)
\r
12 self.format = template.Variable(format)
\r
14 def render(self, context):
\r
15 return self.template.render(template.Context({
\r
16 'user': self.user.resolve(context),
\r
17 'format': self.format.resolve(context)
\r
21 def user_signature(parser, token):
\r
23 tag_name, user, format = token.split_contents()
\r
25 raise template.TemplateSyntaxError, "%r tag requires exactly two arguments" % token.contents.split()[0]
\r
27 return UserSignatureNode(user, format)
\r
30 class ActivityNode(template.Node):
\r
31 template = template.loader.get_template('users/activity.html')
\r
33 def __init__(self, activity):
\r
34 self.activity = template.Variable(activity)
\r
36 def render(self, context):
\r
38 activity = self.activity.resolve(context)
\r
41 'active_at': activity.active_at,
\r
42 'description': activity.type_as_string,
\r
43 'type': activity.activity_type,
\r
46 if activity.activity_type == const.TYPE_ACTIVITY_PRIZE:
\r
47 context['badge'] = True
\r
48 context['title'] = activity.content_object.badge.name
\r
49 context['url'] = activity.content_object.badge.get_absolute_url()
\r
50 context['badge_type'] = activity.content_object.badge.type
\r
52 context['title'] = activity.node.headline
\r
53 context['url'] = activity.node.get_absolute_url()
\r
55 if activity.activity_type in (const.TYPE_ACTIVITY_UPDATE_ANSWER, const.TYPE_ACTIVITY_UPDATE_QUESTION):
\r
56 context['revision'] = True
\r
57 context['summary'] = activity.content_object.summary or \
\r
58 _('Revision n. %(rev_number)d') % {'rev_number': activity.content_object.revision}
\r
60 return self.template.render(template.Context(context))
\r
61 except Exception, e:
\r
65 def activity_item(parser, token):
\r
67 tag_name, activity = token.split_contents()
\r
69 raise template.TemplateSyntaxError, "%r tag requires exactly one arguments" % token.contents.split()[0]
\r
71 return ActivityNode(activity)
\r