* renames certain classes to match their content * splits larger files into smaller ones
116 lines
3.7 KiB
Python
116 lines
3.7 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.mixins import LoginRequiredMixin
|
|
from django.shortcuts import get_object_or_404
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from intervention.forms.intervention import EditInterventionForm, NewInterventionForm
|
|
from intervention.models import Intervention
|
|
from intervention.tables import InterventionTable
|
|
from konova.utils.message_templates import DATA_CHECKED_PREVIOUSLY_TEMPLATE
|
|
from konova.views.identifier import AbstractIdentifierGeneratorView
|
|
from konova.views.form import AbstractNewGeometryFormView, AbstractEditGeometryFormView
|
|
from konova.views.index import AbstractIndexView
|
|
from konova.views.detail import BaseDetailView
|
|
from konova.views.remove import BaseRemoveModalFormView
|
|
|
|
|
|
class InterventionIndexView(LoginRequiredMixin, AbstractIndexView):
|
|
_INDEX_TABLE_CLS = InterventionTable
|
|
_TAB_TITLE = _("Interventions - Overview")
|
|
|
|
def _get_queryset(self):
|
|
qs = Intervention.objects.filter(
|
|
deleted=None,
|
|
).select_related(
|
|
"legal"
|
|
).order_by(
|
|
"-modified__timestamp"
|
|
)
|
|
return qs
|
|
|
|
|
|
class NewInterventionFormView(AbstractNewGeometryFormView):
|
|
_MODEL_CLS = Intervention
|
|
_FORM_CLS = NewInterventionForm
|
|
_TEMPLATE = "intervention/form/view.html"
|
|
_REDIRECT_URL = "intervention:detail"
|
|
_TAB_TITLE = _("New intervention")
|
|
|
|
|
|
class EditInterventionFormView(AbstractEditGeometryFormView):
|
|
_MODEL_CLS = Intervention
|
|
_FORM_CLS = EditInterventionForm
|
|
_TEMPLATE = "intervention/form/view.html"
|
|
_REDIRECT_URL = "intervention:detail"
|
|
_TAB_TITLE = _("Edit {}")
|
|
|
|
|
|
class InterventionIdentifierGeneratorView(LoginRequiredMixin, AbstractIdentifierGeneratorView):
|
|
_MODEL_CLS = Intervention
|
|
_REDIRECT_URL = "intervention:index"
|
|
|
|
|
|
class InterventionDetailView(BaseDetailView):
|
|
_MODEL_CLS = Intervention
|
|
_TEMPLATE = "intervention/detail/view.html"
|
|
|
|
def _get_object(self, id: str):
|
|
""" Returns the intervention
|
|
|
|
Args:
|
|
id (str): The intervention's id
|
|
|
|
Returns:
|
|
obj (Intervention): The intervention
|
|
"""
|
|
# Fetch data, filter out deleted related data
|
|
obj = get_object_or_404(
|
|
self._MODEL_CLS.objects.select_related(
|
|
"geometry",
|
|
"legal",
|
|
"responsible",
|
|
).prefetch_related(
|
|
"legal__revocations",
|
|
),
|
|
id=id,
|
|
deleted=None
|
|
)
|
|
return obj
|
|
|
|
def _get_detail_context(self, obj: Intervention):
|
|
""" Generate object specific detail context for view
|
|
|
|
Args:
|
|
obj (): The record
|
|
|
|
Returns:
|
|
|
|
"""
|
|
compensations = obj.compensations.filter(deleted=None)
|
|
last_checked = obj.get_last_checked_action()
|
|
last_checked_tooltip = ""
|
|
if last_checked:
|
|
last_checked_tooltip = DATA_CHECKED_PREVIOUSLY_TEMPLATE.format(
|
|
last_checked.get_timestamp_str_formatted(),
|
|
last_checked.user
|
|
)
|
|
|
|
has_payment_without_document = obj.payments.exists() and not obj.get_documents()[1].exists()
|
|
context = {
|
|
"last_checked": last_checked,
|
|
"last_checked_tooltip": last_checked_tooltip,
|
|
"compensations": compensations,
|
|
"has_payment_without_document": has_payment_without_document,
|
|
}
|
|
return context
|
|
|
|
class RemoveInterventionView(LoginRequiredMixin, BaseRemoveModalFormView):
|
|
_MODEL_CLS = Intervention
|
|
_REDIRECT_URL = "intervention:index"
|