summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-05-18 20:26:16 -0500
committerDan McGee <dan@archlinux.org>2012-05-18 21:36:05 -0500
commitcf67e7952396121d3f7190195d812ea3f5fc7dcf (patch)
tree1a6fd354c9ee9300eb93f451a3a570a7049a0fde
parent1625cd31c334b017688a8c30631ddad60fafd8f4 (diff)
Issue redirects from non-agnostic to agnostic URLs if unambiguous
For something like "/extra/i686/apache-ant/", we can redirect to "/extra/any/apache-ant/" without ambiguity. Previously this redirected to the split packages listing with a single package, which was neither correct nor really expected. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--packages/views/__init__.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/packages/views/__init__.py b/packages/views/__init__.py
index c1a035d0..3e574c26 100644
--- a/packages/views/__init__.py
+++ b/packages/views/__init__.py
@@ -136,6 +136,16 @@ def details(request, name='', repo='', arch=''):
return direct_to_template(request, 'packages/details.html',
{'pkg': pkg, })
except Package.DoesNotExist:
+ arch_obj = get_object_or_404(Arch, name=arch)
+ # for arch='any' packages, we can issue a redirect to them if we
+ # have a single non-ambiguous option by changing the arch to match
+ # any arch-agnostic package
+ if not arch_obj.agnostic:
+ pkgs = Package.objects.select_related(
+ 'arch', 'repo', 'packager').filter(pkgname=name,
+ repo__name__iexact=repo, arch__agnostic=True)
+ if len(pkgs) == 1:
+ return redirect(pkgs[0], permanent=True)
return split_package_details(request, name, repo, arch)
else:
pkg_data = [