delete reply

This commit is contained in:
Your Name 2024-06-20 16:01:21 -04:00 committed by Henri Dickson
parent 4fcd18cafa
commit 5709dba71a
6 changed files with 84 additions and 44 deletions

View 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>

View file

@ -1,50 +1,58 @@
{% load i18n %}
<section class="replies" hx-target="this" hx-swap="outerHTML">
{% for post in replies %}
<div class="post">
<span class="action">
{% include "action_reply_post.html" %}
{% include "action_like_post.html" %}
{% include "action_boost_post.html" %}
{% include "action_open_post.html" %}
</span>
<span>
<a href="{{ post.author.url }}"
class="nickname"
title="@{{ post.author.handle }}">{{ post.author.name|default:post.author.username }}</a>
</span>
<span class="action inline">
<span class="timestamp">
{% if post.edited %}
{{ post.edited | date }}
<i class="fa-solid fa-pencil"></i>
{% elif post.published %}
{{ post.published | date }}
{% else %}
{{ post.created | date }}
<section class="replies"
hx-target="this"
hx-swap="outerHTML"
id="replies_{{ post.pk }}">
{% with parent_post=post %}
{% for post in replies %}
<div class="post">
<span class="action">
{% if post.author_id == request.user.identity.pk %}
{% include "action_delete_post.html" %}
{% endif %}
{% include "action_reply_post.html" %}
{% include "action_like_post.html" %}
{% include "action_boost_post.html" %}
{% include "action_open_post.html" %}
</span>
</span>
{% if post.summary %}
<details>
<summary>{{ post.summary }}</summary>
<span>
<a href="{{ post.author.url }}"
class="nickname"
title="@{{ post.author.handle }}">{{ post.author.name|default:post.author.username }}</a>
</span>
<span class="action inline">
<span class="timestamp">
{% if post.edited %}
{{ post.edited | date }}
<i class="fa-solid fa-pencil"></i>
{% elif post.published %}
{{ post.published | date }}
{% else %}
{{ post.created | date }}
{% endif %}
</span>
</span>
{% if post.summary %}
<details>
<summary>{{ post.summary }}</summary>
{{ post.safe_content_local }}
</details>
{% else %}
{{ post.safe_content_local }}
</details>
{% else %}
{{ post.safe_content_local }}
{% endif %}
{% for attachment in post.attachments.all %}
<a href="{{ attachment.full_url.relative }}" class="download">
<div>
<i class="fa-solid fa-download"></i> {{ attachment.file_display_name }}
</div>
</a>
{% endfor %}
<div id="replies_{{ post.pk }}"></div>
</div>
{% empty %}
<div class="empty">{% trans 'no replies so far.' %}</div>
{% endfor %}
{% endif %}
{% for attachment in post.attachments.all %}
<a href="{{ attachment.full_url.relative }}" class="download">
<div>
<i class="fa-solid fa-download"></i> {{ attachment.file_display_name }}
</div>
</a>
{% endfor %}
<div id="replies_{{ post.pk }}"></div>
</div>
{% empty %}
<div class="empty">{% trans 'no replies so far.' %}</div>
{% endfor %}
{% endwith %}
{% if post %}
<form class="reply"
role="group"

View file

@ -25,6 +25,7 @@ urlpatterns = [
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("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>/boost", post_boost, name="post_boost"),
path("post/<int:post_id>/like", post_like, name="post_like"),

View file

@ -21,6 +21,7 @@ from .note import note_edit
from .post import (
piece_replies,
post_boost,
post_delete,
post_like,
post_replies,
post_reply,

View file

@ -1,5 +1,6 @@
from django.contrib.auth.decorators import login_required
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.urls import reverse
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"])
@login_required
def post_reply(request: AuthedHttpRequest, post_id: int):

@ -1 +1 @@
Subproject commit f43ecdbab3c7caeb74d91d5566dd791ebdc3c59f
Subproject commit 65f4163e5f6a5b4c4d6af8c9825681d9005189ba