summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2010-12-07 14:12:03 -0600
committerDan McGee <dan@archlinux.org>2010-12-07 14:12:03 -0600
commitfc3ab08cb5663f9b3189b7e04bfd73e7ba2c3e92 (patch)
tree3187142ca6a87f4d91c2f8fee87acd50cd46ccb8 /main
parente8feaa3e01fdb326e82139ff80fce34f7e088438 (diff)
Slim down required by listings
If we have testing/non-testing packages in this list, and we are looking at a package that is in both testing and non-testing, we can show only the packages that correspond with the relevant repo. I'm not sure any explanation will make this easier to understand, but the end result is we don't show a bunch of duplicates where we used to. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'main')
-rw-r--r--main/models.py39
1 files changed, 33 insertions, 6 deletions
diff --git a/main/models.py b/main/models.py
index ec2416f7..b5c395a4 100644
--- a/main/models.py
+++ b/main/models.py
@@ -5,6 +5,9 @@ from django.contrib.sites.models import Site
from main.utils import cache_function
from packages.models import PackageRelation
+from itertools import groupby
+from operator import attrgetter
+
class UserProfile(models.Model):
id = models.AutoField(primary_key=True) # not technically needed
notify = models.BooleanField(
@@ -166,19 +169,43 @@ class Package(models.Model):
@cache_function(300)
def get_requiredby(self):
"""
- Returns a list of package objects.
+ Returns a list of package objects. An attempt will be made to keep this
+ 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()
- return requiredby.order_by('pkgname')
+ arch__in=self.applicable_arches()
+ ).distinct().order_by('pkgname')
+
+ # find another package by this name in the opposite testing setup
+ if not Package.objects.filter(pkgname=self.pkgname,
+ arch=self.arch).exclude(id=self.id,
+ repo__testing=self.repo.testing).exists():
+ # there isn't one? short circuit, all required by entries are fine
+ return requiredby
+
+ trimmed = []
+ # 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)
+ return trimmed
@cache_function(300)
def get_depends(self):
"""
- Returns a list of dicts. Each dict contains ('pkg' and 'dep').
- If it represents a found package both vars will be available;
- else pkg will be None if it is a 'virtual' dependency.
+ Returns a list of dicts. Each dict contains ('pkg' and 'dep'). If it
+ represents a found package both vars will be available; else pkg will
+ be None if it is a 'virtual' dependency. Packages will match the
+ testing status of this package if possible.
"""
deps = []
# TODO: we can use list comprehension and an 'in' query to make this more effective