summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2013-02-03 14:40:41 -0600
committerDan McGee <dan@archlinux.org>2013-02-03 14:40:41 -0600
commitd63a800348f81823f157ec9ed03f9985308c3ea3 (patch)
tree548c7db54c9b8ca4456d1f6c39f5d8fd7f2b2cf0
parent7e6279057a57ef44c11349e594ad392fbfce0098 (diff)
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 <dan@archlinux.org>
-rw-r--r--main/templatetags/pgp.py17
-rw-r--r--templates/public/keys.html4
2 files changed, 13 insertions, 8 deletions
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.conf import settings
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 '<a href="%s" title="PGP key search for %s">%s</a>' % 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)
diff --git a/templates/public/keys.html b/templates/public/keys.html
index 35bf414c..cf8ac784 100644
--- a/templates/public/keys.html
+++ b/templates/public/keys.html
@@ -124,8 +124,8 @@
<tbody>
{% for sig in cross_signatures %}
<tr>
- <td>{% user_pgp_key_link active_users sig.signer %}</td>
- <td>{% user_pgp_key_link active_users sig.signee %}</td>
+ <td>{% user_pgp_key_link sig.signer %}</td>
+ <td>{% user_pgp_key_link sig.signee %}</td>
<td>{{ sig.created }}</td>
<td>{{ sig.expires|default:"" }}</td>
</tr>