diff options
author | Dan McGee <dan@archlinux.org> | 2012-03-08 07:37:07 +0100 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2012-03-08 07:37:07 +0100 |
commit | 314608aee372c890031cd89f556327a93a2538e6 (patch) | |
tree | 37966449ea4da6fa59c7f4d69121dd82e3a3b148 /main | |
parent | 94be52f1bb320206524d2f0f4ad79968ca437727 (diff) | |
download | archweb-314608aee372c890031cd89f556327a93a2538e6.tar.gz archweb-314608aee372c890031cd89f556327a93a2538e6.tar.xz |
Allow more flexibility in pgp_key_link
Allow key_id to be a large integer value that gets converted to hex, and
allow overriding of the default link text.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'main')
-rw-r--r-- | main/templatetags/pgp.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/main/templatetags/pgp.py b/main/templatetags/pgp.py index d69e291..1ffc524 100644 --- a/main/templatetags/pgp.py +++ b/main/templatetags/pgp.py @@ -16,17 +16,28 @@ def format_key(key_id): return u'0x%s' % key_id @register.simple_tag -def pgp_key_link(key_id): +def pgp_key_link(key_id, link_text=None): if not key_id: return "Unknown" + if isinstance(key_id, (int, long)): + key_id = '%X' % key_id + # zero-fill to nearest 8, 16, or 40 chars if necessary + if len(key_id) <= 8: + key_id = key_id.zfill(8) + elif len(key_id) <= 16: + key_id = key_id.zfill(16) + elif len(key_id) <= 40: + key_id = key_id.zfill(40) # Something like 'pgp.mit.edu:11371' 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' % \ (pgp_server, key_id) - values = (url, format_key(key_id), key_id[-8:]) - return '<a href="%s" title="PGP key search for %s">0x%s</a>' % values + if link_text is None: + link_text = '0x%s' % key_id[-8:] + values = (url, format_key(key_id), link_text) + return '<a href="%s" title="PGP key search for %s">%s</a>' % values @register.filter def pgp_fingerprint(key_id, autoescape=True): |