summaryrefslogtreecommitdiff
path: root/packages/models.py
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-12-11 21:19:16 -0600
committerDan McGee <dan@archlinux.org>2012-12-11 21:20:07 -0600
commite08096ee214b1fd60d093e2902c6acec9cf4ae5f (patch)
tree2d260f5d4b972c4b300ccf147843910e4d1bc7b4 /packages/models.py
parent040e0ddea591702856ce7d737bf4ea31f60a89e5 (diff)
Fix FS#32018, provides links always go to [testing] packages
Remove some of the smarts and do less, but be better about properly sorting the items as one might expect. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'packages/models.py')
-rw-r--r--packages/models.py24
1 files changed, 6 insertions, 18 deletions
diff --git a/packages/models.py b/packages/models.py
index ede8c275..a4095f53 100644
--- a/packages/models.py
+++ b/packages/models.py
@@ -412,24 +412,12 @@ class RelatedToBase(models.Model):
new_pkgs.append(package)
pkgs = new_pkgs
- # Logic here is to filter out packages that are in multiple repos if
- # they are not requested. For example, if testing is False, only show a
- # testing package if it doesn't exist in a non-testing repo.
- filtered = {}
- for package in pkgs:
- if package.pkgname not in filtered or \
- package.repo.staging == self.pkg.repo.staging:
- filtered[package.pkgname] = package
- pkgs = filtered.values()
-
- filtered = {}
- for package in pkgs:
- if package.pkgname not in filtered or \
- package.repo.testing == self.pkg.repo.testing:
- filtered[package.pkgname] = package
- pkgs = filtered.values()
-
- return pkgs
+ # Sort providers by preference. We sort those in same staging/testing
+ # combination first, followed by others. We sort by a (staging,
+ # testing) match tuple that will be (True, True) in the best case.
+ key_func = lambda x: (x.repo.staging == self.pkg.repo.staging,
+ x.repo.testing == self.pkg.repo.testing)
+ return sorted(pkgs, key=key_func, reverse=True)
def __unicode__(self):
if self.version: