From d63a800348f81823f157ec9ed03f9985308c3ea3 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 3 Feb 2013 14:40:41 -0600 Subject: Update user_pgp_key_link template tag to use DeveloperKey model The first of several small updates to use the new data we have available. Signed-off-by: Dan McGee --- main/templatetags/pgp.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'main') diff --git a/main/templatetags/pgp.py b/main/templatetags/pgp.py index 581282b4..afad9df2 100644 --- a/main/templatetags/pgp.py +++ b/main/templatetags/pgp.py @@ -3,8 +3,11 @@ from django.utils.html import conditional_escape from django.utils.safestring import mark_safe +from devel.models import DeveloperKey + register = template.Library() + def format_key(key_id): if len(key_id) in (8, 20): return u'0x%s' % key_id @@ -40,12 +43,14 @@ def pgp_key_link(key_id, link_text=None): return '%s' % values @register.simple_tag -def user_pgp_key_link(users, key_id): - matched = [user for user in users if user.userprofile.pgp_key and - user.userprofile.pgp_key[-16:] == key_id[-16:]] - if matched and len(matched) == 1: - return pgp_key_link(key_id, matched[0].get_full_name()) - return pgp_key_link(key_id) +def user_pgp_key_link(key_id): + normalized = key_id[-16:] + try: + matching_key = DeveloperKey.objects.select_related( + 'owner').get(key=normalized, owner_id__isnull=False) + except DeveloperKey.DoesNotExist: + return pgp_key_link(key_id) + return pgp_key_link(key_id, matching_key.owner.get_full_name()) @register.filter(needs_autoescape=True) -- cgit v1.2.3-54-g00ecf