From e3d50a5f49234d7163a87603d12cef70027633e3 Mon Sep 17 00:00:00 2001 From: Dusty Phillips Date: Sun, 12 Oct 2008 21:28:51 -0400 Subject: backport some archweb_pub changes into archweb_dev --- main/models.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/main/models.py b/main/models.py index c62ac20..8123d07 100644 --- a/main/models.py +++ b/main/models.py @@ -198,6 +198,10 @@ class Package(models.Model): - (None, dependname, None) if no matching package is found, eg it is a virtual dep. """ + # object level cache. Doesn't last long, but helps for items rendered + # twice in the same template. + if 'deps_cache' in dir(self): + return self.deps_cache deps = [] for dep in self.packagedepend_set.order_by('depname'): # we only need depend on same-arch-packages @@ -208,10 +212,16 @@ class Package(models.Model): # couldn't find a package in the DB # it should be a virtual depend (or a removed package) deps.append({'dep': dep, 'pkg': None}) - continue + elif len(pkgs) == 1: + deps.append({'dep': dep, 'pkg': pkgs[0]}) else: - for pkg in pkgs: - deps.append({'dep': dep, 'pkg': pkg}) + tpkgs = pkgs.filter(repo__name='Testing') + if len(tpkgs) == 1: + deps.append({'dep': dep, 'pkg': tpkgs[0]}) + else: + for pkg in pkgs: + deps.append({'dep': dep, 'pkg': pkg}) + self.deps_cache = deps return deps class Signoff(models.Model): -- cgit v1.2.3-24-g4f1b