From 5709dba71ac2d9753b7a92e6b54a049829877669 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 20 Jun 2024 16:01:21 -0400 Subject: [PATCH] delete reply --- journal/templates/action_delete_post.html | 14 ++++ journal/templates/replies.html | 94 ++++++++++++----------- journal/urls.py | 1 + journal/views/__init__.py | 1 + journal/views/post.py | 16 ++++ neodb-takahe | 2 +- 6 files changed, 84 insertions(+), 44 deletions(-) create mode 100644 journal/templates/action_delete_post.html diff --git a/journal/templates/action_delete_post.html b/journal/templates/action_delete_post.html new file mode 100644 index 00000000..c98c265c --- /dev/null +++ b/journal/templates/action_delete_post.html @@ -0,0 +1,14 @@ +{% load i18n %} + + + {% if post.piece %} + + {% else %} + + {% endif %} + + diff --git a/journal/templates/replies.html b/journal/templates/replies.html index 43f62755..13df38ca 100644 --- a/journal/templates/replies.html +++ b/journal/templates/replies.html @@ -1,50 +1,58 @@ {% load i18n %} -
- {% for post in replies %} -
- - {% include "action_reply_post.html" %} - {% include "action_like_post.html" %} - {% include "action_boost_post.html" %} - {% include "action_open_post.html" %} - - - {{ post.author.name|default:post.author.username }} - - - - {% if post.edited %} - {{ post.edited | date }} - - {% elif post.published %} - {{ post.published | date }} - {% else %} - {{ post.created | date }} +
+ {% with parent_post=post %} + {% for post in replies %} +
+ + {% 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" %} - - {% if post.summary %} -
- {{ post.summary }} + + {{ post.author.name|default:post.author.username }} + + + + {% if post.edited %} + {{ post.edited | date }} + + {% elif post.published %} + {{ post.published | date }} + {% else %} + {{ post.created | date }} + {% endif %} + + + {% if post.summary %} +
+ {{ post.summary }} + {{ post.safe_content_local }} +
+ {% else %} {{ post.safe_content_local }} -
- {% else %} - {{ post.safe_content_local }} - {% endif %} - {% for attachment in post.attachments.all %} - -
- {{ attachment.file_display_name }} -
-
- {% endfor %} -
-
- {% empty %} -
{% trans 'no replies so far.' %}
- {% endfor %} + {% endif %} + {% for attachment in post.attachments.all %} + +
+ {{ attachment.file_display_name }} +
+
+ {% endfor %} +
+
+ {% empty %} +
{% trans 'no replies so far.' %}
+ {% endfor %} + {% endwith %} {% if post %}
/note/", note_edit, name="note"), path("piece//replies", piece_replies, name="piece_replies"), path("post//replies", post_replies, name="post_replies"), + path("post//delete", post_delete, name="post_delete"), path("post//reply", post_reply, name="post_reply"), path("post//boost", post_boost, name="post_boost"), path("post//like", post_like, name="post_like"), diff --git a/journal/views/__init__.py b/journal/views/__init__.py index 5774c91f..f3084e06 100644 --- a/journal/views/__init__.py +++ b/journal/views/__init__.py @@ -21,6 +21,7 @@ from .note import note_edit from .post import ( piece_replies, post_boost, + post_delete, post_like, post_replies, post_reply, diff --git a/journal/views/post.py b/journal/views/post.py index f46f3763..f1f12c49 100644 --- a/journal/views/post.py +++ b/journal/views/post.py @@ -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): diff --git a/neodb-takahe b/neodb-takahe index f43ecdba..65f4163e 160000 --- a/neodb-takahe +++ b/neodb-takahe @@ -1 +1 @@ -Subproject commit f43ecdbab3c7caeb74d91d5566dd791ebdc3c59f +Subproject commit 65f4163e5f6a5b4c4d6af8c9825681d9005189ba