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 --- templates/devel/index.html | 3 ++- templates/todolists/public_list.html | 4 ++-- templates/todolists/view.html | 4 ++-- todolists/templatetags/__init__.py | 0 todolists/templatetags/todolists.py | 19 +++++++++++++++++++ 5 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 todolists/templatetags/__init__.py create mode 100644 todolists/templatetags/todolists.py diff --git a/templates/devel/index.html b/templates/devel/index.html index 57151041..6d304409 100644 --- a/templates/devel/index.html +++ b/templates/devel/index.html @@ -2,6 +2,7 @@ {% load static from staticfiles %} {% load cache %} {% load package_extras %} +{% load todolists %} {% block title %}Arch Linux - Developer Dashboard{% endblock %} @@ -61,7 +62,7 @@ {{ todopkg.todolist.name }} - {% pkg_details_link todopkg.pkg %} + {% todopkg_details_link todopkg %} {{ todopkg.repo.name }} {{ todopkg.arch.name }} {{ todopkg.pkg.maintainers|join:', ' }} diff --git a/templates/todolists/public_list.html b/templates/todolists/public_list.html index 41caf5b0..da99bc01 100644 --- a/templates/todolists/public_list.html +++ b/templates/todolists/public_list.html @@ -1,6 +1,6 @@ {% extends "base.html" %} {% load static from staticfiles %} -{% load package_extras %} +{% load todolists %} {% block title %}Arch Linux - Todo Lists{% endblock %} @@ -45,7 +45,7 @@ {% for pkg in list.packages %} - {% pkg_details_link pkg.pkg pkg.pkgname %} + {% todopkg_details_link pkg %} {{ pkg.arch.name }} {{ pkg.repo.name|capfirst }} {{ pkg.maintainers|join:', ' }} diff --git a/templates/todolists/view.html b/templates/todolists/view.html index 66bbec6f..89a05126 100644 --- a/templates/todolists/view.html +++ b/templates/todolists/view.html @@ -1,6 +1,6 @@ {% extends "base.html" %} {% load static from staticfiles %} -{% load package_extras %} +{% load todolists %} {% block title %}Arch Linux - Todo: {{ list.name }}{% endblock %} @@ -71,7 +71,7 @@ {{ pkg.arch.name }} {{ pkg.repo.name|capfirst }} - {% pkg_details_link pkg.pkg pkg.pkgname %} + {% todopkg_details_link pkg %} {% if pkg.pkg.flag_date %} {{ pkg.pkg.full_version }} {% else %} diff --git a/todolists/templatetags/__init__.py b/todolists/templatetags/__init__.py new file mode 100644 index 00000000..e69de29b 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 = '%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-55-g3dc8