# Remove-KOM-from-EIV view
* refactors view method into class
This commit is contained in:
@@ -5,42 +5,50 @@ Contact: ksp-servicestelle@sgdnord.rlp.de
|
||||
Created on: 19.08.22
|
||||
|
||||
"""
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.http import HttpRequest, Http404
|
||||
from django.http import HttpRequest, Http404, HttpResponse
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views import View
|
||||
|
||||
from intervention.models import Intervention
|
||||
from konova.decorators import shared_access_required, login_required_modal
|
||||
from konova.decorators import shared_access_required
|
||||
from konova.forms.modals import RemoveModalForm
|
||||
from konova.utils.message_templates import COMPENSATION_REMOVED_TEMPLATE
|
||||
|
||||
|
||||
@login_required_modal
|
||||
@login_required
|
||||
@shared_access_required(Intervention, "id")
|
||||
def remove_compensation_view(request: HttpRequest, id: str, comp_id: str):
|
||||
""" Renders a modal view for removing the compensation
|
||||
class RemoveCompensationFromInterventionView(LoginRequiredMixin, View):
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The compensation's id
|
||||
def __process_request(self, request: HttpRequest, id: str, comp_id: str, *args, **kwargs) -> HttpResponse:
|
||||
""" Renders a modal view for removing the compensation
|
||||
|
||||
Returns:
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The compensation's id
|
||||
|
||||
"""
|
||||
intervention = get_object_or_404(Intervention, id=id)
|
||||
try:
|
||||
comp = intervention.compensations.get(
|
||||
id=comp_id
|
||||
Returns:
|
||||
|
||||
"""
|
||||
intervention = get_object_or_404(Intervention, id=id)
|
||||
try:
|
||||
comp = intervention.compensations.get(
|
||||
id=comp_id
|
||||
)
|
||||
except ObjectDoesNotExist:
|
||||
raise Http404("Unknown compensation")
|
||||
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("intervention:detail", args=(id,)) + "#related_data",
|
||||
)
|
||||
except ObjectDoesNotExist:
|
||||
raise Http404("Unknown compensation")
|
||||
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("intervention:detail", args=(id,)) + "#related_data",
|
||||
)
|
||||
|
||||
@method_decorator(shared_access_required(Intervention, "id"))
|
||||
def get(self, request, id: str, comp_id: str, *args, **kwargs) -> HttpResponse:
|
||||
return self.__process_request(request, id, comp_id, *args, **kwargs)
|
||||
|
||||
@method_decorator(shared_access_required(Intervention, "id"))
|
||||
def post(self, request, id: str, comp_id: str, *args, **kwargs) -> HttpResponse:
|
||||
return self.__process_request(request, id, comp_id, *args, **kwargs)
|
||||
Reference in New Issue
Block a user