diff --git a/aurweb/asgi.py b/aurweb/asgi.py index cf878294..dc6b4355 100644 --- a/aurweb/asgi.py +++ b/aurweb/asgi.py @@ -18,7 +18,7 @@ from aurweb.auth import BasicAuthBackend from aurweb.db import get_engine, query from aurweb.models.accepted_term import AcceptedTerm from aurweb.models.term import Term -from aurweb.routers import accounts, auth, errors, html, rss, sso, trusted_user +from aurweb.routers import accounts, auth, errors, html, packages, rss, sso, trusted_user # Setup the FastAPI app. app = FastAPI(exception_handlers=errors.exceptions) @@ -51,6 +51,7 @@ async def app_startup(): app.include_router(accounts.router) app.include_router(trusted_user.router) app.include_router(rss.router) + app.include_router(packages.router) # Initialize the database engine and ORM. get_engine() diff --git a/aurweb/routers/packages.py b/aurweb/routers/packages.py new file mode 100644 index 00000000..80a4221b --- /dev/null +++ b/aurweb/routers/packages.py @@ -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}") diff --git a/templates/partials/packages/comments.html b/templates/partials/packages/comments.html new file mode 100644 index 00000000..48bc88e6 --- /dev/null +++ b/templates/partials/packages/comments.html @@ -0,0 +1,73 @@ + + +
+

Add Comment

+
+
+
+ + +
+

+ Git commit identifiers referencing commits in the AUR package + repository and URLs are converted to links automatically. + + Markdown syntax + + is partially supported. +

+

+ +

+

+ +

+
+
+
+ +
+
+

+ Latest Comments + +

+
+ {% for comment in comments %} +

+ {% set commentTimestamp = comment.CommentTS | dt | as_timezone(timezone) %} + {{ comment.User.Username }} + commented on {{ "%s" | tr | format(commentTimestamp.strftime("%Y-%m-%d %H:%M")) }} + {% if request.user.is_authenticated() and pkgbase.Maintainer.Username == request.user.Username %} +
+
+ + + + +
+
+ Edit comment + {% endif %} +
+
+ + + + + +
+
+

+
+
+

{{ comment.Comments }}

+
+
+ {% endfor %} +
diff --git a/templates/partials/packages/package_actions.html b/templates/partials/packages/package_actions.html new file mode 100644 index 00000000..36844214 --- /dev/null +++ b/templates/partials/packages/package_actions.html @@ -0,0 +1,33 @@ + + diff --git a/templates/partials/packages/search.html b/templates/partials/packages/search.html new file mode 100644 index 00000000..b6b2da1b --- /dev/null +++ b/templates/partials/packages/search.html @@ -0,0 +1,69 @@ + diff --git a/templates/pkgbase.html b/templates/pkgbase.html new file mode 100644 index 00000000..939aef10 --- /dev/null +++ b/templates/pkgbase.html @@ -0,0 +1,89 @@ +{% extends "partials/layout.html" %} + +{% block pageContent %} + {% include "partials/packages/search.html" %} +
+

Package Base Details: {{ pkgbase.Name }}

+ + {% set result = pkgbase %} + {% set pkgname = "result.Name" %} + {% include "partials/packages/package_actions.html" %} + + + + + + + + + {% if request.user.is_authenticated() and pkgbase.Maintainer.Username == request.user.Username %} + + {% else %} + + {% endif %} + + + + + + + + + + + + + + + + + + + + + + + {% set submitted = pkgbase.SubmittedTS | dt | as_timezone(timezone) %} + + + + + + {% set updated = pkgbase.ModifiedTS | dt | as_timezone(timezone) %} + + +
Git Clone URL: + {{ git_clone_uri_anon | format(pkgbase.Name) }} (read-only, click to copy) + {% if request.user.is_authenticated() and pkgbase.Maintainer.Username == request.user.Username %} +
{{ git_clone_uri_priv | format(pkgbase.Name) }} (click to copy) + {% endif %} +
Keywords: +
+
+ + + +
+
+
+ {% for item in pkgbase.keywords %} + {{ item.Keyword }} + {% endfor %} +
Submitter: {{ pkgbase.Submitter.Username | default("None") }}
Maintainer: {{ pkgbase.Maintainer.Username | default("None") }}
Last Packager: {{ pkgbase.Packager.Username | default("None") }}
Votes: {{ pkgbase.NumVotes }}
Popularity: {{ '%0.2f' % pkgbase.Popularity | float }}
First Submitted: {{ "%s" | tr | format(submitted.strftime("%Y-%m-%d %H:%M")) }}
Last Updated: {{ "%s" | tr | format(updated.strftime("%Y-%m-%d %H:%M")) }}
+ +
+
+

Packages ({{ packages_count }})

+ +
+
+
+ {% set pkgname = result.Name %} + {% set pkgbase_id = result.ID %} + {% set comments = comments %} + {% include "partials/packages/comments.html" %} +{% endblock %}