diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-06-08 12:10:44 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-12-12 12:21:01 +0100 |
commit | f4bbccb5214ff0dd2cbd7bc76973f64c06fc9509 (patch) | |
tree | fe6e7dbda13a8aef85247aba058b3231af890f96 /ishtar_common | |
parent | fcdab311103db69b15589e07354a8e91aec64c67 (diff) | |
download | Ishtar-f4bbccb5214ff0dd2cbd7bc76973f64c06fc9509.tar.bz2 Ishtar-f4bbccb5214ff0dd2cbd7bc76973f64c06fc9509.zip |
Geodata - geoforms: manage large number of related items - fix zoom - better + button
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/forms_common.py | 13 | ||||
-rw-r--r-- | ishtar_common/models_common.py | 2 | ||||
-rw-r--r-- | ishtar_common/templates/gis/openlayers-osm.html | 2 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/blocks/sheet_geographic.html | 4 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/forms/geo_form.html | 10 | ||||
-rw-r--r-- | ishtar_common/views.py | 20 |
6 files changed, 42 insertions, 9 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index b6a36ff03..856381d05 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -2649,6 +2649,9 @@ class GISForm(forms.ModelForm, CustomForm, ManageOldType): main_items_fields = {} if "main_items_fields" in kwargs: main_items_fields = kwargs.pop("main_items_fields") + self.too_many = {} + if "too_many" in kwargs: + self.too_many = kwargs.pop("too_many") self.user = None self.geom_type = kwargs.pop("geom_type") \ if kwargs.get("geom_type", None) else None @@ -2743,7 +2746,7 @@ class GISForm(forms.ModelForm, CustomForm, ManageOldType): # geo keys for an instanced item geo_keys = [] for keys in self.GEO_FIELDS: - if any(getattr(instance, key) for key in keys): + if any(key for key in keys if getattr(instance, key) is not None): if keys[0] != "x": geom = getattr(instance, keys[0]) map_srid = geom.srid or 4326 @@ -2800,13 +2803,19 @@ class GISForm(forms.ModelForm, CustomForm, ManageOldType): ) def save(self, commit=True): + if not getattr(self.instance, "source_content_type", None): + self.instance.source_content_type_id = self.source_content_type + self.instance.source_id = self.source_id item = super().save(commit=commit) for related_key in models.GeoVectorData.RELATED_MODELS: related = getattr(item, related_key) initial = dict([(rel.pk, rel) for rel in related.all()]) new = [int(pk) for pk in sorted(self.cleaned_data.get(related_key, []))] + full_new = new[:] + if related_key in self.too_many: + full_new += self.too_many[related_key] for pk, value in initial.items(): - if pk in new: + if pk in full_new: continue related.remove(value) for new_pk in new: diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index 3fcf4aea9..b13517f25 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -2397,7 +2397,7 @@ class GeoVectorData(Imported, OwnPerms): features = geojson_dct.pop("features") for idx in range(len(features)): feature = features[idx] - lbl = feature["properties"].pop("name") + lbl = self.name or "" feature["properties"]["name"] = lbl feature["properties"]["id"] = self.pk if precision is not None: diff --git a/ishtar_common/templates/gis/openlayers-osm.html b/ishtar_common/templates/gis/openlayers-osm.html index 404ab5708..a6797a580 100644 --- a/ishtar_common/templates/gis/openlayers-osm.html +++ b/ishtar_common/templates/gis/openlayers-osm.html @@ -19,5 +19,7 @@ $(document).ready(function() { let layer_extent = features[0].getGeometry().getExtent().slice(0); features.forEach(function(feature){ ol.extent.extend(layer_extent, feature.getGeometry().getExtent())}); {{ module }}.map.getView().fit(layer_extent, {{ module }}.map.getSize()); + let current_zoom = {{ module }}.map.getView().getZoom(); + if ({{ module }}.map.getView().getZoom() > 18) {{ module }}.map.getView().setZoom(18); }); {% endblock %} diff --git a/ishtar_common/templates/ishtar/blocks/sheet_geographic.html b/ishtar_common/templates/ishtar/blocks/sheet_geographic.html index 709186c1e..d1ac63815 100644 --- a/ishtar_common/templates/ishtar/blocks/sheet_geographic.html +++ b/ishtar_common/templates/ishtar/blocks/sheet_geographic.html @@ -28,5 +28,7 @@ {% endfor %} </table> {% if permission_change_geo %} -<a href="{% url 'create-pre-geo' item.app_label item.model_name item.pk %}"><i class="fa fa-pencil"></i></a> +<div class="text-center"> + <a class="btn btn-success" href="{% url 'create-pre-geo' item.app_label item.model_name item.pk %}"><i class="fa fa-plus"></i> {% trans "geo item" %}</a> +</div> {% endif %} diff --git a/ishtar_common/templates/ishtar/forms/geo_form.html b/ishtar_common/templates/ishtar/forms/geo_form.html new file mode 100644 index 000000000..d09ae22d8 --- /dev/null +++ b/ishtar_common/templates/ishtar/forms/geo_form.html @@ -0,0 +1,10 @@ +{% extends "ishtar/forms/base_related_items.html" %} +{% load i18n %} +{% block form_head %} +{{ block.super }} +{% if form.too_many %} +<div class="alert alert-warning"> + {% trans "Many items are attached to this geographic item. Only the ten first of each type are displayed in this form." %} +</div> +{% endif %} +{% endblock %} diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 9d5256df5..d019da8ba 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -2733,7 +2733,7 @@ class GeoPreCreateView(IshtarMixin, LoginRequiredMixin, FormView): class GeoFormMixin(IshtarMixin, LoginRequiredMixin): form_class = forms.GISForm - template_name = "ishtar/forms/base_related_items.html" + template_name = "ishtar/forms/geo_form.html" model = models.GeoVectorData def _get_source(self, request): @@ -2776,22 +2776,32 @@ class GeoEditView(GeoFormMixin, UpdateView): ): value = getattr(geo, k) if hasattr(value, "all"): - value = ",".join([str(v.pk) for v in value.all()]) + value = ",".join([str(v.pk) for v in value.all().order_by("pk")]) if hasattr(value, "pk"): value = value.pk initial[k] = value kwargs["main_items_fields"] = {} + kwargs["too_many"] = {} + LIMIT = 10 for k in models.GeoVectorData.RELATED_MODELS: kwargs["main_items_fields"][k] = [] - for related_item in getattr(geo, k).all(): - key = "{}_{}_main_item".format(k, related_item.pk) + values = [] + for idx, related_item in enumerate(getattr(geo, k).all()): + if idx >= LIMIT: + if k not in kwargs["too_many"]: + kwargs["too_many"][k] = [] + kwargs["too_many"][k].append(related_item.pk) + continue + pk = str(related_item.pk) + values.append(pk) + key = "{}_{}_main_item".format(k, pk) kwargs["main_items_fields"][k].append( (key, "{} - {}".format(_("Main geo item for"), related_item)) ) if related_item.main_geodata == geo: initial[key] = True - + initial[k] = ",".join(values) kwargs["initial"] = initial kwargs["user"] = self.request.user return kwargs |