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
46
templates/partials/packages/comment_form.html
Normal file
46
templates/partials/packages/comment_form.html
Normal file
|
@ -0,0 +1,46 @@
|
|||
{# `action` is assigned the proper route to use for the form action.
|
||||
When `comment` is provided (PackageComment), we display an edit form
|
||||
for the comment. Otherwise, we display a new form.
|
||||
|
||||
Routes:
|
||||
new comment - /pkgbase/{name}/comments
|
||||
edit comment - /pkgbase/{name}/comments/{id}
|
||||
#}
|
||||
{% set action = "/pkgbase/%s/comments" | format(pkgbase.Name) %}
|
||||
{% if comment %}
|
||||
{% set action = "/pkgbase/%s/comments/%d" | format(pkgbase.Name, comment.ID) %}
|
||||
{% endif %}
|
||||
|
||||
<form action="{{ action }}" method="post">
|
||||
<fieldset>
|
||||
<p>
|
||||
{{ "Git commit identifiers referencing commits in the AUR package "
|
||||
"repository and URLs are converted to links automatically." | tr }}
|
||||
{{ "%sMarkdown syntax%s is partially supported." | tr
|
||||
| format('<a href="https://daringfireball.net/projects/markdown/syntax">',
|
||||
"</a>")
|
||||
| safe }}
|
||||
</p>
|
||||
<p>
|
||||
<textarea id="id_comment"
|
||||
name="comment"
|
||||
cols="80"
|
||||
rows="10"
|
||||
>{% if comment %}{{ comment.Comments or '' }}{% endif %}</textarea>
|
||||
</p>
|
||||
<p>
|
||||
<button type="submit" class="button">
|
||||
{{ ("Save" if comment else "Add Comment") | tr }}
|
||||
</button>
|
||||
{% if comment and not request.user.notified(pkgbase) %}
|
||||
<span class="comment-enable-notifications">
|
||||
<input type="checkbox" name="enable_notifications"
|
||||
id="id_enable_notifications" />
|
||||
<label for="id_enable_notifications">
|
||||
{{ "Enable notifications" | tr }}
|
||||
</label>
|
||||
</span>
|
||||
{% endif %}
|
||||
</p>
|
||||
</fieldset>
|
||||
</form>
|
Loading…
Add table
Add a link
Reference in a new issue