|
|
|
|
@@ -5,29 +5,22 @@ Contact: ksp-servicestelle@sgdnord.rlp.de
|
|
|
|
|
Created on: 19.08.22
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
from django.contrib import messages
|
|
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
|
|
|
from django.http import HttpRequest
|
|
|
|
|
from django.shortcuts import get_object_or_404, render, redirect
|
|
|
|
|
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.contexts import BaseContext
|
|
|
|
|
from konova.decorators import default_group_required, shared_access_required
|
|
|
|
|
from konova.forms import SimpleGeomForm
|
|
|
|
|
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
|
|
|
|
from konova.utils.message_templates import DATA_CHECKED_PREVIOUSLY_TEMPLATE, RECORDED_BLOCKS_EDIT, \
|
|
|
|
|
CHECK_STATE_RESET, FORM_INVALID, GEOMETRY_SIMPLIFIED, GEOMETRIES_IGNORED_TEMPLATE
|
|
|
|
|
from konova.views.base import BaseIndexView, BaseIdentifierGeneratorView, BaseNewSpatialLocatedObjectFormView, \
|
|
|
|
|
BaseEditSpatialLocatedObjectFormView
|
|
|
|
|
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, BaseIndexView):
|
|
|
|
|
class InterventionIndexView(LoginRequiredMixin, AbstractIndexView):
|
|
|
|
|
_INDEX_TABLE_CLS = InterventionTable
|
|
|
|
|
_TAB_TITLE = _("Interventions - Overview")
|
|
|
|
|
|
|
|
|
|
@@ -42,7 +35,7 @@ class InterventionIndexView(LoginRequiredMixin, BaseIndexView):
|
|
|
|
|
return qs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NewInterventionFormView(BaseNewSpatialLocatedObjectFormView):
|
|
|
|
|
class NewInterventionFormView(AbstractNewGeometryFormView):
|
|
|
|
|
_MODEL_CLS = Intervention
|
|
|
|
|
_FORM_CLS = NewInterventionForm
|
|
|
|
|
_TEMPLATE = "intervention/form/view.html"
|
|
|
|
|
@@ -50,7 +43,7 @@ class NewInterventionFormView(BaseNewSpatialLocatedObjectFormView):
|
|
|
|
|
_TAB_TITLE = _("New intervention")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EditInterventionFormView(BaseEditSpatialLocatedObjectFormView):
|
|
|
|
|
class EditInterventionFormView(AbstractEditGeometryFormView):
|
|
|
|
|
_MODEL_CLS = Intervention
|
|
|
|
|
_FORM_CLS = EditInterventionForm
|
|
|
|
|
_TEMPLATE = "intervention/form/view.html"
|
|
|
|
|
@@ -58,7 +51,7 @@ class EditInterventionFormView(BaseEditSpatialLocatedObjectFormView):
|
|
|
|
|
_TAB_TITLE = _("Edit {}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class InterventionIdentifierGeneratorView(LoginRequiredMixin, BaseIdentifierGeneratorView):
|
|
|
|
|
class InterventionIdentifierGeneratorView(LoginRequiredMixin, AbstractIdentifierGeneratorView):
|
|
|
|
|
_MODEL_CLS = Intervention
|
|
|
|
|
_REDIRECT_URL = "intervention:index"
|
|
|
|
|
|
|
|
|
|
@@ -117,69 +110,6 @@ class InterventionDetailView(BaseDetailView):
|
|
|
|
|
}
|
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
@default_group_required
|
|
|
|
|
@shared_access_required(Intervention, "id")
|
|
|
|
|
def edit_view(request: HttpRequest, id: str):
|
|
|
|
|
"""
|
|
|
|
|
Renders a view for editing interventions
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
request (HttpRequest): The incoming request
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
template = "intervention/form/view.html"
|
|
|
|
|
# Get object from db
|
|
|
|
|
intervention = get_object_or_404(Intervention, id=id)
|
|
|
|
|
if intervention.is_recorded:
|
|
|
|
|
messages.info(
|
|
|
|
|
request,
|
|
|
|
|
RECORDED_BLOCKS_EDIT
|
|
|
|
|
)
|
|
|
|
|
return redirect("intervention:detail", id=id)
|
|
|
|
|
|
|
|
|
|
# Create forms, initialize with values from db/from POST request
|
|
|
|
|
data_form = EditInterventionForm(request.POST or None, instance=intervention)
|
|
|
|
|
geom_form = SimpleGeomForm(request.POST or None, read_only=False, instance=intervention)
|
|
|
|
|
if request.method == "POST":
|
|
|
|
|
if data_form.is_valid() and geom_form.is_valid():
|
|
|
|
|
# The data form takes the geom form for processing, as well as the performing user
|
|
|
|
|
# Save the current state of recorded|checked to inform the user in case of a status reset due to editing
|
|
|
|
|
intervention_is_checked = intervention.checked is not None
|
|
|
|
|
intervention = data_form.save(request.user, geom_form)
|
|
|
|
|
messages.success(request, _("Intervention {} edited").format(intervention.identifier))
|
|
|
|
|
if intervention_is_checked:
|
|
|
|
|
messages.info(request, CHECK_STATE_RESET)
|
|
|
|
|
if geom_form.has_geometry_simplified():
|
|
|
|
|
messages.info(
|
|
|
|
|
request,
|
|
|
|
|
GEOMETRY_SIMPLIFIED
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
num_ignored_geometries = geom_form.get_num_geometries_ignored()
|
|
|
|
|
if num_ignored_geometries > 0:
|
|
|
|
|
messages.info(
|
|
|
|
|
request,
|
|
|
|
|
GEOMETRIES_IGNORED_TEMPLATE.format(num_ignored_geometries)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return redirect("intervention:detail", id=intervention.id)
|
|
|
|
|
else:
|
|
|
|
|
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
|
|
|
|
else:
|
|
|
|
|
# For clarification: nothing in this case
|
|
|
|
|
pass
|
|
|
|
|
context = {
|
|
|
|
|
"form": data_form,
|
|
|
|
|
"geom_form": geom_form,
|
|
|
|
|
TAB_TITLE_IDENTIFIER: _("Edit {}").format(intervention.identifier),
|
|
|
|
|
}
|
|
|
|
|
context = BaseContext(request, context).context
|
|
|
|
|
return render(request, template, context)
|
|
|
|
|
|
|
|
|
|
class RemoveInterventionView(LoginRequiredMixin, BaseRemoveModalFormView):
|
|
|
|
|
_MODEL_CLS = Intervention
|
|
|
|
|
_REDIRECT_URL = "intervention:index"
|
|
|
|
|
|