Save edited statuses

This commit is contained in:
Mouse Reeve 2021-10-14 17:13:54 -07:00
parent 8a08d789cb
commit 066f14ca84
3 changed files with 16 additions and 8 deletions

View file

@ -17,7 +17,7 @@ reply_parent: the Status object this post will be in reply to, if applicable
<form
class="is-flex-grow-1{% if not no_script %} submit-status{% endif %}"
name="{{ type }}"
action="{% url "create-status" type %}"
action="{% url "create-status" type draft.id %}"
method="post"
id="form_{{ type }}_{{ book.id }}{{ reply_parent.id }}"
>

View file

@ -328,6 +328,11 @@ urlpatterns = [
views.CreateStatus.as_view(),
name="create-status",
),
re_path(
r"^post/(?P<status_type>\w+)/(?P<existing_status_id>\d+)/?$",
views.CreateStatus.as_view(),
name="create-status",
),
re_path(
r"^delete-status/(?P<status_id>\d+)/?$",
views.DeleteStatus.as_view(),

View file

@ -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():