From 2aa568769de68e9709947924d0262397c87bc968 Mon Sep 17 00:00:00 2001 From: Kumi Date: Tue, 7 May 2024 16:16:05 +0200 Subject: [PATCH] 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. --- .../users/templates/users/category.html | 4 +++- quackscape/users/urls.py | 6 +++++ quackscape/users/views.py | 24 ++++++++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/quackscape/users/templates/users/category.html b/quackscape/users/templates/users/category.html index 8626725..ce4e605 100644 --- a/quackscape/users/templates/users/category.html +++ b/quackscape/users/templates/users/category.html @@ -98,7 +98,9 @@ {{ scene.title }} - + + + {% endfor %} diff --git a/quackscape/users/urls.py b/quackscape/users/urls.py index e42a3aa..ab62680 100644 --- a/quackscape/users/urls.py +++ b/quackscape/users/urls.py @@ -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//scene//delete/", + SceneDeleteView.as_view(), + name="scene-delete", + ), path("login/", Login.as_view(), name="login"), path("logout/", Logout.as_view(), name="logout"), ] diff --git a/quackscape/users/views.py b/quackscape/users/views.py index 4294da1..c3e429c 100644 --- a/quackscape/users/views.py +++ b/quackscape/users/views.py @@ -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"