Intervention Detail View
* adds hint for empty map in case of missing geometry * adds empty geometry workaround, so openlayers is rendered without digitalization tools * adds translations
This commit is contained in:
@@ -10,7 +10,8 @@ from abc import abstractmethod
|
||||
|
||||
from django import forms
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.gis.forms import GeometryField, OSMWidget, MultiPolygonField
|
||||
from django.contrib.gis.forms import GeometryField, OSMWidget
|
||||
from django.contrib.gis.geos import Polygon
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
@@ -101,6 +102,8 @@ class SimpleGeomForm(BaseForm):
|
||||
|
||||
"""
|
||||
geom = GeometryField(
|
||||
required=False,
|
||||
disabled=True,
|
||||
widget=OSMWidget(
|
||||
attrs={
|
||||
"map_width": 600,
|
||||
@@ -110,15 +113,17 @@ class SimpleGeomForm(BaseForm):
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""
|
||||
Constructor does not need to perform further initial setup, like other forms.
|
||||
We simply use this here for easy rendering of a geometry view component
|
||||
|
||||
Args:
|
||||
*args ():
|
||||
**kwargs ():
|
||||
"""
|
||||
super().__init__(*args, **kwargs)
|
||||
geom = self.instance.geometry.geom
|
||||
|
||||
# Initialize geometry
|
||||
try:
|
||||
geom = self.instance.geometry.geom
|
||||
if geom is None:
|
||||
raise AttributeError
|
||||
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
|
||||
self.fields["geom"].widget.attrs["default_zoom"] = 1
|
||||
self.initialize_form_field("geom", geom)
|
||||
self.disable_form_field("geom")
|
||||
self.area = geom.area
|
||||
|
||||
Reference in New Issue
Block a user