Save edited statuses
This commit is contained in:
parent
8a08d789cb
commit
066f14ca84
|
@ -17,7 +17,7 @@ reply_parent: the Status object this post will be in reply to, if applicable
|
||||||
<form
|
<form
|
||||||
class="is-flex-grow-1{% if not no_script %} submit-status{% endif %}"
|
class="is-flex-grow-1{% if not no_script %} submit-status{% endif %}"
|
||||||
name="{{ type }}"
|
name="{{ type }}"
|
||||||
action="{% url "create-status" type %}"
|
action="{% url "create-status" type draft.id %}"
|
||||||
method="post"
|
method="post"
|
||||||
id="form_{{ type }}_{{ book.id }}{{ reply_parent.id }}"
|
id="form_{{ type }}_{{ book.id }}{{ reply_parent.id }}"
|
||||||
>
|
>
|
||||||
|
|
|
@ -328,6 +328,11 @@ urlpatterns = [
|
||||||
views.CreateStatus.as_view(),
|
views.CreateStatus.as_view(),
|
||||||
name="create-status",
|
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(
|
re_path(
|
||||||
r"^delete-status/(?P<status_id>\d+)/?$",
|
r"^delete-status/(?P<status_id>\d+)/?$",
|
||||||
views.DeleteStatus.as_view(),
|
views.DeleteStatus.as_view(),
|
||||||
|
|
|
@ -40,11 +40,6 @@ class EditStatus(View):
|
||||||
}
|
}
|
||||||
return TemplateResponse(request, "compose.html", data)
|
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
|
# pylint: disable= no-self-use
|
||||||
@method_decorator(login_required, name="dispatch")
|
@method_decorator(login_required, name="dispatch")
|
||||||
|
@ -57,12 +52,20 @@ class CreateStatus(View):
|
||||||
data = {"book": book}
|
data = {"book": book}
|
||||||
return TemplateResponse(request, "compose.html", data)
|
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"""
|
"""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:]
|
status_type = status_type[0].upper() + status_type[1:]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
form = getattr(forms, f"{status_type}Form")(request.POST)
|
form = getattr(forms, f"{status_type}Form")(
|
||||||
|
request.POST, instance=existing_status
|
||||||
|
)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
if not form.is_valid():
|
if not form.is_valid():
|
||||||
|
|
Loading…
Reference in New Issue