summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-07-31 19:12:27 -0500
committerDan McGee <dan@archlinux.org>2012-07-31 19:12:27 -0500
commit5f410c000eaca4b5b25664f4dfb59cbe85ea034e (patch)
treee3804051862fed54db29c8dbc79b09d2c9c33bd1
parent0b7939ae1a1e3ce55ee458d24fd5946542d9c14a (diff)
downloadarchweb-5f410c000eaca4b5b25664f4dfb59cbe85ea034e.tar.gz
archweb-5f410c000eaca4b5b25664f4dfb59cbe85ea034e.zip
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 <dan@archlinux.org>
-rw-r--r--packages/views/display.py14
1 files changed, 13 insertions, 1 deletions
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: