feat: implement scene deletion functionality

Added a new `SceneDeleteView` to `views.py`, enabling users to delete scenes directly from the UI. The corresponding URL pattern for scene deletion has been defined in `urls.py`. In addition, the category template (`category.html`) has been updated to include delete action icons alongside existing edit/view actions for each scene. This update enhances user control by allowing for the efficient management and removal of scenes from a project's category listing.

This change addresses user feedback requesting more intuitive content management capabilities within the application. Particularly, it simplifies the workflow for users managing large numbers of scenes, improving the overall user experience by streamlining content administration tasks.
This commit is contained in:
Kumi 2024-05-07 16:16:05 +02:00
parent 520cd80325
commit 2aa568769d
Signed by: kumi
GPG key ID: ECBCC9082395383F
3 changed files with 32 additions and 2 deletions

View file

@ -98,7 +98,9 @@
<a href="/tours/scene/{{ scene.id }}/edit/">{{ scene.title }}</a>
</td>
<td>
<!-- TODO: Actions like Edit/Delete will go here -->
<a href="/tours/scene/{{ scene.id }}/"><i class="ph-light ph-eye"></i></a>
<a href="/tours/scene/{{ scene.id }}/edit/"><i class="ph-light ph-pencil"></i></a>
<a title="Delete" style="color: red;" href="{% url "quackscape.users:scene-delete" category.id scene.id %}"><i class="ph-light ph-trash"></i></a>
</td>
</tr>
{% endfor %}

View file

@ -9,6 +9,7 @@ from .views import (
CategoryDeleteView,
CategoryUpdateView,
MediaDeleteView,
SceneDeleteView,
)
from django.urls import path
@ -40,6 +41,11 @@ urlpatterns = [
MediaDeleteView.as_view(),
name="media-delete",
),
path(
"category/<uuid:category>/scene/<uuid:scene>/delete/",
SceneDeleteView.as_view(),
name="scene-delete",
),
path("login/", Login.as_view(), name="login"),
path("logout/", Logout.as_view(), name="logout"),
]

View file

@ -171,7 +171,29 @@ class MediaDeleteView(LoginRequiredMixin, TitleMixin, DeleteView):
raise Http404()
def get_success_url(self):
return reverse_lazy("quackscape.users:category", kwargs={"category": self.kwargs["category"]})
return reverse_lazy(
"quackscape.users:category", kwargs={"category": self.kwargs["category"]}
)
class SceneDeleteView(LoginRequiredMixin, TitleMixin, DeleteView):
template_name = "users/generic_delete.html"
title = "Delete Scene"
model = OriginalMedia
def get_object(self):
try:
media = OriginalMedia.objects.get(id=self.kwargs["media"])
assert media.user_has_permission(self.request.user)
return media
except (OriginalMedia.DoesNotExist, AssertionError):
raise Http404()
def get_success_url(self):
return reverse_lazy(
"quackscape.users:category", kwargs={"category": self.kwargs["category"]}
)
class Login(TitleMixin, LoginView):
title = "Login"