From ee507a5b81d7a21eaa67da4c848522a5a97d2e3c Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 28 Dec 2012 14:44:09 -0600 Subject: 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 --- todolists/templatetags/__init__.py | 0 todolists/templatetags/todolists.py | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 todolists/templatetags/__init__.py create mode 100644 todolists/templatetags/todolists.py (limited to 'todolists') diff --git a/todolists/templatetags/__init__.py b/todolists/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/todolists/templatetags/todolists.py b/todolists/templatetags/todolists.py new file mode 100644 index 0000000..5f31dc1 --- /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 = '%s' + url = pkg_absolute_url(todopkg.repo, todopkg.arch, pkg.pkgname) + return link % (url, pkg.pkgname, pkg.pkgname) + +# vim: set ts=4 sw=4 et: -- cgit v1.2.3-24-g4f1b