# Remove view

* refactors remove view methods into classes
* introduced AbstractRemoveView
* disables final-delete actions from admin views
* extends error warnings on RemoveEcoAccountModalForm
* removes LoginRequiredMixin from AbstractPublicReportView to make it accessible for the public
* updates translations
This commit is contained in:
2025-12-14 17:37:01 +01:00
parent a2bda8d230
commit 1af807deae
19 changed files with 235 additions and 176 deletions
+65
View File
@@ -0,0 +1,65 @@
"""
Author: Michel Peltriaux
Created on: 14.12.25
"""
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpRequest
from django.urls import reverse
from django.utils.decorators import method_decorator
from django.views import View
from django.utils.translation import gettext_lazy as _
from konova.decorators import default_group_required
from konova.forms.modals import RemoveModalForm
class AbstractRemoveView(LoginRequiredMixin, View):
_MODEL = None
_REDIRECT_URL = None
_FORM = RemoveModalForm
class Meta:
abstract = True
@method_decorator(default_group_required)
def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)
def __process_request(self, request: HttpRequest, id: str):
obj = self._MODEL.objects.get(id=id)
identifier = obj.identifier
form = self._FORM(request.POST or None, instance=obj, request=request)
return form.process_request(
request,
_("{} removed").format(identifier),
redirect_url=reverse(self._REDIRECT_URL)
)
def get(self, request: HttpRequest, id: str):
""" GET endpoint for removing via modal form
Due to the legacy logic of the form (which processes get and post requests directly), we simply need to pipe
the request from GET and POST endpoints directly into the same method.
Args:
request (HttpRequest): The incoming request
id (str): The uuid id as string
Returns:
"""
return self.__process_request(request, id)
def post(self, request: HttpRequest, id: str):
""" POST endpoint for removing via modal form
Due to the legacy logic of the form (which processes get and post requests directly), we simply need to pipe
the request from GET and POST endpoints directly into the same method.
Args:
request (HttpRequest): The incoming request
id (str): The uuid id as string
Returns:
"""
return self.__process_request(request, id)
+2 -6
View File
@@ -3,9 +3,8 @@ Author: Michel Peltriaux
Created on: 14.12.25
"""
from abc import abstractmethod
from abc import abstractmethod, ABC
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpRequest, HttpResponse
from django.utils.decorators import method_decorator
from django.views import View
@@ -13,12 +12,9 @@ from django.views import View
from konova.decorators import uuid_required
class AbstractPublicReportView(LoginRequiredMixin, View):
class AbstractPublicReportView(View, ABC):
_TEMPLATE = None
class Meta:
abstract = True
@method_decorator(uuid_required)
def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)