From 29061c000c2876fd00bdfdf67c0c19d19d2f983d Mon Sep 17 00:00:00 2001 From: Kevin Morris Date: Mon, 14 Feb 2022 15:24:14 -0800 Subject: [PATCH] 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 --- aurweb/routers/pkgbase.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/aurweb/routers/pkgbase.py b/aurweb/routers/pkgbase.py index 7825ad7b..845c6372 100644 --- a/aurweb/routers/pkgbase.py +++ b/aurweb/routers/pkgbase.py @@ -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)