mpeltriaux
55a69d45c3
* splits intervention/views.py (+700 lines) into separate files in new module * view files can now be found in /intervention/views/...
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
"""
|
|
Author: Michel Peltriaux
|
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
|
Contact: ksp-servicestelle@sgdnord.rlp.de
|
|
Created on: 19.08.22
|
|
|
|
"""
|
|
from django.contrib.auth.decorators import login_required
|
|
from django.core.exceptions import ObjectDoesNotExist
|
|
from django.http import HttpRequest, Http404
|
|
from django.shortcuts import get_object_or_404
|
|
from django.urls import reverse
|
|
|
|
from intervention.models import Intervention
|
|
from konova.decorators import shared_access_required
|
|
from konova.forms.modals import RemoveModalForm
|
|
from konova.utils.message_templates import COMPENSATION_REMOVED_TEMPLATE
|
|
|
|
|
|
@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
|
|
|
|
Args:
|
|
request (HttpRequest): The incoming request
|
|
id (str): The compensation's 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",
|
|
)
|
|
|