From c5b24893309e270ac2e1a2857253e0e804f7ef5a Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 3 Apr 2021 12:30:18 -0700 Subject: [PATCH 01/14] Adds start of redraft view --- bookwyrm/status.py | 8 -------- bookwyrm/views/status.py | 29 +++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/bookwyrm/status.py b/bookwyrm/status.py index 7f075741..793bd742 100644 --- a/bookwyrm/status.py +++ b/bookwyrm/status.py @@ -1,18 +1,10 @@ """ Handle user activity """ from django.db import transaction -from django.utils import timezone from bookwyrm import models from bookwyrm.sanitize_html import InputHtmlParser -def delete_status(status): - """ replace the status with a tombstone """ - status.deleted = True - status.deleted_date = timezone.now() - status.save() - - def create_generated_note(user, content, mention_books=None, privacy="public"): """ a note created by the app about user activity """ # sanitize input html diff --git a/bookwyrm/views/status.py b/bookwyrm/views/status.py index fb548690..f86dc49d 100644 --- a/bookwyrm/views/status.py +++ b/bookwyrm/views/status.py @@ -3,6 +3,7 @@ import re from django.contrib.auth.decorators import login_required from django.http import HttpResponseBadRequest from django.shortcuts import get_object_or_404, redirect +from django.template.response import TemplateResponse from django.utils.decorators import method_decorator from django.views import View from markdown import markdown @@ -10,8 +11,8 @@ from markdown import markdown from bookwyrm import forms, models from bookwyrm.sanitize_html import InputHtmlParser from bookwyrm.settings import DOMAIN -from bookwyrm.status import delete_status from bookwyrm.utils import regex +from .feed import feed_page_data from .helpers import handle_remote_webfinger from .reading import edit_readthrough @@ -72,6 +73,7 @@ class CreateStatus(View): return redirect(request.headers.get("Referer", "/")) +@method_decorator(login_required, name="dispatch") class DeleteStatus(View): """ tombstone that bad boy """ @@ -84,10 +86,33 @@ class DeleteStatus(View): return HttpResponseBadRequest() # perform deletion - delete_status(status) + status.delete() return redirect(request.headers.get("Referer", "/")) +@method_decorator(login_required, name="dispatch") +class DeleteAndRedraft(View): + """ delete a status but let the user re-create it """ + + def post(self, request, status_id): + """ delete and tombstone a status """ + status = get_object_or_404(models.Status, id=status_id) + + # don't let people delete other people's statuses + if status.user != request.user and not request.user.has_perm("moderate_post"): + return HttpResponseBadRequest() + + # TODO: get the correct form (maybe a generic form) + redraft_form = forms.StatusForm(instance=status) + + # perform deletion + status.delete() + data = feed_page_data(request.user) + # TODO: set up the correct edit state + data['redraft_form'] = redraft_form + return TemplateResponse(request, 'feed/feed.html') + + def find_mentions(content): """ detect @mentions in raw status content """ if not content: From 8711a2eba51f9ef2b9e655e4d5701cabe5d7c82c Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 3 Apr 2021 12:31:28 -0700 Subject: [PATCH 02/14] Adds url path --- bookwyrm/urls.py | 1 + bookwyrm/views/__init__.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 2b874eb9..8e583a58 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -202,6 +202,7 @@ urlpatterns = [ re_path(r"%s/replies(.json)?/?$" % status_path, views.Replies.as_view()), re_path(r"^post/(?P\w+)/?$", views.CreateStatus.as_view()), re_path(r"^delete-status/(?P\d+)/?$", views.DeleteStatus.as_view()), + re_path(r"^redraft-status/(?P\d+)/?$", views.DeleteAndRedraft.as_view()), # interact re_path(r"^favorite/(?P\d+)/?$", views.Favorite.as_view()), re_path(r"^unfavorite/(?P\d+)/?$", views.Unfavorite.as_view()), diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 22e6071c..d053e971 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -31,7 +31,7 @@ from .shelf import Shelf from .shelf import create_shelf, delete_shelf from .shelf import shelve, unshelve from .site import Site -from .status import CreateStatus, DeleteStatus +from .status import CreateStatus, DeleteStatus, DeleteAndRedraft from .tag import Tag, AddTag, RemoveTag from .updates import get_notification_count, get_unread_status_count from .user import User, EditUser, Followers, Following From fb900d58cdeb866290d4804a49903c9a27638358 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 3 Apr 2021 12:38:12 -0700 Subject: [PATCH 03/14] Names status urls --- bookwyrm/urls.py | 26 ++++++++++++++++++++------ bookwyrm/views/status.py | 4 ++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 8e583a58..828d46bf 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -197,12 +197,26 @@ urlpatterns = [ re_path(r"^block/(?P\d+)/?$", views.Block.as_view()), re_path(r"^unblock/(?P\d+)/?$", views.unblock), # statuses - re_path(r"%s(.json)?/?$" % status_path, views.Status.as_view()), - re_path(r"%s/activity/?$" % status_path, views.Status.as_view()), - re_path(r"%s/replies(.json)?/?$" % status_path, views.Replies.as_view()), - re_path(r"^post/(?P\w+)/?$", views.CreateStatus.as_view()), - re_path(r"^delete-status/(?P\d+)/?$", views.DeleteStatus.as_view()), - re_path(r"^redraft-status/(?P\d+)/?$", views.DeleteAndRedraft.as_view()), + re_path(r"%s(.json)?/?$" % status_path, views.Status.as_view(), name="status"), + re_path(r"%s/activity/?$" % status_path, views.Status.as_view(), name="status"), + re_path( + r"%s/replies(.json)?/?$" % status_path, views.Replies.as_view(), name="replies" + ), + re_path( + r"^post/(?P\w+)/?$", + views.CreateStatus.as_view(), + name="create-status", + ), + re_path( + r"^delete-status/(?P\d+)/?$", + views.DeleteStatus.as_view(), + name="delete-status", + ), + re_path( + r"^redraft-status/(?P\d+)/?$", + views.DeleteAndRedraft.as_view(), + name="redraft", + ), # interact re_path(r"^favorite/(?P\d+)/?$", views.Favorite.as_view()), re_path(r"^unfavorite/(?P\d+)/?$", views.Unfavorite.as_view()), diff --git a/bookwyrm/views/status.py b/bookwyrm/views/status.py index f86dc49d..b68b7339 100644 --- a/bookwyrm/views/status.py +++ b/bookwyrm/views/status.py @@ -109,8 +109,8 @@ class DeleteAndRedraft(View): status.delete() data = feed_page_data(request.user) # TODO: set up the correct edit state - data['redraft_form'] = redraft_form - return TemplateResponse(request, 'feed/feed.html') + data["redraft_form"] = redraft_form + return TemplateResponse(request, "feed/feed.html") def find_mentions(content): From 029913de32756101b16aa45034cd450b1a292a4a Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 3 Apr 2021 13:06:36 -0700 Subject: [PATCH 04/14] Logic for rendering a particular compose tab server-side --- .../templates/snippets/create_status.html | 44 +++++++++++++++---- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/bookwyrm/templates/snippets/create_status.html b/bookwyrm/templates/snippets/create_status.html index 76357986..7dee4b70 100644 --- a/bookwyrm/templates/snippets/create_status.html +++ b/bookwyrm/templates/snippets/create_status.html @@ -2,36 +2,62 @@ {% load i18n %} {% load bookwyrm_tags %} +{% with status_type=request.GET.status_type %}
-
+
{% with 0|uuid as uuid %} {% include 'snippets/create_status_form.html' with type='review' %} {% endwith %}
-