2010-03-27 14:15:20 -07:00
|
|
|
from django.db import models
|
2011-02-18 14:35:54 -08:00
|
|
|
from django.db.models.signals import post_save
|
2010-03-27 14:15:20 -07:00
|
|
|
from django.contrib.auth.models import User
|
|
|
|
|
|
|
|
class PackageRelation(models.Model):
|
|
|
|
'''
|
|
|
|
Represents maintainership (or interest) in a package by a given developer.
|
|
|
|
It is not a true foreign key to packages as we want to key off
|
|
|
|
pkgbase/pkgname instead, as well as preserve this information across
|
|
|
|
package deletes, adds, and in all repositories.
|
|
|
|
'''
|
|
|
|
MAINTAINER = 1
|
|
|
|
WATCHER = 2
|
|
|
|
TYPE_CHOICES = (
|
|
|
|
(MAINTAINER, 'Maintainer'),
|
|
|
|
(WATCHER, 'Watcher'),
|
|
|
|
)
|
|
|
|
pkgbase = models.CharField(max_length=255)
|
|
|
|
user = models.ForeignKey(User, related_name="package_relations")
|
|
|
|
type = models.PositiveIntegerField(choices=TYPE_CHOICES, default=MAINTAINER)
|
2011-02-18 14:25:53 -08:00
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return "%s: %s (%s)" % (
|
|
|
|
self.pkgbase, self.user, self.get_type_display())
|
|
|
|
|
2010-03-27 14:15:20 -07:00
|
|
|
class Meta:
|
|
|
|
unique_together = (('pkgbase', 'user', 'type'),)
|
|
|
|
|
2010-07-23 11:14:31 -07:00
|
|
|
class PackageGroup(models.Model):
|
|
|
|
'''
|
|
|
|
Represents a group a package is in. There is no actual group entity,
|
|
|
|
only names that link to given packages.
|
|
|
|
'''
|
2011-02-07 10:48:12 -08:00
|
|
|
pkg = models.ForeignKey('main.Package', related_name='groups')
|
2010-07-23 11:14:31 -07:00
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
|
2011-02-07 10:48:12 -08:00
|
|
|
def __unicode__(self):
|
2011-02-18 14:25:53 -08:00
|
|
|
return "%s: %s" % (name, pkg)
|
2011-02-07 10:48:12 -08:00
|
|
|
|
2011-02-07 11:45:05 -08:00
|
|
|
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']
|
|
|
|
|
2011-02-18 14:35:54 -08:00
|
|
|
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")
|
|
|
|
|
2010-03-27 14:15:20 -07:00
|
|
|
# vim: set ts=4 sw=4 et:
|