""" 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.mixins import LoginRequiredMixin from django.shortcuts import get_object_or_404 from django.urls import reverse from compensation.models import Compensation from intervention.forms.modals.remove import RemoveCompensationFromInterventionModalForm from intervention.models import Intervention from konova.utils.message_templates import COMPENSATION_REMOVED_TEMPLATE from konova.views.remove import BaseRemoveModalFormView class RemoveCompensationFromInterventionView(LoginRequiredMixin, BaseRemoveModalFormView): _MODEL_CLS = Intervention _FORM_CLS = RemoveCompensationFromInterventionModalForm _MSG_SUCCESS = COMPENSATION_REMOVED_TEMPLATE _REDIRECT_URL = "intervention:detail" def _user_has_shared_access(self, user, **kwargs): compensation_id = kwargs.get("comp_id", None) compensation = get_object_or_404(Compensation, id=compensation_id) return compensation.is_shared_with(user) def _user_has_permission(self, user, **kwargs): return user.is_default_user() def _get_msg_success(self, *args, **kwargs): compensation_id = kwargs.get("comp_id", None) compensation = get_object_or_404(Compensation, id=compensation_id) return self._MSG_SUCCESS.format(compensation.identifier) def _get_redirect_url(self, *args, **kwargs): obj = kwargs.get("obj") return reverse(self._REDIRECT_URL, args=(obj.id,)) + "#related_data"