summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-02-16 03:00:33 +0100
committerDan McGee <dan@archlinux.org>2011-02-17 00:43:50 +0100
commit8d3d05c7cb81611537aa34fa68e98e5e22b74847 (patch)
tree6ab657920b1c9d33b73175a44d40ce5d0f011522
parent7f1c7b08227e49172734f09552ceae8bc1f685ad (diff)
downloadarchweb-8d3d05c7cb81611537aa34fa68e98e5e22b74847.tar.gz
archweb-8d3d05c7cb81611537aa34fa68e98e5e22b74847.tar.xz
Allow for optional info in required by display
We need to make our root object the PackageDepend rather than the Package to get at this, so do a slight refactor on get_requiredby(). Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--main/models.py31
-rw-r--r--templates/packages/details.html7
2 files changed, 22 insertions, 16 deletions
diff --git a/main/models.py b/main/models.py
index dafbb1e..73a7620 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(
@@ -173,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,
@@ -189,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)
diff --git a/templates/packages/details.html b/templates/packages/details.html
index ac99718..09b970c 100644
--- a/templates/packages/details.html
+++ b/templates/packages/details.html
@@ -186,9 +186,10 @@
{% if rqdby %}
<ul>
{% for req in rqdby %}
- <li><a href="{{ req.get_absolute_url }}"
- title="View package details for {{ req.pkgname }}">{{ req.pkgname }}</a>
- {% if req.repo.testing %}<span class="testing-dep">(testing)</span>{% endif %}
+ <li><a href="{{ req.pkg.get_absolute_url }}"
+ title="View package details for {{ req.pkg.pkgname }}">{{ req.pkg.pkgname }}</a>
+ {% if req.pkg.repo.testing %}<span class="testing-dep">(testing)</span>{% endif %}
+ {% if req.optional %}<span class="opt-dep">(optional)</span>{% endif %}
</li>
{% endfor %}
</ul>