diff options
author | Dan McGee <dan@archlinux.org> | 2011-11-17 13:32:42 -0600 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-11-17 13:32:42 -0600 |
commit | f43a33ed8696d7bcb987d4878c6411c5d16846d6 (patch) | |
tree | 2f3553e5190f7d390a108ec20c1ebcd92ea74224 /packages | |
parent | 3a0e55a1de6fb42aaa0deece68cccba8ebb83cc8 (diff) |
Display package URLs unquoted if possible
Example: kbd-ru-keymaps.
Before: http://wiki.archlinux.org/index.php/%D0%98%D0%BD%D1%82%D0%B5%D1%80%D0%BD%D0%B0%D1%86%D0%B8%D0%BE%D0%BD%D0%B0%D0%BB%D0%B8%D0%B7%D0%B0%D1%86%D0%B8%D1%8F
After: http://wiki.archlinux.org/index.php/Интернационализация
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'packages')
-rw-r--r-- | packages/templatetags/package_extras.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/packages/templatetags/package_extras.py b/packages/templatetags/package_extras.py index 01bf7510..67c7fbbc 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: @@ -13,6 +13,17 @@ def link_encode(url, query, doseq=False): data = urlencode(query, doseq).replace('&', '&') 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 |