summaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorJelle van der Waa <jelle@vdwaa.nl>2016-11-30 21:40:31 +0100
committerJelle van der Waa <jelle@vdwaa.nl>2017-05-02 21:13:56 +0200
commit9ae767cb4faf8d8d58630cd4716d946abcc9653a (patch)
treea12c529ba640c095190a2c09125aed0fa80a6031 /main
parent0b714e47d27d1a5f32635f144c7ad1f7bc1635a2 (diff)
downloadarchweb-9ae767cb4faf8d8d58630cd4716d946abcc9653a.tar.gz
archweb-9ae767cb4faf8d8d58630cd4716d946abcc9653a.zip
port templates/packages to pure django
Diffstat (limited to 'main')
-rw-r--r--main/templatetags/details_link.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/main/templatetags/details_link.py b/main/templatetags/details_link.py
new file mode 100644
index 00000000..b94f8487
--- /dev/null
+++ b/main/templatetags/details_link.py
@@ -0,0 +1,77 @@
+from urllib import urlencode, quote as urlquote, unquote
+from django import template
+from main.templatetags import pgp
+
+register = template.Library()
+
+
+def link_encode(url, query):
+ # massage the data into all utf-8 encoded strings first, so urlencode
+ # doesn't barf at the data we pass it
+ query = {k: unicode(v).encode('utf-8') for k, v in query.items()}
+ data = urlencode(query)
+ return "%s?%s" % (url, data)
+
+
+@register.inclusion_tag('packages/details_link.html')
+def details_link(pkg):
+ return {'pkg': pkg}
+
+
+@register.simple_tag
+def scm_link(package, operation):
+ parts = (package.repo.svn_root, operation, package.pkgbase)
+ linkbase = (
+ "https://projects.archlinux.org/svntogit/%s.git/%s/trunk?"
+ "h=packages/%s")
+ return linkbase % tuple(urlquote(part.encode('utf-8')) for part in parts)
+
+
+@register.simple_tag
+def bugs_list(package):
+ url = "https://bugs.archlinux.org/"
+ data = {
+ 'project': package.repo.bugs_project,
+ 'cat[]': package.repo.bugs_category,
+ 'string': package.pkgname,
+ }
+ return link_encode(url, data)
+
+
+@register.simple_tag
+def bug_report(package):
+ url = "https://bugs.archlinux.org/newtask"
+ data = {
+ 'project': package.repo.bugs_project,
+ 'product_category': package.repo.bugs_category,
+ 'item_summary': '[%s] PLEASE ENTER SUMMARY' % package.pkgname,
+ }
+ return link_encode(url, data)
+
+
+@register.simple_tag
+def wiki_link(package):
+ url = "https://wiki.archlinux.org/index.php/Special:Search"
+ data = {
+ 'search': package.pkgname,
+ }
+ return link_encode(url, data)
+
+
+@register.simple_tag
+def pgp_key_link(key_id, link_text=None):
+ return pgp.pgp_key_link(key_id, link_text)
+
+
+@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
+
+# vim: set ts=4 sw=4 et: