diff options
author | Dan McGee <dan@archlinux.org> | 2011-04-19 06:26:10 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-04-19 06:26:13 +0200 |
commit | f1f01ecf0216441dd66f3bc6afc14fe104de291f (patch) | |
tree | e9cb94fdbbc92c29f40bde47b05b6f1020e4549b /packages | |
parent | d8022fd5720a8367a03bbff58668ed701a0bebcf (diff) | |
download | archweb-f1f01ecf0216441dd66f3bc6afc14fe104de291f.tar.gz archweb-f1f01ecf0216441dd66f3bc6afc14fe104de291f.tar.xz |
Reimplement links code as template tags
These were starting to get a bit too much inside the model itself, and
they don't really belong there as they are view layer concerns anyway.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'packages')
-rw-r--r-- | packages/templatetags/package_extras.py | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/packages/templatetags/package_extras.py b/packages/templatetags/package_extras.py index dd5b934..e089b72 100644 --- a/packages/templatetags/package_extras.py +++ b/packages/templatetags/package_extras.py @@ -1,4 +1,4 @@ -import urllib +from urllib import urlencode, quote as urlquote try: from urlparse import parse_qs except ImportError: @@ -22,7 +22,7 @@ class BuildQueryStringNode(template.Node): qs['sort'] = ['-' + self.sortfield] else: qs['sort'] = [self.sortfield] - return urllib.urlencode(qs, True) + return urlencode(qs, True) @register.tag(name='buildsortqs') def do_buildsortqs(parser, token): @@ -48,4 +48,37 @@ def userpkgs(user): ) return '' + +def svn_link(package, svnpath): + '''Helper function for the two real SVN link methods.''' + parts = (package.repo.svn_root, package.pkgbase, svnpath) + linkbase = "http://projects.archlinux.org/svntogit/%s.git/tree/%s/%s/" + return linkbase % tuple(urlquote(part) for part in parts) + +@register.simple_tag +def svn_arch(package): + repo = package.repo.name.lower() + return svn_link(package, "repos/%s-%s" % (repo, package.arch.name)) + +@register.simple_tag +def svn_trunk(package): + return svn_link(package, "trunk") + +@register.simple_tag +def bugs_list(package): + data = { + 'project': package.repo.bugs_project, + 'string': package.pkgname, + } + return "https://bugs.archlinux.org/?%s" % urlencode(data) + +@register.simple_tag +def bug_report(package): + data = { + 'project': package.repo.bugs_project, + 'product_category': package.repo.bugs_category, + 'item_summary': '[%s]' % package.pkgname, + } + return "https://bugs.archlinux.org/newtask?%s" % urlencode(data) + # vim: set ts=4 sw=4 et: |