summaryrefslogtreecommitdiff
path: root/packages/templatetags
diff options
context:
space:
mode:
authorJohannes Krampf <johannes.krampf@gmail.com>2011-11-26 14:27:45 +0100
committerJohannes Krampf <johannes.krampf@gmail.com>2011-11-26 14:27:45 +0100
commit56c773b32fc68639eb55666b6cfaa32bc9618321 (patch)
treedcc047f0552224facb6d05cddf2fb72b973bd683 /packages/templatetags
parentfbd23db51b7160a308cd88e407e676994eb08b10 (diff)
parent85657db05d7f65604340699cfcb9967c9e81a0ef (diff)
Merged with archweb trunk
Diffstat (limited to 'packages/templatetags')
-rw-r--r--packages/templatetags/package_extras.py48
1 files changed, 45 insertions, 3 deletions
diff --git a/packages/templatetags/package_extras.py b/packages/templatetags/package_extras.py
index d4d0ca1a..fc2201e5 100644
--- a/packages/templatetags/package_extras.py
+++ b/packages/templatetags/package_extras.py
@@ -1,4 +1,4 @@
-from urllib import urlencode, quote as urlquote
+from urllib import urlencode, quote as urlquote, unquote
try:
from urlparse import parse_qs
except ImportError:
@@ -9,6 +9,21 @@ from django.utils.html import escape
register = template.Library()
+def link_encode(url, query, doseq=False):
+ data = urlencode(query, doseq).replace('&', '&amp;')
+ return "%s?%s" % (url, data)
+
+@register.filter
+def url_unquote(original_url):
+ try:
+ url = original_url
+ if isinstance(url, unicode):
+ url = url.encode('ascii')
+ url = unquote(url).decode('utf-8')
+ return url
+ except UnicodeError:
+ return original_url
+
class BuildQueryStringNode(template.Node):
def __init__(self, sortfield):
self.sortfield = sortfield
@@ -37,6 +52,15 @@ def do_buildsortqs(parser, token):
return BuildQueryStringNode(sortfield[1:-1])
@register.simple_tag
+def pkg_details_link(pkg):
+ template = '<a href="%s" title="View package details for %s">%s</a>'
+ return template % (pkg.get_absolute_url(), pkg.pkgname, pkg.pkgname)
+
+@register.simple_tag
+def multi_pkg_details(pkgs):
+ return ', '.join([pkg_details_link(pkg) for pkg in pkgs])
+
+@register.simple_tag
def userpkgs(user):
if user:
# TODO don't hardcode
@@ -48,22 +72,40 @@ 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):
+ url = "https://bugs.parabolagnulinux.org/bugs/issue?"
data = {
'@action': 'search',
'title': package.pkgname,
}
- return "https://bugs.parabolagnulinux.org/bugs/issue?%s" % urlencode(data)
+ return link_encode(url, data)
@register.simple_tag
def bug_report(package):
+ url = "https://bugs.parabolagnulinux.org/bugs/issue?"
data = {
'@template': 'item',
'keyword': 'packages',
'title': '[%s]' % package.pkgname,
}
- return "https://bugs.parabolagnulinux.org/bugs/issue?%s" % urlencode(data)
+ return link_encode(url, data)
@register.simple_tag
def flag_unfree(package):