mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
feat(FastAPI): add pkgbase comments (new, edit)
In PHP, this was implemented using an /rpc type 'get-comment-form'. With FastAPI, we've decided to reorganize this into a non-RPC route: `/pkgbase/{name}/comments/{id}/form`, rendered via the new `templates/partials/packages/comment_form.html` template. When the comment_form.html template is provided a `comment` object, it will produce an edit comment form. Otherwise, it will produce a new comment form. A few new FastAPI routes have been introduced: - GET `/pkgbase/{name}/comments/{id}/form` - Produces a JSON response based on {"form": "<form_markup>"}. - POST `/pkgbase/{name}/comments' - Creates a new comment. - POST `/pkgbase/{name}/comments/{id}` - Edits an existing comment. In addition, some Javascript has been modified for our new routes. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
0d8216e8ea
commit
fc28aad245
6 changed files with 333 additions and 79 deletions
|
@ -11,6 +11,7 @@ from aurweb import db
|
|||
from aurweb.models.official_provider import OFFICIAL_BASE, OfficialProvider
|
||||
from aurweb.models.package import Package
|
||||
from aurweb.models.package_base import PackageBase
|
||||
from aurweb.models.package_comment import PackageComment
|
||||
from aurweb.models.package_dependency import PackageDependency
|
||||
from aurweb.models.package_notification import PackageNotification
|
||||
from aurweb.models.package_relation import PackageRelation
|
||||
|
@ -121,6 +122,13 @@ def get_pkg_or_base(name: str, cls: Union[Package, PackageBase] = PackageBase):
|
|||
return instance
|
||||
|
||||
|
||||
def get_pkgbase_comment(pkgbase: PackageBase, id: int) -> PackageComment:
|
||||
comment = pkgbase.comments.filter(PackageComment.ID == id).first()
|
||||
if not comment:
|
||||
raise HTTPException(status_code=int(HTTPStatus.NOT_FOUND))
|
||||
return comment
|
||||
|
||||
|
||||
@register_filter("out_of_date")
|
||||
def out_of_date(packages: orm.Query) -> orm.Query:
|
||||
return packages.filter(PackageBase.OutOfDateTS.isnot(None))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue