mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix: pkgbase -> package redirection
We were redirecting in some error-cases, which this commit sorts out: - package count == 1 and package base name != package name - was redirecting to {name} and not the only associated Package Now, when we have a package base name that mismatches its only package, we display the package base page. Otherwise, we redirect to the first package's page. Closes #282 Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
708ade4dbf
commit
29061c000c
1 changed files with 7 additions and 4 deletions
|
@ -39,14 +39,17 @@ async def pkgbase(request: Request, name: str) -> Response:
|
|||
# Get the PackageBase.
|
||||
pkgbase = get_pkg_or_base(name, PackageBase)
|
||||
|
||||
# If this is not a split package, redirect to /packages/{name}.
|
||||
if pkgbase.packages.count() == 1:
|
||||
return RedirectResponse(f"/packages/{name}",
|
||||
# Redirect to /packages if there's only one related Package
|
||||
# and its name matches its PackageBase.
|
||||
packages = pkgbase.packages.all()
|
||||
pkg = packages[0]
|
||||
if len(packages) == 1 and pkg.Name == pkgbase.Name:
|
||||
return RedirectResponse(f"/packages/{pkg.Name}",
|
||||
status_code=int(HTTPStatus.SEE_OTHER))
|
||||
|
||||
# Add our base information.
|
||||
context = pkgbaseutil.make_context(request, pkgbase)
|
||||
context["packages"] = pkgbase.packages.all()
|
||||
context["packages"] = packages
|
||||
|
||||
return render_template(request, "pkgbase/index.html", context)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue