summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-06-21 08:56:50 -0500
committerDan McGee <dan@archlinux.org>2011-06-21 08:56:50 -0500
commitdcbee21c1ba281b061db302056c771936925c824 (patch)
tree96e16779c59b9c6bf3485db20ad616177cc5814d
parent92e13e0670661a542db646c668780cb4620c0b13 (diff)
Nicer formatting of PGP key display value
Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--main/templatetags/pgp.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/main/templatetags/pgp.py b/main/templatetags/pgp.py
index d9126dbd..956de892 100644
--- a/main/templatetags/pgp.py
+++ b/main/templatetags/pgp.py
@@ -3,6 +3,17 @@ from django.conf import settings
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:
+ # normal display format is 5 groups of 4 hex chars seperated by spaces,
+ # double space, then 5 more groups of 4 hex chars
+ split = tuple(key_id[i:i+4] for i in range(0, 40, 4))
+ return u'%s&nbsp; %s' % (' '.join(split[0:5]), ' '.join(split[5:10]))
+ return u'0x%s' % key_id
+
@register.simple_tag
def pgp_key_link(key_id):
if not key_id:
@@ -10,10 +21,10 @@ def pgp_key_link(key_id):
# Something like 'pgp.mit.edu:11371'
pgp_server = getattr(settings, 'PGP_SERVER', None)
if not pgp_server:
- return "0x%s" % key_id
+ return format_key(key_id)
url = 'http://%s/pks/lookup?op=vindex&fingerprint=on&exact=on&search=0x%s' % \
(pgp_server, key_id)
- values = (url, key_id, key_id)
- return '<a href="%s" title="PGP key search for 0x%s">0x%s</a>' % values
+ values = (url, key_id, format_key(key_id))
+ return '<a href="%s" title="PGP key search for 0x%s">%s</a>' % values
# vim: set ts=4 sw=4 et: