delete reply
This commit is contained in:
parent
4fcd18cafa
commit
5709dba71a
6 changed files with 84 additions and 44 deletions
14
journal/templates/action_delete_post.html
Normal file
14
journal/templates/action_delete_post.html
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{% load i18n %}
|
||||||
|
<span>
|
||||||
|
<a hx-post="{% url 'journal:post_delete' post.pk %}"
|
||||||
|
hx-swap="outerHTML"
|
||||||
|
hx-trigger="click once"
|
||||||
|
{% if post.piece %} hx-confirm="{% trans "are you sure to delete the mark or note related with this post?" %}" {% else %} hx-confirm="{% trans "are you sure to delete this post?" %}" {% endif %}
|
||||||
|
hx-target="#replies_{{ parent_post.pk }}">
|
||||||
|
{% if post.piece %}
|
||||||
|
<!--i class="fa-regular fa-trash-can"></i -->
|
||||||
|
{% else %}
|
||||||
|
<i class="fa-regular fa-square-minus"></i>
|
||||||
|
{% endif %}
|
||||||
|
</a>
|
||||||
|
</span>
|
|
@ -1,8 +1,15 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
<section class="replies" hx-target="this" hx-swap="outerHTML">
|
<section class="replies"
|
||||||
|
hx-target="this"
|
||||||
|
hx-swap="outerHTML"
|
||||||
|
id="replies_{{ post.pk }}">
|
||||||
|
{% with parent_post=post %}
|
||||||
{% for post in replies %}
|
{% for post in replies %}
|
||||||
<div class="post">
|
<div class="post">
|
||||||
<span class="action">
|
<span class="action">
|
||||||
|
{% if post.author_id == request.user.identity.pk %}
|
||||||
|
{% include "action_delete_post.html" %}
|
||||||
|
{% endif %}
|
||||||
{% include "action_reply_post.html" %}
|
{% include "action_reply_post.html" %}
|
||||||
{% include "action_like_post.html" %}
|
{% include "action_like_post.html" %}
|
||||||
{% include "action_boost_post.html" %}
|
{% include "action_boost_post.html" %}
|
||||||
|
@ -45,6 +52,7 @@
|
||||||
{% empty %}
|
{% empty %}
|
||||||
<div class="empty">{% trans 'no replies so far.' %}</div>
|
<div class="empty">{% trans 'no replies so far.' %}</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% endwith %}
|
||||||
{% if post %}
|
{% if post %}
|
||||||
<form class="reply"
|
<form class="reply"
|
||||||
role="group"
|
role="group"
|
||||||
|
|
|
@ -25,6 +25,7 @@ urlpatterns = [
|
||||||
path("item/<str:item_uuid>/note/<str:note_uuid>", note_edit, name="note"),
|
path("item/<str:item_uuid>/note/<str:note_uuid>", note_edit, name="note"),
|
||||||
path("piece/<str:piece_uuid>/replies", piece_replies, name="piece_replies"),
|
path("piece/<str:piece_uuid>/replies", piece_replies, name="piece_replies"),
|
||||||
path("post/<int:post_id>/replies", post_replies, name="post_replies"),
|
path("post/<int:post_id>/replies", post_replies, name="post_replies"),
|
||||||
|
path("post/<int:post_id>/delete", post_delete, name="post_delete"),
|
||||||
path("post/<int:post_id>/reply", post_reply, name="post_reply"),
|
path("post/<int:post_id>/reply", post_reply, name="post_reply"),
|
||||||
path("post/<int:post_id>/boost", post_boost, name="post_boost"),
|
path("post/<int:post_id>/boost", post_boost, name="post_boost"),
|
||||||
path("post/<int:post_id>/like", post_like, name="post_like"),
|
path("post/<int:post_id>/like", post_like, name="post_like"),
|
||||||
|
|
|
@ -21,6 +21,7 @@ from .note import note_edit
|
||||||
from .post import (
|
from .post import (
|
||||||
piece_replies,
|
piece_replies,
|
||||||
post_boost,
|
post_boost,
|
||||||
|
post_delete,
|
||||||
post_like,
|
post_like,
|
||||||
post_replies,
|
post_replies,
|
||||||
post_reply,
|
post_reply,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.core.exceptions import BadRequest, ObjectDoesNotExist, PermissionDenied
|
from django.core.exceptions import BadRequest, ObjectDoesNotExist, PermissionDenied
|
||||||
|
from django.http import Http404
|
||||||
from django.shortcuts import get_object_or_404, redirect, render
|
from django.shortcuts import get_object_or_404, redirect, render
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
@ -32,6 +33,21 @@ def post_replies(request: AuthedHttpRequest, post_id: int):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@require_http_methods(["POST"])
|
||||||
|
@login_required
|
||||||
|
def post_delete(request: AuthedHttpRequest, post_id: int):
|
||||||
|
p = Takahe.get_post(post_id)
|
||||||
|
if not p:
|
||||||
|
raise Http404(_("Post not found"))
|
||||||
|
if p.author_id != request.user.identity.pk:
|
||||||
|
raise PermissionDenied(_("Insufficient permission"))
|
||||||
|
parent_post = p.in_reply_to_post()
|
||||||
|
Takahe.delete_posts([post_id])
|
||||||
|
if parent_post:
|
||||||
|
return post_replies(request, parent_post.pk)
|
||||||
|
return redirect(reverse("home")) # FIXME
|
||||||
|
|
||||||
|
|
||||||
@require_http_methods(["POST"])
|
@require_http_methods(["POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def post_reply(request: AuthedHttpRequest, post_id: int):
|
def post_reply(request: AuthedHttpRequest, post_id: int):
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit f43ecdbab3c7caeb74d91d5566dd791ebdc3c59f
|
Subproject commit 65f4163e5f6a5b4c4d6af8c9825681d9005189ba
|
Loading…
Add table
Reference in a new issue