Verified Commit 29061c00 authored by Kevin Morris's avatar Kevin Morris
Browse files

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's avatarKevin Morris <kevr@0cost.org>
parent 708ade4d
......@@ -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)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment