From 066f14ca846c5393aa960cdeeb1b36c389336bf2 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 14 Oct 2021 17:13:54 -0700 Subject: [PATCH] Save edited statuses --- .../snippets/create_status/layout.html | 2 +- bookwyrm/urls.py | 5 +++++ bookwyrm/views/status.py | 17 ++++++++++------- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/bookwyrm/templates/snippets/create_status/layout.html b/bookwyrm/templates/snippets/create_status/layout.html index 1343316fa..d824e270e 100644 --- a/bookwyrm/templates/snippets/create_status/layout.html +++ b/bookwyrm/templates/snippets/create_status/layout.html @@ -17,7 +17,7 @@ reply_parent: the Status object this post will be in reply to, if applicable
diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 8296493bd..e6c9ad0b4 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -328,6 +328,11 @@ urlpatterns = [ views.CreateStatus.as_view(), name="create-status", ), + re_path( + r"^post/(?P\w+)/(?P\d+)/?$", + views.CreateStatus.as_view(), + name="create-status", + ), re_path( r"^delete-status/(?P\d+)/?$", views.DeleteStatus.as_view(), diff --git a/bookwyrm/views/status.py b/bookwyrm/views/status.py index cddb5f59c..0b6db8995 100644 --- a/bookwyrm/views/status.py +++ b/bookwyrm/views/status.py @@ -40,11 +40,6 @@ class EditStatus(View): } return TemplateResponse(request, "compose.html", data) - def post(self, request, status_id): - """save an edited status""" - status = get_object_or_404(models.Status.select_subclasses(), id=status_id) - status.raise_not_editable(request.user) - # pylint: disable= no-self-use @method_decorator(login_required, name="dispatch") @@ -57,12 +52,20 @@ class CreateStatus(View): data = {"book": book} return TemplateResponse(request, "compose.html", data) - def post(self, request, status_type): + def post(self, request, status_type, existing_status_id=None): """create status of whatever type""" + if existing_status_id: + existing_status = get_object_or_404( + models.Status.select_subclasses(), id=existing_status_id + ) + existing_status.raise_not_editable(request.user) + status_type = status_type[0].upper() + status_type[1:] try: - form = getattr(forms, f"{status_type}Form")(request.POST) + form = getattr(forms, f"{status_type}Form")( + request.POST, instance=existing_status + ) except AttributeError: return HttpResponseBadRequest() if not form.is_valid():