Creates edit status endpoint

This commit is contained in:
Mouse Reeve 2021-10-14 16:30:27 -07:00
parent 1f6f543847
commit 7488f8da96
4 changed files with 26 additions and 3 deletions

View file

@ -20,7 +20,7 @@
</li>
{% if status.status_type != 'GeneratedNote' and status.status_type != 'Rating' %}
<li role="menuitem" class="dropdown-item p-0">
<form class="" name="edit-{{ status.id }}" action="{% url 'create-status' status.id %}" method="post">
<form class="" name="edit-{{ status.id }}" action="{% url 'edit-status' status.id %}" method="post">
{% csrf_token %}
<button class="button is-radiusless is-fullwidth is-small" type="submit">
{% trans "Edit" %}

View file

@ -315,6 +315,7 @@ urlpatterns = [
re_path(
rf"{STATUS_PATH}/replies(.json)?/?$", views.Replies.as_view(), name="replies"
),
re_path(r"^edit/(?P<status_id>\d+)/?$", views.EditStatus.as_view(), name="edit-status"),
re_path(
r"^post/?$",
views.CreateStatus.as_view(),

View file

@ -60,7 +60,7 @@ from .search import Search
from .shelf import Shelf
from .shelf import create_shelf, delete_shelf
from .shelf import shelve, unshelve
from .status import CreateStatus, DeleteStatus, update_progress
from .status import CreateStatus, EditStatus, DeleteStatus, update_progress
from .status import edit_readthrough
from .updates import get_notification_count, get_unread_status_count
from .user import User, Followers, Following, hide_suggestions

View file

@ -21,13 +21,35 @@ from .helpers import handle_remote_webfinger, is_api_request
from .helpers import load_date_in_user_tz_as_utc
# pylint: disable= no-self-use
@method_decorator(login_required, name="dispatch")
class EditStatus(View):
"""the view for *posting*"""
def get(self, request, status_id): # pylint: disable=unused-argument
"""load the edit panel"""
status = get_object_or_404(models.Status.select_subclasses(), id=status_id)
status.raise_not_editable(request.user)
data = {
"status": status,
}
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")
class CreateStatus(View):
"""the view for *posting*"""
def get(self, request, status_type): # pylint: disable=unused-argument
"""compose view (used for editing)"""
"""compose view (...not used?)"""
book = get_object_or_404(models.Edition, id=request.GET.get("book"))
data = {"book": book}
return TemplateResponse(request, "compose.html", data)