#7 New forms WIP

* adds saving functionality for new intervention form
* refactors new identifier generating, so a pre-generated identifier from a new element form will be checked again before saving
* adds css fixes for disturbing input field:focus bugs
* adds missing csrf token to new collapsible form
* adds/updates translations
* introduces mark_as_deleted as only marking instead of using delete() which will really delete from the db
This commit is contained in:
mipel
2021-09-23 15:05:17 +02:00
parent 951477c58f
commit 9b728e5d10
11 changed files with 375 additions and 182 deletions

View File

@@ -59,11 +59,18 @@ def new_view(request: HttpRequest):
"""
template = "intervention/new/view.html"
form = NewInterventionForm(request.POST or None)
data_form = NewInterventionForm(request.POST or None)
geom_form = SimpleGeomForm(request.POST or None, read_only=False)
if request.method == "POST":
if form.is_valid():
intervention = form.save(request.user)
messages.success(request, _("Intervention {} added").format(intervention.title))
if data_form.is_valid() and geom_form.is_valid():
generated_identifier = data_form.cleaned_data.get("identifier", None)
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")
else:
messages.error(request, _("Invalid input"))
@@ -71,7 +78,8 @@ def new_view(request: HttpRequest):
# For clarification: nothing in this case
pass
context = {
"form": form,
"data_form": data_form,
"geom_form": geom_form,
}
context = BaseContext(request, context).context
return render(request, template, context)