7_New_forms #28
@ -12,6 +12,5 @@
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 | 
			
		||||
{% block body %}
 | 
			
		||||
    <h2>{{data_form.form_title}}</h2>
 | 
			
		||||
    {% include 'form/main_data_collapse_form.html' %}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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()
 | 
			
		||||
 | 
			
		||||
@ -32,9 +32,7 @@
 | 
			
		||||
            </div>
 | 
			
		||||
            <div id="dataCard" class="collapse" aria-labelledby="dataCardHeader">
 | 
			
		||||
                <div class="card-body">
 | 
			
		||||
                    {% with data_form as form %}
 | 
			
		||||
                        {% include 'form/generic_table_form_body.html' %}
 | 
			
		||||
                    {% endwith %}
 | 
			
		||||
                    {% include 'form/generic_table_form_body.html' %}
 | 
			
		||||
                </div>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
@ -54,7 +52,6 @@
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
    <div class="row">
 | 
			
		||||
        <div class="col-6">
 | 
			
		||||
            <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.
 | 
			
		||||
{% endcomment %}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
{% if geom_form.area == 0 %}
 | 
			
		||||
{% if geom_form.empty %}
 | 
			
		||||
    <div class="alert alert-info">{% trans 'No geometry added, yet.' %}</div>
 | 
			
		||||
{% endif %}
 | 
			
		||||
{{geom_form.media}}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user