mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
[FastAPI] Basic pkgbase template
Co-author: Kevin Morris <kevr@0cost.org> Signed-off-by: Leonidas Spyropoulos <artafinde@gmail.com> Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
9197f86a03
commit
1e1c0c3fe5
6 changed files with 303 additions and 1 deletions
37
aurweb/routers/packages.py
Normal file
37
aurweb/routers/packages.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
from http import HTTPStatus
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Request
|
||||
from fastapi.responses import RedirectResponse
|
||||
|
||||
import aurweb.models.package
|
||||
import aurweb.models.package_comment
|
||||
import aurweb.models.package_keyword
|
||||
|
||||
from aurweb import db
|
||||
from aurweb.models.package_base import PackageBase
|
||||
from aurweb.templates import make_variable_context, render_template
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/packages/{package}")
|
||||
async def package_base(request: Request, package: str):
|
||||
package = db.query(PackageBase).filter(PackageBase.Name == package).first()
|
||||
if not package:
|
||||
raise HTTPException(status_code=int(HTTPStatus.NOT_FOUND))
|
||||
|
||||
context = await make_variable_context(request, package.Name)
|
||||
context["git_clone_uri_anon"] = aurweb.config.get("options", "git_clone_uri_anon")
|
||||
context["git_clone_uri_priv"] = aurweb.config.get("options", "git_clone_uri_priv")
|
||||
context["pkgbase"] = package
|
||||
context["packages"] = package.packages.all()
|
||||
context["packages_count"] = package.packages.count()
|
||||
context["keywords"] = package.keywords.all()
|
||||
context["comments"] = package.comments.all()
|
||||
|
||||
return render_template(request, "pkgbase.html", context)
|
||||
|
||||
|
||||
@router.get("/pkgbase/{package}")
|
||||
async def package_base_redirect(request: Request, package: str):
|
||||
return RedirectResponse(f"/packages/{package}")
|
Loading…
Add table
Add a link
Reference in a new issue