summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2023-11-28 18:51:16 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2023-11-28 18:56:45 +0100
commitaac25d8d954eec47cb6211f58cb1f89d3bbc34d1 (patch)
tree50cf303bccffad3eda1030ba7ef43f254f507d6a
parent20954e71e00a2199dde84eb9d5aa42e3bcb155fa (diff)
downloadIshtar-aac25d8d954eec47cb6211f58cb1f89d3bbc34d1.tar.bz2
Ishtar-aac25d8d954eec47cb6211f58cb1f89d3bbc34d1.zip
🐛 New Geo item form: center map widget on the center of the main geo item or use default center of the instance (#5676)
-rw-r--r--changelog/en/changelog_2022-06-15.md2
-rw-r--r--changelog/fr/changelog_2023-01-25.md3
-rw-r--r--ishtar_common/forms_common.py29
-rw-r--r--ishtar_common/views.py3
4 files changed, 31 insertions, 6 deletions
diff --git a/changelog/en/changelog_2022-06-15.md b/changelog/en/changelog_2022-06-15.md
index f58362514..80b2a1591 100644
--- a/changelog/en/changelog_2022-06-15.md
+++ b/changelog/en/changelog_2022-06-15.md
@@ -9,6 +9,8 @@ v4.0.67 - 2023-11-28
- Document table: fix performance issue on sort (#5667)
- Document bulk update: fix to add new author (#5681)
- Custom form - add missing forms types (#5668)
+- New Geo item form: center map widget on the center of the main geo item or use default center of the instance (#5676)
+
v4.0.66 - 2023-11-22
--------------------
diff --git a/changelog/fr/changelog_2023-01-25.md b/changelog/fr/changelog_2023-01-25.md
index 020ac98a2..bc31a053c 100644
--- a/changelog/fr/changelog_2023-01-25.md
+++ b/changelog/fr/changelog_2023-01-25.md
@@ -1,4 +1,4 @@
-v4.0.67 - 2023-11-28
+v4.0.67 - 2023-11-29
--------------------
### Corrections de dysfonctionnements ###
@@ -9,6 +9,7 @@ v4.0.67 - 2023-11-28
- Table documents : correction d'un problĂšme de performance lors du tri (#5667)
- Document - Formulaire de mise à jour groupée : correction de l'ajout de nouveau auteur (#5681)
- Formulaire personalisé : ajout de type de formulaire manquants (#5668)
+- Formulaire nouvel élément géographique : widget de carte centré sur le centre de l'élément géographique principal ou à défaut au centre par défaut paramétré pour l'instance (#5676)
v4.0.66 - 2023-11-22
--------------------
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py
index 3747a03c6..a4a77c8f7 100644
--- a/ishtar_common/forms_common.py
+++ b/ishtar_common/forms_common.py
@@ -2792,7 +2792,8 @@ class GISForm(forms.ModelForm, CustomForm, ManageOldType):
self.is_instancied = bool(instance)
self.source_content_type = kwargs.pop("source_content_type", None)
self.source_id = kwargs.pop("source_id", None)
- super(GISForm, self).__init__(*args, **kwargs)
+ self.default_center = kwargs.pop("default_center") if "default_center" in kwargs else None
+ super().__init__(*args, **kwargs)
if back_url:
self.fields["back_url"] = forms.CharField(
label="", required=False, widget=forms.HiddenInput, initial=back_url)
@@ -2807,7 +2808,6 @@ class GISForm(forms.ModelForm, CustomForm, ManageOldType):
else:
self.fields["source_content_type_id"].initial = self.source_content_type
self.fields["source_id"].initial = self.source_id
- self.geo_keys = self.get_geo_keys(instance)
fields = OrderedDict()
for related_key in models.GeoVectorData.RELATED_MODELS:
@@ -2830,6 +2830,7 @@ class GISForm(forms.ModelForm, CustomForm, ManageOldType):
fields[field_key] = forms.BooleanField(
label=label, required=False, disabled=disabled
)
+ self.geo_keys = self.get_geo_keys(instance)
for k in self.geo_keys:
fields[k] = self.fields[k]
for k in self.fields:
@@ -2853,14 +2854,32 @@ class GISForm(forms.ModelForm, CustomForm, ManageOldType):
"z", "estimated_error_z",
"spatial_reference_system",
]
+ base_widget_attrs = {}
+ if self.default_center:
+ base_widget_attrs.update({
+ "default_lon": self.default_center[0],
+ "default_lat": self.default_center[1],
+ })
+ else:
+ profile = models.IshtarSiteProfile.get_current_profile()
+ if profile.default_center:
+ # TODO: reverse...
+ base_widget_attrs.update({
+ "default_lon": profile.default_center.y,
+ "default_lat": profile.default_center.x,
+ })
for keys in self.GEO_FIELDS:
if any(key == self.geom_type for key in keys):
map_srid = 4326
widget = widgets.OSMWidget
+ widget_attrs = {
+ "map_srid": map_srid,
+ "cols": True,
+ "geom_type": self.GEOM_TYPES[self.geom_type]
+ }
+ widget_attrs.update(base_widget_attrs)
self.fields[keys[0]].widget = widget(
- attrs={"map_srid": map_srid,
- "cols": True,
- "geom_type": self.GEOM_TYPES[self.geom_type]})
+ attrs=widget_attrs)
self.fields.pop("spatial_reference_system")
geo_keys = keys[:]
self.fields.pop("x")
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index 2ab7e970d..db493fd37 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -2938,6 +2938,9 @@ class GeoCreateView(GeoFormMixin, CreateView):
kwargs["source_content_type"] = content_type.pk
kwargs["source_id"] = obj.pk
kwargs["geom_type"] = self.kwargs.get("geom_type")
+ main_geodata = obj.main_geodata
+ if main_geodata and main_geodata.cached_x and main_geodata.cached_y:
+ kwargs["default_center"] = (main_geodata.cached_x, main_geodata.cached_y)
kwargs["user"] = self.request.user
return kwargs