* fixes bug in case of unset dates for intervention
* adds missing template formater
* adds/updates translations
This commit is contained in:
2021-09-27 11:12:40 +02:00
parent 7ee28e526e
commit e94dbbd3c8
5 changed files with 172 additions and 153 deletions

View File

@@ -265,6 +265,13 @@ class EditInterventionForm(NewInterventionForm):
self.form_title = _("Edit intervention")
self.form_caption = ""
reg_date = self.instance.legal.registration_date
bind_date = self.instance.legal.binding_date
if reg_date is not None:
reg_date = reg_date.isoformat()
if bind_date is not None:
bind_date = bind_date.isoformat()
# Initialize form data
form_data = {
"identifier": self.instance.identifier,
@@ -276,8 +283,8 @@ class EditInterventionForm(NewInterventionForm):
"registration_file_number": self.instance.responsible.registration_file_number,
"conservation_office": self.instance.responsible.conservation_office,
"conservation_file_number": self.instance.responsible.conservation_file_number,
"registration_date": self.instance.legal.registration_date.isoformat(),
"binding_date": self.instance.legal.binding_date.isoformat(),
"registration_date": reg_date,
"binding_date": bind_date,
"comment": self.instance.comment,
}
disabled_fields = [

View File

@@ -13,7 +13,7 @@ from konova.decorators import *
from konova.forms import SimpleGeomForm, NewDocumentForm, RemoveModalForm, RecordModalForm
from konova.sub_settings.django_settings import DEFAULT_DATE_FORMAT
from konova.utils.documents import remove_document, get_document
from konova.utils.message_templates import FORM_INVALID, INTERVENTION_INVALID
from konova.utils.message_templates import INTERVENTION_INVALID
from konova.utils.user_checks import in_group
@@ -68,7 +68,10 @@ def new_view(request: HttpRequest):
if generated_identifier != intervention.identifier:
messages.info(
request,
_("The identifier '{}' had to be changed to '{}' since another entry has been added in the meanwhile, which uses this identifier")
_("The identifier '{}' had to be changed to '{}' since another entry has been added in the meanwhile, which uses this identifier").format(
generated_identifier,
intervention.identifier
)
)
messages.success(request, _("Intervention {} added").format(intervention.identifier))
return redirect("intervention:index")
@@ -221,20 +224,17 @@ def edit_view(request: HttpRequest, id: str):
"""
template = "intervention/new/view.html"
# Get object from db
intervention = get_object_or_404(Intervention, 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():
generated_identifier = data_form.cleaned_data.get("identifier", None)
# The data form takes the geom form for processing, as well as the performing user
intervention = data_form.save(request.user, geom_form)
if generated_identifier != intervention.identifier:
messages.info(
request,
_("The identifier '{}' had to be changed to '{}' since another entry has been added in the meanwhile, which uses this identifier")
)
messages.success(request, _("Intervention {} added").format(intervention.identifier))
return redirect("intervention:index")
messages.success(request, _("Intervention {} edited").format(intervention.identifier))
return redirect("intervention:open", id=intervention.id)
else:
messages.error(request, _("Invalid input"))
else: