Hi On 14/03/15 05:52 AM, Paul Wise wrote: > On Sat, Mar 14, 2015 at 4:47 PM, Stefano Zacchiroli wrote: >> On Sat, Mar 14, 2015 at 09:33:55AM +0800, Paul Wise wrote: >>> On Fri, 2015-03-13 at 19:32 +0100, Stefano Zacchiroli wrote: >>>> This has now been fixed, so I'm closing this bug. >>> >>> I think the suites should redirect to the right version, they don't >>> yet. >> >> Please elaborate. > > Compare the URL you get when visiting these two URLs: > > https://sources.debian.net/src/network-manager/experimental/ > https://sources.debian.net/src/network-manager/latest/ > > Jason has already implemented the change and is in the process of > testing it before submitting. >
Here's the patch :) I fixed two issues in one commit, since they were on the very same part of the code: The one reported by Paul, and the other that a package with multiple versions in the same suite (example, glibc) would not get redirected to the latest version when going to /src/package/<suite>/ Thanks -- Jason Pleau
>From b7a42373874defca8eb2330be7ed9a7b33b858d3 Mon Sep 17 00:00:00 2001 From: Jason Pleau <[email protected]> Date: Sun, 15 Mar 2015 18:33:02 -0400 Subject: [PATCH] suites/redirects: rework the way redirects were done * Do HTTP redirects instead of just rendering the page for the correct version. * Fixed an issue where packages with multiple versions would not redirect to the correct versions when going to /src/package/<suite>/. Example: a package in sid could have version 2.0-1 for amd64, and version 1.0-1 for i386. Going to /src/package/sid/ should redirect us to /src/package/2.0-1/, and not /src/package/1.0-1/. --- debsources/app/sources/views.py | 30 ++++++++++++++++++------------ debsources/tests/test_webapp.py | 10 ++++++++++ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/debsources/app/sources/views.py b/debsources/app/sources/views.py index 28d2b2e..ac36912 100644 --- a/debsources/app/sources/views.py +++ b/debsources/app/sources/views.py @@ -255,6 +255,16 @@ class SourceView(GeneralView): pkg_infos=pkg_infos ) + def _redirect_to_url(self, redirect_url): + if self.d.get('api'): + self.render_func = bind_redirect(url_for('.api_source', + path_to=redirect_url)) + else: + self.render_func = bind_redirect(url_for('.source', + path_to=redirect_url)) + + return dict(redirect=redirect_url) + def _handle_latest_version(self, package, path): """ redirects to the latest version for the requested page, @@ -275,14 +285,7 @@ class SourceView(GeneralView): else: redirect_url = '/'.join([package, version, path]) - if self.d.get('api'): - self.render_func = bind_redirect(url_for('.api_source', - path_to=redirect_url)) - else: - self.render_func = bind_redirect(url_for('.source', - path_to=redirect_url)) - - return dict(redirect=redirect_url) + return self._redirect_to_url(redirect_url) def get_objects(self, path_to): """ @@ -316,9 +319,12 @@ class SourceView(GeneralView): session, package) except InvalidPackageOrVersionError: raise Http404Error("%s not found" % package) - for version_suite in versions_w_suites: - if version in version_suite['suites']: - return self._render_location( - package, version_suite['version'], path) + + versions = sorted([v['version'] for v in versions_w_suites + if version in v['suites']], + cmp=version_compare) + if versions: + redirect_url = '/'.join([package, versions[-1]]) + return self._redirect_to_url(redirect_url) return self._render_location(package, version, path) diff --git a/debsources/tests/test_webapp.py b/debsources/tests/test_webapp.py index 6118b68..b83dba3 100644 --- a/debsources/tests/test_webapp.py +++ b/debsources/tests/test_webapp.py @@ -417,6 +417,16 @@ class DebsourcesTestCase(unittest.TestCase, DbTestFixture): follow_redirects=True).data) self.assertIn("2.03-2", rv['path']) + def test_multiple_versions_in_suite(self): + rv = json.loads(self.app.get('/api/src/patch/sid/', + follow_redirects=True).data) + self.assertIn('2.7.5-1', rv['path']) + + def test_multiple_versions_in_suite_alias(self): + rv = json.loads(self.app.get('/api/src/patch/unstable/', + follow_redirects=True).data) + self.assertIn('2.7.5-1', rv['path']) + def test_codesearch_box(self): rv = self.app.get('/src/ledit/2.03-2/ledit.ml/') self.assertIn('value="package:ledit "', rv.data) -- 2.1.4

