# 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:
@@ -10,7 +10,6 @@ from django.contrib.auth.decorators import login_required
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from django.shortcuts import get_object_or_404, render, redirect
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from compensation.forms.compensation import EditCompensationForm, NewCompensationForm
|
||||
@@ -18,13 +17,11 @@ from compensation.models import Compensation
|
||||
from compensation.tables.compensation import CompensationTable
|
||||
from intervention.models import Intervention
|
||||
from konova.contexts import BaseContext
|
||||
from konova.decorators import shared_access_required, default_group_required, login_required_modal
|
||||
from konova.decorators import shared_access_required, default_group_required
|
||||
from konova.forms import SimpleGeomForm
|
||||
from konova.forms.modals import RemoveModalForm
|
||||
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
||||
from konova.utils.message_templates import COMPENSATION_REMOVED_TEMPLATE, \
|
||||
RECORDED_BLOCKS_EDIT, CHECK_STATE_RESET, FORM_INVALID, PARAMS_INVALID, IDENTIFIER_REPLACED, \
|
||||
COMPENSATION_ADDED_TEMPLATE, GEOMETRY_SIMPLIFIED, GEOMETRIES_IGNORED_TEMPLATE
|
||||
from konova.utils.message_templates import RECORDED_BLOCKS_EDIT, CHECK_STATE_RESET, FORM_INVALID, PARAMS_INVALID, \
|
||||
IDENTIFIER_REPLACED, COMPENSATION_ADDED_TEMPLATE, GEOMETRY_SIMPLIFIED, GEOMETRIES_IGNORED_TEMPLATE
|
||||
from konova.views.identifier import AbstractIdentifierGeneratorView
|
||||
from konova.views.index import AbstractIndexView
|
||||
|
||||
@@ -194,26 +191,3 @@ def edit_view(request: HttpRequest, id: str):
|
||||
}
|
||||
context = BaseContext(request, context).context
|
||||
return render(request, template, context)
|
||||
|
||||
@login_required_modal
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(Compensation, "id")
|
||||
def remove_view(request: HttpRequest, id: str):
|
||||
""" Renders a modal view for removing the compensation
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The compensation's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
comp = get_object_or_404(Compensation, id=id)
|
||||
form = RemoveModalForm(request.POST or None, instance=comp, request=request)
|
||||
return form.process_request(
|
||||
request=request,
|
||||
msg_success=COMPENSATION_REMOVED_TEMPLATE.format(comp.identifier),
|
||||
redirect_url=reverse("compensation:index"),
|
||||
)
|
||||
|
||||
|
||||
20
compensation/views/compensation/remove.py
Normal file
20
compensation/views/compensation/remove.py
Normal file
@@ -0,0 +1,20 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Created on: 14.12.25
|
||||
|
||||
"""
|
||||
from django.http import HttpRequest
|
||||
from django.utils.decorators import method_decorator
|
||||
|
||||
from compensation.models import Compensation
|
||||
from konova.decorators import shared_access_required
|
||||
from konova.views.remove import AbstractRemoveView
|
||||
|
||||
|
||||
class RemoveCompensationView(AbstractRemoveView):
|
||||
_MODEL = Compensation
|
||||
_REDIRECT_URL = "compensation:index"
|
||||
|
||||
@method_decorator(shared_access_required(Compensation, "id"))
|
||||
def dispatch(self, request: HttpRequest, id: str, *args, **kwargs):
|
||||
return super().dispatch(request, id, *args, **kwargs)
|
||||
@@ -9,18 +9,16 @@ from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from compensation.forms.eco_account import EditEcoAccountForm, NewEcoAccountForm, RemoveEcoAccountModalForm
|
||||
from compensation.forms.eco_account import EditEcoAccountForm, NewEcoAccountForm
|
||||
from compensation.models import EcoAccount
|
||||
from compensation.tables.eco_account import EcoAccountTable
|
||||
from konova.contexts import BaseContext
|
||||
from konova.decorators import shared_access_required, default_group_required, login_required_modal
|
||||
from konova.decorators import shared_access_required, default_group_required
|
||||
from konova.forms import SimpleGeomForm
|
||||
from konova.settings import ETS_GROUP
|
||||
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
||||
from konova.utils.message_templates import CANCEL_ACC_RECORDED_OR_DEDUCTED, RECORDED_BLOCKS_EDIT, FORM_INVALID, \
|
||||
from konova.utils.message_templates import RECORDED_BLOCKS_EDIT, FORM_INVALID, \
|
||||
IDENTIFIER_REPLACED, GEOMETRY_SIMPLIFIED, GEOMETRIES_IGNORED_TEMPLATE
|
||||
from konova.views.identifier import AbstractIdentifierGeneratorView
|
||||
from konova.views.index import AbstractIndexView
|
||||
@@ -171,36 +169,3 @@ def edit_view(request: HttpRequest, id: str):
|
||||
}
|
||||
context = BaseContext(request, context).context
|
||||
return render(request, template, context)
|
||||
|
||||
|
||||
@login_required_modal
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(EcoAccount, "id")
|
||||
def remove_view(request: HttpRequest, id: str):
|
||||
""" Renders a modal view for removing the eco account
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The account's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
acc = get_object_or_404(EcoAccount, id=id)
|
||||
|
||||
# If the eco account has already been recorded OR there are already deductions, it can not be deleted by a regular
|
||||
# default group user
|
||||
if acc.recorded is not None or acc.deductions.exists():
|
||||
user = request.user
|
||||
if not user.in_group(ETS_GROUP):
|
||||
messages.info(request, CANCEL_ACC_RECORDED_OR_DEDUCTED)
|
||||
return redirect("compensation:acc:detail", id=id)
|
||||
|
||||
form = RemoveEcoAccountModalForm(request.POST or None, instance=acc, request=request)
|
||||
return form.process_request(
|
||||
request=request,
|
||||
msg_success=_("Eco-account removed"),
|
||||
redirect_url=reverse("compensation:acc:index"),
|
||||
)
|
||||
|
||||
|
||||
22
compensation/views/eco_account/remove.py
Normal file
22
compensation/views/eco_account/remove.py
Normal file
@@ -0,0 +1,22 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Created on: 14.12.25
|
||||
|
||||
"""
|
||||
from django.http import HttpRequest
|
||||
from django.utils.decorators import method_decorator
|
||||
|
||||
from compensation.forms.eco_account import RemoveEcoAccountModalForm
|
||||
from compensation.models import EcoAccount
|
||||
from konova.decorators import shared_access_required
|
||||
from konova.views.remove import AbstractRemoveView
|
||||
|
||||
|
||||
class RemoveEcoAccountView(AbstractRemoveView):
|
||||
_MODEL = EcoAccount
|
||||
_REDIRECT_URL = "compensation:acc:index"
|
||||
_FORM = RemoveEcoAccountModalForm
|
||||
|
||||
@method_decorator(shared_access_required(EcoAccount, "id"))
|
||||
def dispatch(self, request: HttpRequest, id: str, *args, **kwargs):
|
||||
return super().dispatch(request, id, *args, **kwargs)
|
||||
Reference in New Issue
Block a user