summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2010-07-28 15:02:17 -0500
committerDan McGee <dan@archlinux.org>2010-07-28 15:02:17 -0500
commit2461b12cef1665e6c84c96caf53ff8775092e530 (patch)
tree32e9fcb0f380f706f8caf299f0edb02115328c62 /packages
parent88eb925d03b938d761c80d945171db91735e9e2a (diff)
Add new 'userpkgs' template tag
For easy linking to a given person's packages when we have a user object. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'packages')
-rw-r--r--packages/templatetags/package_extras.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/packages/templatetags/package_extras.py b/packages/templatetags/package_extras.py
index ff66a9f2..66ba31a7 100644
--- a/packages/templatetags/package_extras.py
+++ b/packages/templatetags/package_extras.py
@@ -30,3 +30,25 @@ def do_buildsortqs(parser, token):
"%r tag's argument should be in quotes" % tagname)
return BuildQueryStringNode(sortfield[1:-1])
+@register.tag
+def userpkgs(parser, token):
+ try:
+ tagname, user = token.split_contents()
+ except ValueError:
+ raise template.TemplateSyntaxError(
+ "%r tag requires a single argument" % tagname)
+ return UserPkgsNode(user)
+
+class UserPkgsNode(template.Node):
+ def __init__(self, user):
+ self.user = template.Variable(user)
+
+ def render(self, context):
+ try:
+ real_user = self.user.resolve(context)
+ # TODO don't hardcode
+ return '<a href="/packages/search/?maintainer=%s">%s</a>' % (
+ real_user.username, real_user.get_full_name())
+ except template.VariableDoesNotExist:
+ return ''
+ pass