diff options
author | Dan McGee <dan@archlinux.org> | 2012-12-28 14:44:09 -0600 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2012-12-28 14:48:29 -0600 |
commit | ee507a5b81d7a21eaa67da4c848522a5a97d2e3c (patch) | |
tree | a48e7b8c27ab27aaa055d40e90efdbfa093a6ad5 /todolists | |
parent | 20b64e42672d185821cc584dfa4b133ee259a144 (diff) |
Add a todolist package details link template tag
Given the way we retrieve certain related objects, it makes more sense
to use a custom tag here rather than our generic package details link
tag. When viewing a large todolist, this saves significantly on the
number of queries we need to build the page.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'todolists')
-rw-r--r-- | todolists/templatetags/__init__.py | 0 | ||||
-rw-r--r-- | todolists/templatetags/todolists.py | 19 |
2 files changed, 19 insertions, 0 deletions
diff --git a/todolists/templatetags/__init__.py b/todolists/templatetags/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/todolists/templatetags/__init__.py diff --git a/todolists/templatetags/todolists.py b/todolists/templatetags/todolists.py new file mode 100644 index 00000000..5f31dc1f --- /dev/null +++ b/todolists/templatetags/todolists.py @@ -0,0 +1,19 @@ +from django import template + +register = template.Library() + + +def pkg_absolute_url(repo, arch, pkgname): + return '/packages/%s/%s/%s/' % (repo.name.lower(), arch.name, pkgname) + + +@register.simple_tag +def todopkg_details_link(todopkg): + pkg = todopkg.pkg + if not pkg: + return todopkg.pkgname + link = '<a href="%s" title="View package details for %s">%s</a>' + url = pkg_absolute_url(todopkg.repo, todopkg.arch, pkg.pkgname) + return link % (url, pkg.pkgname, pkg.pkgname) + +# vim: set ts=4 sw=4 et: |