1 from django import template
\r
2 from django.utils.translation import ugettext as _
\r
3 from django.utils.safestring import mark_safe
\r
4 from forum.forms import AwardPointsForm
\r
7 register = template.Library()
\r
9 class UserSignatureNode(template.Node):
\r
10 template = template.loader.get_template('users/signature.html')
\r
12 def __init__(self, user, format):
\r
13 self.user = template.Variable(user)
\r
14 self.format = template.Variable(format)
\r
16 def render(self, context):
\r
17 return self.template.render(template.Context({
\r
18 'user': self.user.resolve(context),
\r
19 'format': self.format.resolve(context)
\r
23 def user_signature(parser, token):
\r
25 tag_name, user, format = token.split_contents()
\r
27 raise template.TemplateSyntaxError, "%r tag requires exactly two arguments" % token.contents.split()[0]
\r
29 return UserSignatureNode(user, format)
\r
32 class ActivityNode(template.Node):
\r
33 template = template.loader.get_template('users/activity.html')
\r
35 def __init__(self, activity, viewer):
\r
36 self.activity = template.Variable(activity)
\r
37 self.viewer = template.Variable(viewer)
\r
39 def render(self, context):
\r
41 action = self.activity.resolve(context).leaf()
\r
42 viewer = self.viewer.resolve(context)
\r
43 describe = mark_safe(action.describe(viewer))
\r
44 return self.template.render(template.Context(dict(action=action, describe=describe)))
\r
45 except Exception, e:
\r
46 logging.error("Error in %s action describe: %s" % (action.action_type, str(e)))
\r
49 def activity_item(parser, token):
\r
51 tag_name, activity, viewer = token.split_contents()
\r
53 raise template.TemplateSyntaxError, "%r tag requires exactly two arguments" % token.contents.split()[0]
\r
55 return ActivityNode(activity, viewer)
\r
58 @register.inclusion_tag('users/menu.html')
\r
59 def user_menu(request, user):
\r
60 return dict(viewer=request.user, user=user)
\r