From 0a9995a56c7acee2d3283e50373420373013db8d Mon Sep 17 00:00:00 2001 From: Sebastian Gutzeit Date: Fri, 22 Sep 2023 15:36:38 +0200 Subject: [PATCH] App Datenmanagement: Bugfix Kartendaten laden --- .../templates/datenmanagement/map.html | 32 ++++++++--------- datenmanagement/urls.py | 19 +++++----- datenmanagement/views/views_form.py | 2 +- datenmanagement/views/views_list_map.py | 36 +++++++------------ 4 files changed, 40 insertions(+), 49 deletions(-) diff --git a/datenmanagement/templates/datenmanagement/map.html b/datenmanagement/templates/datenmanagement/map.html index c199e37c..2f5ad5b7 100644 --- a/datenmanagement/templates/datenmanagement/map.html +++ b/datenmanagement/templates/datenmanagement/map.html @@ -230,8 +230,13 @@
Adressensuche
// define several globally available variables window.geometryType = '{{ geometry_type }}'; + window.promises = []; + window.count = 0; {% if heavy_load_limit %} window.heavyLoadLimit = true + // variables and constants for the number of (already fetched) features of the GeoJSON feature collection + window.border = {{ objects_count }} + window.limit = {{ heavy_load_limit }} {% endif %} {% if highlight_flag %} window.highlightFlag = true @@ -301,14 +306,9 @@
Adressensuche
// falls große Datenmenge zu erwarten ist... if (window.heavyLoadLimit) { - // Konstanten und Variablen für die Anzahl der (bereits geholten) Features der GeoJSON featureCollection definieren - const border = {{ objects_count }}; - const limit = {{ heavy_load_limit }}; - let promises = []; - let count = 0; // Zähler im Bootstrap-Modal setzen, das während des Ladevorgangs der GeoJSON featureCollection für die Karte eingeblendet wird - $('#loading-modal-map-data-count').text(count); - $('#loading-modal-map-data-border').text(border); + $('#loading-modal-map-data-count').text(window.count); + $('#loading-modal-map-data-border').text(window.border); } /** @@ -342,9 +342,9 @@
Adressensuche
}); const data = await response.json(); if (heavyLoad) { - count += data.features.length; - $('#loading-modal-map-data-count').text(count); - if (count === border) { + window.count += data.features.length; + $('#loading-modal-map-data-count').text(window.count); + if (window.count === window.border) { toggleModal($('#loading-modal')); } } else @@ -362,10 +362,10 @@
Adressensuche
// falls große Datenmenge zu erwarten ist... if (window.heavyLoadLimit) { // GeoJSON featureCollection für die Karte in mehreren Ladeschritten holen, die alle parallel ausgeführt werden - for (let offset = 0; offset < border; offset += limit) { - promises.push(fetchGeoJsonFeatureCollection(true, limit, offset)); + for (let offset = 0; offset < window.border; offset += window.limit) { + window.promises.push(fetchGeoJsonFeatureCollection(true, window.limit, offset)); } - Promise.all(promises) + Promise.all(window.promises) .then(data => { // jedes Feature der GeoJSON featureCollection mit Marker versehen, Aktionen und Eigenschaften definieren, Tooltip setzen und zum Cluster hinzufügen L.Proj.geoJson(data, { @@ -415,10 +415,10 @@
Adressensuche
// falls große Datenmenge zu erwarten ist... if (window.heavyLoadLimit) { // GeoJSON featureCollection für die Karte in mehreren Ladeschritten holen, die alle parallel ausgeführt werden - for (let offset = 0; offset < border; offset += limit) { - promises.push(fetchGeoJsonFeatureCollection(true, limit, offset)); + for (let offset = 0; offset < window.border; offset += window.limit) { + window.promises.push(fetchGeoJsonFeatureCollection(true, window.limit, offset)); } - Promise.all(promises) + Promise.all(window.promises) .then(data => { // für jedes Feature der GeoJSON featureCollection Aktionen und Eigenschaften definieren und Feature zur Karte hinzufügen L.Proj.geoJson(data, { diff --git a/datenmanagement/urls.py b/datenmanagement/urls.py index db1917b5..c6feaf8a 100644 --- a/datenmanagement/urls.py +++ b/datenmanagement/urls.py @@ -7,7 +7,8 @@ from .views.functions import delete_object_immediately from .views.views_form import DataAddView, DataChangeView, DataDeleteView from .views.views_general import GeometryView, GISFiletoGeoJSON, IndexView, StartView -from .views.views_list_map import DataListView, DataMapListView, DataMapView, DataView +from .views.views_list_map import MapDataCompositionView, MapListView, TableDataCompositionView, \ + TableListView router = DefaultRouter() @@ -84,7 +85,7 @@ def permission_required(*perms): model_name + '/data', view=permission_required( 'datenmanagement.view_' + model_name_lower - )(DataView.as_view(model=model)), + )(TableDataCompositionView.as_view(model=model)), name=model_name + '_data' ) ) @@ -96,7 +97,7 @@ def permission_required(*perms): model_name + '/data/subset/', view=permission_required( 'datenmanagement.view_' + model_name_lower - )(DataView.as_view(model=model)), + )(TableDataCompositionView.as_view(model=model)), name=model_name + '_data_subset' ) ) @@ -109,7 +110,7 @@ def permission_required(*perms): 'datenmanagement.change_' + model_name_lower, 'datenmanagement.delete_' + model_name_lower, 'datenmanagement.view_' + model_name_lower - )(DataListView.as_view( + )(TableListView.as_view( model=model, template_name='datenmanagement/list.html' )), @@ -126,7 +127,7 @@ def permission_required(*perms): 'datenmanagement.change_' + model_name_lower, 'datenmanagement.delete_' + model_name_lower, 'datenmanagement.view_' + model_name_lower - )(DataListView.as_view( + )(TableListView.as_view( model=model, template_name='datenmanagement/list.html' )), @@ -140,7 +141,7 @@ def permission_required(*perms): model_name + '/mapdata', view=permission_required( 'datenmanagement.view_' + model_name_lower - )(DataMapView.as_view(model=model)), + )(MapDataCompositionView.as_view(model=model)), name=model_name + '_mapdata' ) ) @@ -152,7 +153,7 @@ def permission_required(*perms): model_name + '/mapdata/subset/', view=permission_required( 'datenmanagement.view_' + model_name_lower - )(DataMapView.as_view(model=model)), + )(MapDataCompositionView.as_view(model=model)), name=model_name + '_mapdata_subset' ) ) @@ -165,7 +166,7 @@ def permission_required(*perms): 'datenmanagement.change_' + model_name_lower, 'datenmanagement.delete_' + model_name_lower, 'datenmanagement.view_' + model_name_lower - )(DataMapListView.as_view( + )(MapListView.as_view( model=model, template_name='datenmanagement/map.html' )), @@ -182,7 +183,7 @@ def permission_required(*perms): 'datenmanagement.change_' + model_name_lower, 'datenmanagement.delete_' + model_name_lower, 'datenmanagement.view_' + model_name_lower - )(DataMapListView.as_view( + )(MapListView.as_view( model=model, template_name='datenmanagement/map.html' )), diff --git a/datenmanagement/views/views_form.py b/datenmanagement/views/views_form.py index 3874d4f8..209f0b47 100644 --- a/datenmanagement/views/views_form.py +++ b/datenmanagement/views/views_form.py @@ -5,7 +5,7 @@ from django.db import connections from django.forms.models import modelform_factory from django.urls import reverse -from django.views.generic import CreateView, DeleteView, UpdateView +from django.views.generic.edit import CreateView, DeleteView, UpdateView from json import dumps from re import sub from time import time diff --git a/datenmanagement/views/views_list_map.py b/datenmanagement/views/views_list_map.py index d8a68e91..853bf074 100644 --- a/datenmanagement/views/views_list_map.py +++ b/datenmanagement/views/views_list_map.py @@ -5,7 +5,7 @@ from django.db.models import Q from django.urls import reverse from django.utils.html import escape -from django.views import generic +from django.views.generic.base import TemplateView from django_datatables_view.base_datatable_view import BaseDatatableView from jsonview.views import JsonView from json import dumps, loads @@ -18,7 +18,7 @@ add_model_context_elements -class DataView(BaseDatatableView): +class TableDataCompositionView(BaseDatatableView): """ bereitet Datenbankobjekte für Tabellenansicht auf @@ -39,7 +39,7 @@ def __init__(self, model=None): self.columns_with_foreign_key = self.model.BasemodelMeta.list_fields_with_foreign_key self.column_as_highlight_flag = self.model.BasemodelMeta.list_highlight_flag self.thumbs = self.model.BasemodelMeta.thumbs - super(DataView, self).__init__() + super().__init__() def get_initial_queryset(self): if self.kwargs and self.kwargs['subset_id']: @@ -253,7 +253,7 @@ def ordering(self, qs): return qs -class DataListView(generic.ListView): +class TableListView(TemplateView): """ listet alle Datenbankobjekte eines Datensatzes in einer Tabelle auf @@ -262,17 +262,12 @@ class DataListView(generic.ListView): :param success_url: Success-URL """ + model = None + def __init__(self, model=None, template_name=None, success_url=None): self.model = model self.template_name = template_name - super(DataListView, self).__init__() - - def get_queryset(self): - """ - überschreibt Funktion für Standard-Rückgabewert, - damit diese nichts zurückgibt statt stumpf die Gesamtmenge aller Objekte des Datenmodells - """ - return + super().__init__() def get_context_data(self, **kwargs): """ @@ -291,7 +286,7 @@ def get_context_data(self, **kwargs): return context -class DataMapView(JsonView): +class MapDataCompositionView(JsonView): """ Abfrage aller Datenbankobjekte eines Datensatzes für die Karte * limit: auf n Datenbankobjekte limitieren (entspricht SQL-LIMIT) @@ -307,7 +302,7 @@ def __init__(self, model): self.model_name_lower = self.model.__name__.lower() self.model_pk_field = self.model._meta.pk.name self.editable = self.model.BasemodelMeta.editable - super(DataMapView, self).__init__() + super().__init__() def get_context_data(self, **kwargs): """ @@ -445,7 +440,7 @@ def get_context_data(self, **kwargs): return map_features -class DataMapListView(generic.ListView): +class MapListView(TemplateView): """ zeigt alle Datenbankobjekte eines Datensatzes auf einer Karte an; außerdem werden, falls definiert, entsprechende Filtermöglichkeiten geladen @@ -454,19 +449,14 @@ class DataMapListView(generic.ListView): :param template_name: Name des Templates """ + model = None + def __init__(self, model=None, template_name=None): self.model = model self.model_name = self.model.__name__ self.model_name_lower = self.model.__name__.lower() self.template_name = template_name - super(DataMapListView, self).__init__() - - def get_queryset(self): - """ - überschreibt Funktion für Standard-Rückgabewert, - damit diese nichts zurückgibt statt stumpf die Gesamtmenge aller Objekte des Datenmodells - """ - return + super().__init__() def get_context_data(self, **kwargs): """