summaryrefslogtreecommitdiff
path: root/packages/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/models.py')
-rw-r--r--packages/models.py42
1 files changed, 41 insertions, 1 deletions
diff --git a/packages/models.py b/packages/models.py
index 70ac4fe5..5dbdea45 100644
--- a/packages/models.py
+++ b/packages/models.py
@@ -1,4 +1,5 @@
from django.db import models
+from django.db.models.signals import post_save
from django.contrib.auth.models import User
class PackageRelation(models.Model):
@@ -17,6 +18,21 @@ class PackageRelation(models.Model):
pkgbase = models.CharField(max_length=255)
user = models.ForeignKey(User, related_name="package_relations")
type = models.PositiveIntegerField(choices=TYPE_CHOICES, default=MAINTAINER)
+
+ def get_associated_packages(self):
+ # TODO: delayed import to avoid circular reference
+ from main.models import Package
+ return Package.objects.filter(pkgbase=self.pkgbase).select_related(
+ 'arch', 'repo')
+
+ def repositories(self):
+ packages = self.get_associated_packages()
+ return sorted(set([p.repo for p in packages]))
+
+ def __unicode__(self):
+ return "%s: %s (%s)" % (
+ self.pkgbase, self.user, self.get_type_display())
+
class Meta:
unique_together = (('pkgbase', 'user', 'type'),)
@@ -25,7 +41,31 @@ class PackageGroup(models.Model):
Represents a group a package is in. There is no actual group entity,
only names that link to given packages.
'''
- pkg = models.ForeignKey('main.Package')
+ pkg = models.ForeignKey('main.Package', related_name='groups')
+ name = models.CharField(max_length=255)
+
+ def __unicode__(self):
+ return "%s: %s" % (name, pkg)
+
+class License(models.Model):
+ pkg = models.ForeignKey('main.Package', related_name='licenses')
name = models.CharField(max_length=255)
+ def __unicode__(self):
+ return self.name
+
+ class Meta:
+ ordering = ['name']
+
+def remove_inactive_maintainers(sender, instance, created, **kwargs):
+ # instance is an auth.models.User; we want to remove any existing
+ # maintainer relations if the user is no longer active
+ if not instance.is_active:
+ maint_relations = PackageRelation.objects.filter(user=instance,
+ type=PackageRelation.MAINTAINER)
+ maint_relations.delete()
+
+post_save.connect(remove_inactive_maintainers, sender=User,
+ dispatch_uid="packages.models")
+
# vim: set ts=4 sw=4 et: