From 5f410c000eaca4b5b25664f4dfb59cbe85ea034e Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Tue, 31 Jul 2012 19:12:27 -0500 Subject: Add package details redirect for package replacements This makes sense if there is only one available replacement. We could get more sophisticated and show the removed page if there are multiple replacements available. Additionally, automatically redirect if there was only one matching package for a given package update deletion object. Signed-off-by: Dan McGee --- packages/views/display.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'packages/views') diff --git a/packages/views/display.py b/packages/views/display.py index 1ea9ea48..d6922314 100644 --- a/packages/views/display.py +++ b/packages/views/display.py @@ -51,12 +51,24 @@ def recently_removed_package(request, name, repo, arch, cutoff=CUTOFF): match = match.filter(created__gte=when) try: match = match.latest() + elsewhere = match.elsewhere() + if len(elsewhere) == 1: + return redirect(elsewhere[0]) return render(request, 'packages/removed.html', {'update': match, }, status=410) except Update.DoesNotExist: return None +def replaced_package(request, name, repo, arch): + '''Check our package replacements to see if this is a package we used to + have but no longer do.''' + match = Package.objects.filter(replaces__name=name, repo=repo, arch=arch) + if len(match) == 1: + return redirect(match[0], permanent=True) + return None + + def redirect_agnostic(request, name, repo, 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 @@ -95,7 +107,7 @@ def details(request, name='', repo='', arch=''): except Package.DoesNotExist: # attempt a variety of fallback options before 404ing options = (redirect_agnostic, split_package_details, - recently_removed_package) + recently_removed_package, replaced_package) for method in options: ret = method(request, name, repo_obj, arch_obj) if ret: -- cgit v1.2.3-54-g00ecf