summaryrefslogtreecommitdiff
path: root/ishtar_common/forms_common.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/forms_common.py')
-rw-r--r--ishtar_common/forms_common.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py
index 822efadda..a24d2396e 100644
--- a/ishtar_common/forms_common.py
+++ b/ishtar_common/forms_common.py
@@ -2603,6 +2603,7 @@ class GISForm(forms.ModelForm, CustomForm, ManageOldType):
"data_type": models.GeoDataType,
"origin": models.GeoOriginType,
"provider": models.GeoProviderType,
+ "buffer_type": models.GeoBufferType,
}
pk = forms.IntegerField(label="", required=False, widget=forms.HiddenInput)
@@ -2631,12 +2632,16 @@ class GISForm(forms.ModelForm, CustomForm, ManageOldType):
provider = widgets.ModelChoiceField(
model=models.GeoProviderType, label=_("Provider"), choices=[], required=False
)
+ buffer_type = widgets.ModelChoiceField(
+ model=models.GeoBufferType, label=_("Buffer type"), choices=[], required=False
+ )
comment = forms.CharField(label=_("Comment"), widget=forms.Textarea, required=False)
TYPES = [
FieldType("origin", models.GeoOriginType),
FieldType("data_type", models.GeoDataType),
FieldType("provider", models.GeoProviderType),
+ FieldType("buffer_type", models.GeoBufferType),
]
class Meta:
@@ -2649,6 +2654,7 @@ class GISForm(forms.ModelForm, CustomForm, ManageOldType):
_("Related items"), collapse=True),
"name": FormHeader(_("Meta-data")),
"geo_field": FormHeader(_("Geography")),
+ "buffer": FormHeader(_("Buffer"), collapse=True),
}
OPTIONS_PERMISSIONS = [
# field name, permission, options
@@ -2735,6 +2741,7 @@ class GISForm(forms.ModelForm, CustomForm, ManageOldType):
def _get_base_geo_keys(self):
geo_keys = []
+ extra_geo = ["buffer", "buffer_type"]
if self.geom_type == "coordinates":
geo_keys = [
"x", "estimated_error_x",
@@ -2767,7 +2774,7 @@ class GISForm(forms.ModelForm, CustomForm, ManageOldType):
self.fields.pop(geo_field)
if self.geom_type == "point_3d":
geo_keys = list(geo_keys) + ["z"]
- return geo_keys
+ return geo_keys + extra_geo
def _get_instance_geo_keys(self, instance):
# geo keys for an instanced item
@@ -2814,6 +2821,18 @@ class GISForm(forms.ModelForm, CustomForm, ManageOldType):
def clean(self):
cleaned_data = self.cleaned_data
+ if cleaned_data.get("buffer", None) \
+ and not cleaned_data.get("buffer_type", None):
+ raise forms.ValidationError(
+ _("If you set a buffer set a buffer type.")
+ )
+ if cleaned_data.get("buffer_type", None) \
+ and not cleaned_data.get("buffer", None):
+ raise forms.ValidationError(
+ _("If you set a buffer type set a buffer.")
+ )
+
+
if "x" not in self.geo_keys:
# reverse...
geo_value = cleaned_data[self.geo_keys[0]]