1 from django import template
\r
2 from django.utils.translation import ugettext as _
\r
3 from django.utils.safestring import mark_safe
\r
6 register = template.Library()
\r
8 class UserSignatureNode(template.Node):
\r
9 template = template.loader.get_template('users/signature.html')
\r
11 def __init__(self, user, format):
\r
12 self.user = template.Variable(user)
\r
13 self.format = template.Variable(format)
\r
15 def render(self, context):
\r
16 return self.template.render(template.Context({
\r
17 'user': self.user.resolve(context),
\r
18 'format': self.format.resolve(context)
\r
22 def user_signature(parser, token):
\r
24 tag_name, user, format = token.split_contents()
\r
26 raise template.TemplateSyntaxError, "%r tag requires exactly two arguments" % token.contents.split()[0]
\r
28 return UserSignatureNode(user, format)
\r
31 class ActivityNode(template.Node):
\r
32 template = template.loader.get_template('users/activity.html')
\r
34 def __init__(self, activity, viewer):
\r
35 self.activity = template.Variable(activity)
\r
36 self.viewer = template.Variable(viewer)
\r
38 def render(self, context):
\r
40 action = self.activity.resolve(context).leaf
\r
41 viewer = self.viewer.resolve(context)
\r
42 describe = mark_safe(action.describe(viewer))
\r
43 return self.template.render(template.Context(dict(action=action, describe=describe)))
\r
44 except Exception, e:
\r
46 msg = "Error in action describe: \n %s" % (
\r
47 traceback.format_exc()
\r
52 def activity_item(parser, token):
\r
54 tag_name, activity, viewer = token.split_contents()
\r
56 raise template.TemplateSyntaxError, "%r tag requires exactly two arguments" % token.contents.split()[0]
\r
58 return ActivityNode(activity, viewer)
\r
62 def flagged_item(parser, token):
\r
64 tag_name, post, viewer = token.split_contents()
\r
66 raise template.TemplateSyntaxError, "%r tag requires exactly two arguments" % token.contents.split()[0]
\r
68 return ActivityNode(post, viewer)
\r
71 @register.inclusion_tag('users/menu.html')
\r
72 def user_menu(viewer, user):
\r
73 return dict(viewer=viewer, user=user)
\r