summaryrefslogtreecommitdiff
path: root/main/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'main/models.py')
-rw-r--r--main/models.py62
1 files changed, 39 insertions, 23 deletions
diff --git a/main/models.py b/main/models.py
index ff2ecf02..a7cc2335 100644
--- a/main/models.py
+++ b/main/models.py
@@ -7,7 +7,6 @@ from packages.models import PackageRelation
from itertools import groupby
import pytz
-from operator import attrgetter
class UserProfile(models.Model):
notify = models.BooleanField(
@@ -117,7 +116,6 @@ class Package(models.Model):
build_date = models.DateTimeField(null=True)
last_update = models.DateTimeField(null=True, blank=True)
files_last_update = models.DateTimeField(null=True, blank=True)
- license = models.CharField(max_length=255, null=True)
packager_str = models.CharField(max_length=255)
packager = models.ForeignKey(User, null=True)
flag_date = models.DateTimeField(null=True)
@@ -174,10 +172,15 @@ class Package(models.Model):
list slim by including the corresponding package in the same testing
category as this package if that check makes sense.
"""
- requiredby = Package.objects.select_related('arch', 'repo').filter(
- packagedepend__depname=self.pkgname,
- arch__in=self.applicable_arches()
- ).distinct().order_by('pkgname')
+ requiredby = PackageDepend.objects.select_related('pkg',
+ 'pkg__arch', 'pkg__repo').filter(
+ pkg__arch__in=self.applicable_arches(),
+ depname=self.pkgname).order_by(
+ 'pkg__pkgname', 'pkg__id')
+ # sort out duplicate packages; this happens if something has a double
+ # versioned dep such as a kernel module
+ requiredby = [list(vals)[0] for k, vals in
+ groupby(requiredby, lambda x: x.pkg.id)]
# find another package by this name in the opposite testing setup
if not Package.objects.filter(pkgname=self.pkgname,
@@ -190,14 +193,15 @@ class Package(models.Model):
# for each unique package name, try to screen our package list down to
# those packages in the same testing category (yes or no) iff there is
# a package in the same testing category.
- for name, pkgs in groupby(requiredby, attrgetter('pkgname')):
- pkgs = list(pkgs)
- pkg = pkgs[0]
- if len(pkgs) > 1:
- pkgs = [p for p in pkgs if p.repo.testing == self.repo.testing]
- if len(pkgs) > 0:
- pkg = pkgs[0]
- trimmed.append(pkg)
+ for name, dep_pkgs in groupby(requiredby, lambda x: x.pkg.pkgname):
+ dep_pkgs = list(dep_pkgs)
+ dep = dep_pkgs[0]
+ if len(dep_pkgs) > 1:
+ dep_pkgs = [d for d in dep_pkgs
+ if d.pkg.repo.testing == self.repo.testing]
+ if len(dep_pkgs) > 0:
+ dep = dep_pkgs[0]
+ trimmed.append(dep)
return trimmed
@cache_function(300)
@@ -210,7 +214,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('depname'):
+ for dep in self.packagedepend_set.order_by('optional', 'depname'):
pkgs = Package.objects.select_related('arch', 'repo').filter(
pkgname=dep.depname)
if not self.arch.agnostic:
@@ -260,7 +264,7 @@ class Package(models.Model):
repo.testing flag. For any non-split packages, the return value will be
an empty list.
"""
- return Package.objects.filter(arch__in=self.applicable_arches,
+ return Package.objects.filter(arch__in=self.applicable_arches(),
repo__testing=self.repo.testing, pkgbase=self.pkgbase).exclude(id=self.id)
def get_svn_link(self, svnpath):
@@ -309,15 +313,27 @@ class Signoff(models.Model):
packager = models.ForeignKey(User)
class PackageFile(models.Model):
- pkg = models.ForeignKey('Package')
- path = models.CharField(max_length=255)
+ pkg = models.ForeignKey(Package)
+ is_directory = models.BooleanField(default=False)
+ directory = models.CharField(max_length=255)
+ filename = models.CharField(max_length=255, null=True, blank=True)
+
+ def __unicode__(self):
+ return "%s%s" % (self.directory, self.filename or '')
+
class Meta:
db_table = 'package_files'
class PackageDepend(models.Model):
- pkg = models.ForeignKey('Package')
- depname = models.CharField(db_index=True, max_length=255)
- depvcmp = models.CharField(max_length=255)
+ pkg = models.ForeignKey(Package)
+ depname = models.CharField(max_length=255, db_index=True)
+ depvcmp = models.CharField(max_length=255, default='')
+ optional = models.BooleanField(default=False)
+ description = models.TextField(null=True, blank=True)
+
+ def __unicode__(self):
+ return "%s%s" % (self.depname, self.depvcmp)
+
class Meta:
db_table = 'package_depends'
@@ -349,8 +365,8 @@ class Todolist(models.Model):
return '/todo/%i/' % self.id
class TodolistPkg(models.Model):
- list = models.ForeignKey('Todolist')
- pkg = models.ForeignKey('Package')
+ list = models.ForeignKey(Todolist)
+ pkg = models.ForeignKey(Package)
complete = models.BooleanField(default=False)
class Meta:
db_table = 'todolist_pkgs'