diff --git a/intervention/templates/intervention/new/view.html b/intervention/templates/intervention/new/view.html
index d543b7a3..ccd43fe9 100644
--- a/intervention/templates/intervention/new/view.html
+++ b/intervention/templates/intervention/new/view.html
@@ -12,6 +12,5 @@
{% endblock %}
{% block body %}
-
{{data_form.form_title}}
{% include 'form/main_data_collapse_form.html' %}
{% endblock %}
\ No newline at end of file
diff --git a/intervention/views.py b/intervention/views.py
index 11fa06fa..b7caceb8 100644
--- a/intervention/views.py
+++ b/intervention/views.py
@@ -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 INTERVENTION_INVALID
+from konova.utils.message_templates import INTERVENTION_INVALID, FORM_INVALID
from konova.utils.user_checks import in_group
@@ -76,12 +76,12 @@ def new_view(request: HttpRequest):
messages.success(request, _("Intervention {} added").format(intervention.identifier))
return redirect("intervention:index")
else:
- messages.error(request, _("Invalid input"))
+ messages.error(request, FORM_INVALID)
else:
# For clarification: nothing in this case
pass
context = {
- "data_form": data_form,
+ "form": data_form,
"geom_form": geom_form,
"url": reverse("intervention:new-id")
}
@@ -255,12 +255,12 @@ def edit_view(request: HttpRequest, id: str):
messages.success(request, _("Intervention {} edited").format(intervention.identifier))
return redirect("intervention:open", id=intervention.id)
else:
- messages.error(request, _("Invalid input"))
+ messages.error(request, FORM_INVALID)
else:
# For clarification: nothing in this case
pass
context = {
- "data_form": data_form,
+ "form": data_form,
"geom_form": geom_form,
}
context = BaseContext(request, context).context
diff --git a/konova/autocompletes.py b/konova/autocompletes.py
index 94798b96..196f78df 100644
--- a/konova/autocompletes.py
+++ b/konova/autocompletes.py
@@ -104,12 +104,18 @@ class KonovaCodeAutocomplete(Select2QuerySetView):
code_lists__in=[self.c]
)
if self.q:
- q_or = Q()
- q_or |= Q(long_name__icontains=self.q)
- q_or |= Q(short_name__icontains=self.q)
- q_or |= Q(parent__long_name__icontains=self.q)
- q_or |= Q(parent__short_name__icontains=self.q)
- qs = qs.filter(q_or).distinct()
+ # Remove whitespaces from self.q and split input in all keywords (if multiple given)
+ q = dict.fromkeys(self.q.strip().split(" "))
+ # Create one filter looking up for all keys where all keywords can be found in the same result
+ _filter = Q()
+ for keyword in q:
+ q_or = Q()
+ q_or |= Q(long_name__icontains=keyword)
+ q_or |= Q(short_name__icontains=keyword)
+ q_or |= Q(parent__long_name__icontains=keyword)
+ q_or |= Q(parent__short_name__icontains=keyword)
+ _filter.add(q_or, Q.AND)
+ qs = qs.filter(_filter).distinct()
return qs
diff --git a/konova/forms.py b/konova/forms.py
index eeed9744..0e6ad47e 100644
--- a/konova/forms.py
+++ b/konova/forms.py
@@ -263,15 +263,14 @@ class SimpleGeomForm(BaseForm):
# Initialize geometry
try:
geom = self.instance.geometry.geom
- if geom is None:
- raise AttributeError
+ self.empty = geom.empty
except AttributeError:
- # catches if no geometry has been added, yet. Replace with empty placeholder polygon.
- geom = Polygon.from_bbox([0, 0, 0, 0])
- # Zoom out to a very high level, so the user can see directly that there is no geometry for this entry
+ # If no geometry exists for this form, we simply set the value to None and zoom to the maximum level
+ geom = None
+ self.empty = True
self.fields["geom"].widget.attrs["default_zoom"] = 1
+
self.initialize_form_field("geom", geom)
- self.area = geom.area
if read_only:
self.fields["geom"].disabled = True
diff --git a/konova/models.py b/konova/models.py
index 40711259..20f78549 100644
--- a/konova/models.py
+++ b/konova/models.py
@@ -63,7 +63,7 @@ class BaseResource(UuidModel):
abstract = True
def delete(self, using=None, keep_parents=False):
- """ Base deletin of a resource
+ """ Base deleting of a resource
Args:
using ():
@@ -74,7 +74,7 @@ class BaseResource(UuidModel):
"""
try:
self.created.delete()
- except ObjectDoesNotExist:
+ except (ObjectDoesNotExist, AttributeError) as e:
# Object does not exist anymore - we can skip this
pass
super().delete()
diff --git a/templates/form/main_data_collapse_form.html b/templates/form/main_data_collapse_form.html
index 2c783e4c..e219fb88 100644
--- a/templates/form/main_data_collapse_form.html
+++ b/templates/form/main_data_collapse_form.html
@@ -32,9 +32,7 @@
- {% with data_form as form %}
- {% include 'form/generic_table_form_body.html' %}
- {% endwith %}
+ {% include 'form/generic_table_form_body.html' %}
@@ -54,7 +52,6 @@
-