diff options
Diffstat (limited to 'main/templatetags')
-rw-r--r-- | main/templatetags/cdn.py | 7 | ||||
-rw-r--r-- | main/templatetags/pgp.py | 20 |
2 files changed, 17 insertions, 10 deletions
diff --git a/main/templatetags/cdn.py b/main/templatetags/cdn.py index c25040c0..5cb12fcf 100644 --- a/main/templatetags/cdn.py +++ b/main/templatetags/cdn.py @@ -23,12 +23,7 @@ class CDNPrefixNode(template.Node): oncdn = getattr(settings, 'CDN_ENABLED', True) if not oncdn: return '' - secure = 'secure' in context and context['secure'] # if left undefined, same behavior as if CDN is turned off - paths = { - False: getattr(settings, 'CDN_PATH', ''), - True: getattr(settings, 'CDN_PATH_SECURE', ''), - } - return paths[secure] + return getattr(settings, 'CDN_PATH', '') # vim: set ts=4 sw=4 et: diff --git a/main/templatetags/pgp.py b/main/templatetags/pgp.py index 956de892..d69e2918 100644 --- a/main/templatetags/pgp.py +++ b/main/templatetags/pgp.py @@ -1,10 +1,11 @@ from django import template from django.conf import settings +from django.utils.html import conditional_escape +from django.utils.safestring import mark_safe register = template.Library() def format_key(key_id): - print len(key_id) if len(key_id) in (8, 20): return u'0x%s' % key_id elif len(key_id) == 40: @@ -22,9 +23,20 @@ def pgp_key_link(key_id): pgp_server = getattr(settings, 'PGP_SERVER', None) if not pgp_server: return format_key(key_id) - url = 'http://%s/pks/lookup?op=vindex&fingerprint=on&exact=on&search=0x%s' % \ + url = 'http://%s/pks/lookup?op=vindex&fingerprint=on&exact=on&search=0x%s' % \ (pgp_server, key_id) - values = (url, key_id, format_key(key_id)) - return '<a href="%s" title="PGP key search for 0x%s">%s</a>' % values + values = (url, format_key(key_id), key_id[-8:]) + return '<a href="%s" title="PGP key search for %s">0x%s</a>' % values + +@register.filter +def pgp_fingerprint(key_id, autoescape=True): + if not key_id: + return u'' + if autoescape: + esc = conditional_escape + else: + esc = lambda x: x + return mark_safe(format_key(esc(key_id))) +pgp_fingerprint.needs_autoescape = True # vim: set ts=4 sw=4 et: |