# BaseModalFormView refactoring
* extends BaseModalFormView to hold general logic for processing GET and POST requests for BaseModalForm endpoints * refactors uuid check to use a specific parameter instead of kwargs * fixes css bug where modal form input elements would not be visible * refactors check view for intervention from function to class * refactors DeductionViews to inherit from extended BaseModalFormView
This commit is contained in:
@@ -5,35 +5,26 @@ Contact: ksp-servicestelle@sgdnord.rlp.de
|
||||
Created on: 19.08.22
|
||||
|
||||
"""
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.http import HttpRequest
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from intervention.forms.modals.check import CheckModalForm
|
||||
from intervention.models import Intervention
|
||||
from konova.decorators import registration_office_group_required, shared_access_required
|
||||
from konova.utils.message_templates import INTERVENTION_INVALID
|
||||
from konova.views.base import BaseModalFormView
|
||||
|
||||
|
||||
@login_required
|
||||
@registration_office_group_required
|
||||
@shared_access_required(Intervention, "id")
|
||||
def check_view(request: HttpRequest, id: str):
|
||||
""" Renders check form for an intervention
|
||||
class InterventionCheckView(LoginRequiredMixin, BaseModalFormView):
|
||||
_MODEL_CLS = Intervention
|
||||
_FORM_CLS = CheckModalForm
|
||||
_MSG_SUCCESS = _("Check performed")
|
||||
_MSG_ERROR = INTERVENTION_INVALID
|
||||
_REDIRECT_URL = "intervention:detail"
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): Intervention's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
intervention = get_object_or_404(Intervention, id=id)
|
||||
form = CheckModalForm(request.POST or None, instance=intervention, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("Check performed"),
|
||||
msg_error=INTERVENTION_INVALID
|
||||
)
|
||||
def _user_has_permission(self, user):
|
||||
return user.is_zb_user()
|
||||
|
||||
def _get_redirect_url(self, *args, **kwargs):
|
||||
redirect_url = super()._get_redirect_url(*args, **kwargs)
|
||||
redirect_url += "#related_data"
|
||||
return redirect_url
|
||||
|
||||
@@ -8,19 +8,24 @@ Created on: 19.08.22
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
|
||||
from intervention.models import Intervention
|
||||
from konova.utils.message_templates import DEDUCTION_ADDED, DEDUCTION_EDITED, DEDUCTION_REMOVED
|
||||
from konova.views.deduction import AbstractNewDeductionView, AbstractEditDeductionView, AbstractRemoveDeductionView
|
||||
|
||||
_INTERVENTION_DETAIL_URL_NAME = "intervention:detail"
|
||||
|
||||
class NewInterventionDeductionView(LoginRequiredMixin, AbstractNewDeductionView):
|
||||
_MODEL = Intervention
|
||||
_REDIRECT_URL = "intervention:detail"
|
||||
_MODEL_CLS = Intervention
|
||||
_MSG_SUCCESS = DEDUCTION_ADDED
|
||||
_REDIRECT_URL = _INTERVENTION_DETAIL_URL_NAME
|
||||
|
||||
|
||||
class EditInterventionDeductionView(LoginRequiredMixin, AbstractEditDeductionView):
|
||||
_MODEL = Intervention
|
||||
_REDIRECT_URL = "intervention:detail"
|
||||
_MODEL_CLS = Intervention
|
||||
_MSG_SUCCESS = DEDUCTION_EDITED
|
||||
_REDIRECT_URL = _INTERVENTION_DETAIL_URL_NAME
|
||||
|
||||
|
||||
class RemoveInterventionDeductionView(LoginRequiredMixin, AbstractRemoveDeductionView):
|
||||
_MODEL = Intervention
|
||||
_REDIRECT_URL = "intervention:detail"
|
||||
_MODEL_CLS = Intervention
|
||||
_MSG_SUCCESS = DEDUCTION_REMOVED
|
||||
_REDIRECT_URL = _INTERVENTION_DETAIL_URL_NAME
|
||||
|
||||
Reference in New Issue
Block a user