From e08096ee214b1fd60d093e2902c6acec9cf4ae5f Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Tue, 11 Dec 2012 21:19:16 -0600 Subject: 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 --- packages/models.py | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) (limited to 'packages') diff --git a/packages/models.py b/packages/models.py index ede8c27..a4095f5 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: -- cgit v1.2.3-24-g4f1b