add comment deletion

Signed-off-by: Ari Archer <ari@ari.lt>
This commit is contained in:
Arija A. 2024-06-07 18:45:31 +03:00
parent 1e79ade47c
commit daf14c136e
4 changed files with 24 additions and 5 deletions

2
run.sh
View file

@ -4,7 +4,7 @@ set -u
main() {
kill -9 $(pgrep python3) || true
kill -9 $(pgrep memcached) || true
kill -9 $(pgrep gunicorn) || true
cd src
python3 -m pip install gunicorn

View file

@ -96,7 +96,22 @@ Comment:
```""",
)
flask.flash(f"Comment #{comment_id} confirmed.")
flask.flash(f"Comment #{comment.id} confirmed.")
return flask.redirect(flask.url_for("views.index"))
@views.get("/delete/<int:comment_id>/<string:token>/", alias=True)
@views.get("/delete/<int:comment_id>/<string:token>")
def delete(comment_id: int, token: str):
"""delete a comment"""
comment: models.Comment = models.Comment.query.filter_by(id=comment_id, token=token).first_or_404()
models.db.session.delete(comment)
models.db.session.commit()
flask.flash(f"Comment #{comment.id} deleted.")
return flask.redirect(flask.url_for("views.index"))
@ -157,7 +172,11 @@ Visit the following URL to *confirm* your email:
{flask.request.url.rstrip("/")}{flask.url_for("views.confirm", comment_id=comment.id, token=comment.token)}
...Or paste it into your browser.""",
Or you may delete the comment:
{flask.request.url.rstrip("/")}{flask.url_for("views.delete", comment_id=comment.id, token=comment.token)}
If clicking doesn't work - try pasting it into your browser, or running `curl`/`wget`/`axel` on it :)""",
)
except Exception:
models.db.session.delete(comment)

View file

@ -42,7 +42,7 @@
<details open>
<summary>messages from the server</summary>
{% for category, message in messages %}
<div data-category="{{ category }}">{{ message | escape }}</div>
<div><b>[{{ category | escape }}] {{ message | escape }}</b></div>
{% endfor %}
</details>
{% endif %}

View file

@ -450,7 +450,7 @@
</form>
<div align="center">
<i>Report any impersonation to the owner of this website: Ari Archer.</i>
<i>Report any impersonation, illegal/graphic content, and/or anything disturbing to the owner of this website: Ari Archer.</i>
</div>
<div id="comments">