summaryrefslogtreecommitdiff
path: root/main/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'main/models.py')
-rw-r--r--main/models.py43
1 files changed, 32 insertions, 11 deletions
diff --git a/main/models.py b/main/models.py
index 59dc154b..a5d6c42e 100644
--- a/main/models.py
+++ b/main/models.py
@@ -1,6 +1,8 @@
from django.db import models
+from django.core.validators import RegexValidator
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
+from django.forms import ValidationError
from main.utils import cache_function, make_choice
from packages.models import PackageRelation
@@ -9,6 +11,23 @@ from datetime import datetime
from itertools import groupby
import pytz
+class PositiveBigIntegerField(models.BigIntegerField):
+ _south_introspects = True
+
+ def get_internal_type(self):
+ return "BigIntegerField"
+
+ def formfield(self, **kwargs):
+ defaults = {'min_value': 0}
+ defaults.update(kwargs)
+ return super(PositiveBigIntegerField, self).formfield(**defaults)
+
+def validate_pgp_key_length(value):
+ if len(value) not in (8, 16, 40):
+ raise ValidationError(
+ u'Ensure this value has 8, 16, or 40 characters (it has %d).' % len(value),
+ 'pgp_key_value')
+
class UserProfile(models.Model):
notify = models.BooleanField(
"Send notifications",
@@ -26,6 +45,11 @@ class UserProfile(models.Model):
max_length=50,
help_text="Required field")
other_contact = models.CharField(max_length=100, null=True, blank=True)
+ pgp_key = models.CharField(max_length=40, null=True, blank=True,
+ verbose_name="PGP key", validators=[RegexValidator(r'^[0-9A-F]+$',
+ "Ensure this value consists of only hex characters.", 'hex_char'),
+ validate_pgp_key_length],
+ help_text="PGP Key ID or fingerprint (8, 16, or 40 hex digits)")
website = models.CharField(max_length=200, null=True, blank=True)
yob = models.IntegerField("Year of birth", null=True, blank=True)
location = models.CharField(max_length=50, null=True, blank=True)
@@ -49,9 +73,8 @@ class TodolistManager(models.Manager):
return self.filter(todolistpkg__complete=False).distinct()
class PackageManager(models.Manager):
- def flagged(self):
- return self.get_query_set().filter(flag_date__isnull=False)
-
+ def normal(self):
+ return self.select_related('arch', 'repo')
class Donor(models.Model):
name = models.CharField(max_length=255, unique=True)
@@ -118,11 +141,10 @@ class Package(models.Model):
pkgdesc = models.CharField(max_length=255, null=True)
url = models.CharField(max_length=255, null=True)
filename = models.CharField(max_length=255)
- # TODO: it would be nice to have the >0 check constraint back here
- compressed_size = models.BigIntegerField(null=True)
- installed_size = models.BigIntegerField(null=True)
+ compressed_size = PositiveBigIntegerField()
+ installed_size = PositiveBigIntegerField()
build_date = models.DateTimeField(null=True)
- last_update = models.DateTimeField(null=True, blank=True)
+ last_update = models.DateTimeField()
files_last_update = models.DateTimeField(null=True, blank=True)
packager_str = models.CharField(max_length=255)
packager = models.ForeignKey(User, null=True,
@@ -232,8 +254,7 @@ class Package(models.Model):
deps = []
# TODO: we can use list comprehension and an 'in' query to make this more effective
for dep in self.packagedepend_set.order_by('optional', 'depname'):
- pkgs = Package.objects.select_related('arch', 'repo').filter(
- pkgname=dep.depname)
+ pkgs = Package.objects.normal().filter(pkgname=dep.depname)
if not self.arch.agnostic:
# make sure we match architectures if possible
pkgs = pkgs.filter(arch__in=self.applicable_arches())
@@ -297,7 +318,7 @@ class Package(models.Model):
if self.repo.testing:
return None
try:
- return Package.objects.get(repo__testing=True,
+ return Package.objects.normal().get(repo__testing=True,
pkgname=self.pkgname, arch=self.arch)
except Package.DoesNotExist:
return None
@@ -305,7 +326,7 @@ class Package(models.Model):
def elsewhere(self):
'''attempt to locate this package anywhere else, regardless of
architecture or repository. Excludes this package from the list.'''
- return Package.objects.select_related('arch', 'repo').filter(
+ return Package.objects.normal().filter(
pkgname=self.pkgname).exclude(id=self.id).order_by(
'arch__name', 'repo__name')