diff options
author | Dan McGee <dan@archlinux.org> | 2011-01-13 21:32:57 +0100 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-01-13 21:32:57 +0100 |
commit | 6285c379bac3fa05ecb3ccaccbe981d3573e290a (patch) | |
tree | d18d8aff9660122c43eeec951d90ef8a23efd821 /packages | |
parent | 176d1619023e542cf25a9a52cc61df638df8dd67 (diff) | |
download | archweb-6285c379bac3fa05ecb3ccaccbe981d3573e290a.tar.gz archweb-6285c379bac3fa05ecb3ccaccbe981d3573e290a.tar.xz |
Make userpkgs a simple_tag
Cleans up the code a decent amount.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'packages')
-rw-r--r-- | packages/templatetags/package_extras.py | 37 |
1 files changed, 12 insertions, 25 deletions
diff --git a/packages/templatetags/package_extras.py b/packages/templatetags/package_extras.py index 3cd2b91..d59a556 100644 --- a/packages/templatetags/package_extras.py +++ b/packages/templatetags/package_extras.py @@ -31,29 +31,16 @@ 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) +@register.simple_tag +def userpkgs(user): + if user: + # TODO don't hardcode + title = escape('View packages maintained by ' + user.get_full_name()) + return '<a href="/packages/?maintainer=%s" title="%s">%s</a>' % ( + user.username, + title, + user.get_full_name(), + ) + return '' - def render(self, context): - try: - real_user = self.user.resolve(context) - # TODO don't hardcode - title = escape('View packages maintained by ' + real_user.get_full_name()) - return '<a href="/packages/search/?maintainer=%s" title="%s">%s</a>' % ( - real_user.username, - title, - real_user.get_full_name(), - ) - except template.VariableDoesNotExist: - return '' - pass +# vim: set ts=4 sw=4 et: |