diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2012-11-15 10:54:14 -0500 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2012-11-15 10:54:14 -0500 |
commit | 3d122f711a481e2357d53ffee9e091a4581b8df6 (patch) | |
tree | 3d9ea3ccbeb5be44ab48d06413d8b56ac84eb465 /main | |
parent | bd86ba0d5f5b07ba114134b3c12f8f4843e52ec4 (diff) | |
parent | 7edc58c89c78d2e7c4f646e4b8562bc52ad7218d (diff) |
Merge commit '7edc58c' (requires new parabolaweb-update)
Show signature data on package details page
Conflicts:
requirements.txt
requirements_prod.txt
Diffstat (limited to 'main')
-rw-r--r-- | main/models.py | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/main/models.py b/main/models.py index 15a92662..4f2d64ea 100644 --- a/main/models.py +++ b/main/models.py @@ -1,3 +1,9 @@ +from base64 import b64decode +from datetime import datetime +from itertools import groupby +from pgpdump import BinaryData +import pytz + from django.db import models from django.contrib.auth.models import User from django.contrib.sites.models import Site @@ -5,10 +11,6 @@ from django.contrib.sites.models import Site from .fields import PositiveBigIntegerField, PGPKeyField from .utils import cache_function, make_choice, set_created_field -from datetime import datetime -from itertools import groupby -import pytz - class UserProfile(models.Model): notify = models.BooleanField( @@ -183,8 +185,29 @@ class Package(models.Model): domain = Site.objects.get_current().domain return '%s://%s%s' % (proto, domain, self.get_absolute_url()) - def is_signed(self): - return bool(self.pgp_signature) + @property + @cache_function(15) + def signature(self): + try: + data = b64decode(self.pgp_signature) + except TypeError: + return None + data = BinaryData(data) + packets = list(data.packets()) + return packets[0] + + @property + @cache_function(15) + def signer(self): + sig = self.signature + if sig and sig.key_id: + try: + user = User.objects.get( + userprofile__pgp_key__endswith=sig.key_id) + except User.DoesNotExist: + user = None + return user + return None _maintainers = None |