#7 New Form
* extends KonovaCode filtering for parent objects matching given input * renames data_form into form for easier template render support * simplifies empty geometry form initialization
This commit is contained in:
parent
f3f5cc2b50
commit
1965721dea
@ -12,6 +12,5 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<h2>{{data_form.form_title}}</h2>
|
|
||||||
{% include 'form/main_data_collapse_form.html' %}
|
{% include 'form/main_data_collapse_form.html' %}
|
||||||
{% endblock %}
|
{% endblock %}
|
@ -13,7 +13,7 @@ from konova.decorators import *
|
|||||||
from konova.forms import SimpleGeomForm, NewDocumentForm, RemoveModalForm, RecordModalForm
|
from konova.forms import SimpleGeomForm, NewDocumentForm, RemoveModalForm, RecordModalForm
|
||||||
from konova.sub_settings.django_settings import DEFAULT_DATE_FORMAT
|
from konova.sub_settings.django_settings import DEFAULT_DATE_FORMAT
|
||||||
from konova.utils.documents import remove_document, get_document
|
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
|
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))
|
messages.success(request, _("Intervention {} added").format(intervention.identifier))
|
||||||
return redirect("intervention:index")
|
return redirect("intervention:index")
|
||||||
else:
|
else:
|
||||||
messages.error(request, _("Invalid input"))
|
messages.error(request, FORM_INVALID)
|
||||||
else:
|
else:
|
||||||
# For clarification: nothing in this case
|
# For clarification: nothing in this case
|
||||||
pass
|
pass
|
||||||
context = {
|
context = {
|
||||||
"data_form": data_form,
|
"form": data_form,
|
||||||
"geom_form": geom_form,
|
"geom_form": geom_form,
|
||||||
"url": reverse("intervention:new-id")
|
"url": reverse("intervention:new-id")
|
||||||
}
|
}
|
||||||
@ -255,12 +255,12 @@ def edit_view(request: HttpRequest, id: str):
|
|||||||
messages.success(request, _("Intervention {} edited").format(intervention.identifier))
|
messages.success(request, _("Intervention {} edited").format(intervention.identifier))
|
||||||
return redirect("intervention:open", id=intervention.id)
|
return redirect("intervention:open", id=intervention.id)
|
||||||
else:
|
else:
|
||||||
messages.error(request, _("Invalid input"))
|
messages.error(request, FORM_INVALID)
|
||||||
else:
|
else:
|
||||||
# For clarification: nothing in this case
|
# For clarification: nothing in this case
|
||||||
pass
|
pass
|
||||||
context = {
|
context = {
|
||||||
"data_form": data_form,
|
"form": data_form,
|
||||||
"geom_form": geom_form,
|
"geom_form": geom_form,
|
||||||
}
|
}
|
||||||
context = BaseContext(request, context).context
|
context = BaseContext(request, context).context
|
||||||
|
@ -104,12 +104,18 @@ class KonovaCodeAutocomplete(Select2QuerySetView):
|
|||||||
code_lists__in=[self.c]
|
code_lists__in=[self.c]
|
||||||
)
|
)
|
||||||
if self.q:
|
if self.q:
|
||||||
q_or = Q()
|
# Remove whitespaces from self.q and split input in all keywords (if multiple given)
|
||||||
q_or |= Q(long_name__icontains=self.q)
|
q = dict.fromkeys(self.q.strip().split(" "))
|
||||||
q_or |= Q(short_name__icontains=self.q)
|
# Create one filter looking up for all keys where all keywords can be found in the same result
|
||||||
q_or |= Q(parent__long_name__icontains=self.q)
|
_filter = Q()
|
||||||
q_or |= Q(parent__short_name__icontains=self.q)
|
for keyword in q:
|
||||||
qs = qs.filter(q_or).distinct()
|
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
|
return qs
|
||||||
|
|
||||||
|
|
||||||
|
@ -263,15 +263,14 @@ class SimpleGeomForm(BaseForm):
|
|||||||
# Initialize geometry
|
# Initialize geometry
|
||||||
try:
|
try:
|
||||||
geom = self.instance.geometry.geom
|
geom = self.instance.geometry.geom
|
||||||
if geom is None:
|
self.empty = geom.empty
|
||||||
raise AttributeError
|
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# catches if no geometry has been added, yet. Replace with empty placeholder polygon.
|
# If no geometry exists for this form, we simply set the value to None and zoom to the maximum level
|
||||||
geom = Polygon.from_bbox([0, 0, 0, 0])
|
geom = None
|
||||||
# Zoom out to a very high level, so the user can see directly that there is no geometry for this entry
|
self.empty = True
|
||||||
self.fields["geom"].widget.attrs["default_zoom"] = 1
|
self.fields["geom"].widget.attrs["default_zoom"] = 1
|
||||||
|
|
||||||
self.initialize_form_field("geom", geom)
|
self.initialize_form_field("geom", geom)
|
||||||
self.area = geom.area
|
|
||||||
if read_only:
|
if read_only:
|
||||||
self.fields["geom"].disabled = True
|
self.fields["geom"].disabled = True
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ class BaseResource(UuidModel):
|
|||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
def delete(self, using=None, keep_parents=False):
|
def delete(self, using=None, keep_parents=False):
|
||||||
""" Base deletin of a resource
|
""" Base deleting of a resource
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
using ():
|
using ():
|
||||||
@ -74,7 +74,7 @@ class BaseResource(UuidModel):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.created.delete()
|
self.created.delete()
|
||||||
except ObjectDoesNotExist:
|
except (ObjectDoesNotExist, AttributeError) as e:
|
||||||
# Object does not exist anymore - we can skip this
|
# Object does not exist anymore - we can skip this
|
||||||
pass
|
pass
|
||||||
super().delete()
|
super().delete()
|
||||||
|
@ -32,9 +32,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="dataCard" class="collapse" aria-labelledby="dataCardHeader">
|
<div id="dataCard" class="collapse" aria-labelledby="dataCardHeader">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
{% with data_form as form %}
|
{% include 'form/generic_table_form_body.html' %}
|
||||||
{% include 'form/generic_table_form_body.html' %}
|
|
||||||
{% endwith %}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -54,7 +52,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<a href="{{ form.cancel_redirect }}">
|
<a href="{{ form.cancel_redirect }}">
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
Encapsules the rendering and initializing of a geometry view component, e.g. used in the detail views.
|
Encapsules the rendering and initializing of a geometry view component, e.g. used in the detail views.
|
||||||
{% endcomment %}
|
{% endcomment %}
|
||||||
|
|
||||||
|
{% if geom_form.empty %}
|
||||||
{% if geom_form.area == 0 %}
|
|
||||||
<div class="alert alert-info">{% trans 'No geometry added, yet.' %}</div>
|
<div class="alert alert-info">{% trans 'No geometry added, yet.' %}</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{geom_form.media}}
|
{{geom_form.media}}
|
||||||
|
Loading…
Reference in New Issue
Block a user