# Remove View refactoring
* refactors remove view for kom, eiv, oek and ema * introduces BaseRemoveModalFormView * moves html blocking logic from BaseModalForm into BaseModalFormView
This commit is contained in:
@@ -106,7 +106,7 @@ class NewCompensationStateModalForm(BaseModalForm):
|
||||
|
||||
"""
|
||||
redirect_url = redirect_url if redirect_url is not None else request.META.get("HTTP_REFERER", "home")
|
||||
template = self.template
|
||||
template = self._TEMPLATE
|
||||
if request.method == "POST":
|
||||
if self.is_valid():
|
||||
# Modal forms send one POST for checking on data validity. This can be used to return possible errors
|
||||
|
||||
@@ -18,8 +18,8 @@ from compensation.views.compensation.action import NewCompensationActionView, Ed
|
||||
from compensation.views.compensation.state import NewCompensationStateView, EditCompensationStateView, \
|
||||
RemoveCompensationStateView
|
||||
from compensation.views.compensation.compensation import \
|
||||
remove_view, CompensationIndexView, CompensationIdentifierGeneratorView, CompensationDetailView, \
|
||||
NewCompensationFormView, EditCompensationFormView
|
||||
CompensationIndexView, CompensationIdentifierGeneratorView, CompensationDetailView, \
|
||||
NewCompensationFormView, EditCompensationFormView, RemoveCompensationView
|
||||
from compensation.views.compensation.log import CompensationLogView
|
||||
|
||||
urlpatterns = [
|
||||
@@ -31,7 +31,7 @@ urlpatterns = [
|
||||
path('<id>', CompensationDetailView.as_view(), name='detail'),
|
||||
path('<id>/log', CompensationLogView.as_view(), name='log'),
|
||||
path('<id>/edit', EditCompensationFormView.as_view(), name='edit'),
|
||||
path('<id>/remove', remove_view, name='remove'),
|
||||
path('<id>/remove', RemoveCompensationView.as_view(), name='remove'),
|
||||
|
||||
path('<id>/state/new', NewCompensationStateView.as_view(), name='new-state'),
|
||||
path('<id>/state/<state_id>/edit', EditCompensationStateView.as_view(), name='state-edit'),
|
||||
|
||||
@@ -8,9 +8,8 @@ Created on: 24.08.21
|
||||
from django.urls import path
|
||||
|
||||
from compensation.autocomplete.eco_account import EcoAccountAutocomplete
|
||||
from compensation.views.eco_account.eco_account import remove_view, \
|
||||
EcoAccountIndexView, EcoAccountIdentifierGeneratorView, EcoAccountDetailView, NewEcoAccountFormView, \
|
||||
EditEcoAccountFormView
|
||||
from compensation.views.eco_account.eco_account import EcoAccountIndexView, EcoAccountIdentifierGeneratorView, \
|
||||
EcoAccountDetailView, NewEcoAccountFormView, EditEcoAccountFormView, RemoveEcoAccountView
|
||||
from compensation.views.eco_account.log import EcoAccountLogView
|
||||
from compensation.views.eco_account.record import EcoAccountRecordView
|
||||
from compensation.views.eco_account.report import EcoAccountReportView
|
||||
@@ -37,7 +36,7 @@ urlpatterns = [
|
||||
path('<id>/record', EcoAccountRecordView.as_view(), name='record'),
|
||||
path('<id>/report', EcoAccountReportView.as_view(), name='report'),
|
||||
path('<id>/edit', EditEcoAccountFormView.as_view(), name='edit'),
|
||||
path('<id>/remove', remove_view, name='remove'),
|
||||
path('<id>/remove', RemoveEcoAccountView.as_view(), name='remove'),
|
||||
path('<id>/resub', EcoAccountResubmissionView.as_view(), name='resubmission-create'),
|
||||
|
||||
path('<id>/state/new', NewEcoAccountStateView.as_view(), name='new-state'),
|
||||
|
||||
@@ -25,6 +25,7 @@ from konova.utils.message_templates import COMPENSATION_REMOVED_TEMPLATE, DATA_C
|
||||
from konova.views.base import BaseIndexView, BaseIdentifierGeneratorView, BaseNewSpatialLocatedObjectFormView, \
|
||||
BaseEditSpatialLocatedObjectFormView
|
||||
from konova.views.detail import BaseDetailView
|
||||
from konova.views.remove import BaseRemoveModalFormView
|
||||
|
||||
|
||||
class CompensationIndexView(LoginRequiredMixin, BaseIndexView):
|
||||
@@ -164,25 +165,10 @@ class CompensationDetailView(BaseDetailView):
|
||||
return 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"),
|
||||
)
|
||||
class RemoveCompensationView(LoginRequiredMixin, BaseRemoveModalFormView):
|
||||
_MODEL_CLS = Compensation
|
||||
_FORM_CLS = RemoveModalForm
|
||||
_REDIRECT_URL = "compensation:index"
|
||||
|
||||
def _user_has_permission(self, user):
|
||||
return user.is_default_user()
|
||||
|
||||
@@ -22,6 +22,10 @@ class NewEcoAccountDeductionView(LoginRequiredMixin, AbstractNewDeductionView):
|
||||
if not obj.recorded:
|
||||
raise Http404()
|
||||
|
||||
def _check_for_recorded_instance(self, obj):
|
||||
# Deductions can be created on recorded as well as on non-recorded entries
|
||||
return None
|
||||
|
||||
|
||||
class EditEcoAccountDeductionView(LoginRequiredMixin, AbstractEditDeductionView):
|
||||
_MODEL_CLS = EcoAccount
|
||||
|
||||
@@ -26,6 +26,7 @@ from konova.utils.message_templates import CANCEL_ACC_RECORDED_OR_DEDUCTED, RECO
|
||||
from konova.views.base import BaseIndexView, BaseIdentifierGeneratorView, BaseNewSpatialLocatedObjectFormView, \
|
||||
BaseEditSpatialLocatedObjectFormView
|
||||
from konova.views.detail import BaseDetailView
|
||||
from konova.views.remove import BaseRemoveModalFormView
|
||||
|
||||
|
||||
class EcoAccountIndexView(LoginRequiredMixin, BaseIndexView):
|
||||
@@ -254,34 +255,10 @@ class EcoAccountDetailView(BaseDetailView):
|
||||
return 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"),
|
||||
)
|
||||
class RemoveEcoAccountView(LoginRequiredMixin, BaseRemoveModalFormView):
|
||||
_MODEL_CLS = EcoAccount
|
||||
_FORM_CLS = RemoveEcoAccountModalForm
|
||||
_REDIRECT_URL = "compensation:acc:index"
|
||||
|
||||
def _user_has_permission(self, user):
|
||||
return user.is_default_user()
|
||||
|
||||
Reference in New Issue
Block a user