From af7624d8c13d4840b1698a5174745cf3dfc67a30 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Tue, 11 Feb 2020 14:32:36 +0100 Subject: [PATCH 01/19] new way to manage settings --- CHANGES.md | 6 + doc/configuration.rst | 28 +++- doc/installation.rst | 17 +-- setup.py | 1 + terra_geocrud/map/styles.py | 7 +- terra_geocrud/models.py | 5 +- terra_geocrud/properties/files.py | 3 +- terra_geocrud/serializers.py | 11 +- terra_geocrud/settings.py | 159 +++++++++++++++++----- terra_geocrud/templatetags/map_tags.py | 11 +- terra_geocrud/tests/test_template_tags.py | 36 ++--- terra_geocrud/tests/test_views.py | 6 +- terra_geocrud/views.py | 25 +++- test_terra_geocrud/settings/__init__.py | 1 + 14 files changed, 220 insertions(+), 96 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 200804c7..cd0ee4c7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,11 @@ CHANGELOG 0.3.35.dev0 (XXXX-XX-XX) ---------------------------- +!! Breaking changes !! + +New settings system. +After install, please reset your settings in Django admin / GEOCRUD / Preference section (superuser only) + * Fix way to generate templates @@ -38,6 +43,7 @@ CHANGELOG * New template tag to handle image from data-url stored image * Fix bug in admin + 0.3.32 (2020-02-06) ---------------------------- diff --git a/doc/configuration.rst b/doc/configuration.rst index 9ef7bae4..77460c87 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -9,14 +9,25 @@ In your project : :: INSTALLED_APPS = [ - ... + # apps required by terralego base + 'django.contrib.gis', + 'django.contrib.postgres', + 'rest_framework_gis', + 'rest_framework_jwt', + 'terra_utils', + 'terra_accounts', + # apps required by CRUD + 'siteprefs', # set preferences directly in admin 'geostore', # store geographic data 'template_model', # store template in model 'template_engines', # generate odt and docx templates 'rest_framework', # if you want to try api HTML interface 'django_json_widget', # if you want to use django admin + 'sorl.thumbnail', # to generate and manage cached image thumbnails + 'mapbox_baselayer', # store and configure mapbox base layers 'reversion', # used to store every change on data (run ./manage.py createinitialrevisions first) + # CRUD app 'terra_geocrud', ... @@ -36,8 +47,15 @@ In your project : urlpatterns = [ ... - # some urls in geostore are required by geocrud - path('api/geostore/', include('geostore.urls')), + # admin + path('', admin.site.urls), # some base admin views are available in geocrud. But you need to register them yourself in a custom app + + # terralego based urls + path('api/', include('terra_utils.urls')), + path('api/', include('terra_accounts.urls')), + + # urls required for gecrud + path('api/mapbox_baselayer/', include('mapbox_baselayer.urls')), path('api/crud/', include('terra_geocrud.urls')), ... ] @@ -61,7 +79,7 @@ you can disable and / or customize admin Waiting for settings definition directly in models. -Settings should be overrided with TERRA_GEOCRUD settings in your project settings file: +Settings should be overrided directly in django admin :: @@ -106,4 +124,4 @@ Settings should be overrided with TERRA_GEOCRUD settings in your project settin :: - MBGLRENDERER_URL = 'http://mbglrenderer' \ No newline at end of file + MBGLRENDERER_URL = 'http://mbglrenderer' diff --git a/doc/installation.rst b/doc/installation.rst index c817f146..efce9e2e 100644 --- a/doc/installation.rst +++ b/doc/installation.rst @@ -4,11 +4,8 @@ Installation Requirements ------------ -Must be installed, for the package to work: - -* terracommon.terra -* template_model -* template_engines +* DATABASE : postgres 10+ / postgis 2.4+ / pgrouting 2.5+ +* GeoDjango libs installed https://docs.djangoproject.com/en/3.0/ref/contrib/gis/install/geolibs/ With pip -------- @@ -17,19 +14,19 @@ From Pypi: :: - pip install xxxxxxxxxx-xxxxxxxxxxxx + pip install django-terra-geocrud From Github: :: - pip install -e https://github.com/Terralego/terra.backend.crud.git@master#egg=django-template-engines + pip install -e https://github.com/Terralego/django-terra-geocrud.git@master#egg=django-terra-geocrud With git -------- :: - git clone https://github.com/Terralego/terra.backend.crud.git - cd terra.backend.crud - python setup.py install + git clone https://github.com/Terralego/django-terra-geocrud.git + django-terra-geocrud + pip install -e . diff --git a/setup.py b/setup.py index b94334e8..68a17a70 100644 --- a/setup.py +++ b/setup.py @@ -46,6 +46,7 @@ ], install_requires=[ 'django>=2.2', + 'django-siteprefs', 'django-reversion>=3.0.4', 'django-template-model>=1.0.1', 'django-template-engines>=1.2.24', diff --git a/terra_geocrud/map/styles.py b/terra_geocrud/map/styles.py index 163c5d69..67ff8aa0 100644 --- a/terra_geocrud/map/styles.py +++ b/terra_geocrud/map/styles.py @@ -27,12 +27,11 @@ def map_style_with_default(self): def get_default_style(layer): - style_settings = app_settings.TERRA_GEOCRUD.get('STYLES', {}) response = {} if layer.is_point: - response = style_settings.get('point') + response = app_settings.DEFAULT_STYLE_POINT elif layer.is_linestring: - response = style_settings.get('line') + response = app_settings.DEFAULT_STYLE_LINE elif layer.is_polygon: - response = style_settings.get('polygon') + response = app_settings.DEFAULT_STYLE_POLYGON return deepcopy(response) diff --git a/terra_geocrud/models.py b/terra_geocrud/models.py index 752a14a8..0b098ea0 100644 --- a/terra_geocrud/models.py +++ b/terra_geocrud/models.py @@ -70,7 +70,10 @@ def extent(self): extent = features_extent.get('extent') # get extent in settings if no features - return extent if extent else app_settings.TERRA_GEOCRUD['EXTENT'] + return extent if extent else [app_settings.MAP_EXTENT_SW_LNG, + app_settings.MAP_EXTENT_SW_LAT, + app_settings.MAP_EXTENT_NE_LNG, + app_settings.MAP_EXTENT_NE_LAT] def get_layer(self): return self.layer diff --git a/terra_geocrud/properties/files.py b/terra_geocrud/properties/files.py index 79252113..75ceb7f5 100644 --- a/terra_geocrud/properties/files.py +++ b/terra_geocrud/properties/files.py @@ -17,8 +17,7 @@ def get_info_content(value): def get_storage(): - """ Get media storage for feature data element, using settings """ - StorageClass = get_storage_class(import_path=app_settings.TERRA_GEOCRUD['DATA_FILE_STORAGE_CLASS']) + StorageClass = get_storage_class(import_path=app_settings.DATA_FILE_STORAGE_CLASS) return StorageClass() diff --git a/terra_geocrud/serializers.py b/terra_geocrud/serializers.py index d7d1f634..89d1e596 100644 --- a/terra_geocrud/serializers.py +++ b/terra_geocrud/serializers.py @@ -166,6 +166,7 @@ def get_properties(self, obj): if data_format == 'data-url': # apply special cases for files data_type = 'file' + data = {"url": None} if value: # generate / get thumbnail for image @@ -188,6 +189,7 @@ def get_properties(self, obj): pass except IndexError: pass + elif data_format == "date": data_type = 'date' data = value @@ -268,9 +270,11 @@ def get_action_url(self, obj): class Meta: model = models.FeaturePicture - extra_kwargs = { - } - fields = ('id', 'category', 'legend', 'image', 'thumbnail', 'action_url', 'created_at', 'updated_at') + fields = ( + 'id', 'category', 'legend', 'image', + 'thumbnail', 'action_url', + 'created_at', 'updated_at' + ) class FeatureAttachmentSerializer(BaseUpdatableMixin): @@ -397,6 +401,7 @@ def get_display_properties(self, obj): except IndexError: pass + elif data_format == "date": data_type = 'date' data = value diff --git a/terra_geocrud/settings.py b/terra_geocrud/settings.py index 64ede78c..1722aa1a 100644 --- a/terra_geocrud/settings.py +++ b/terra_geocrud/settings.py @@ -1,40 +1,125 @@ -from copy import deepcopy - from django.conf import settings +from django.contrib.postgres.fields import JSONField +from django.db.models import CharField + +DATA_FILE_STORAGE_CLASS = 'django.core.files.storage.FileSystemStorage' +MBGLRENDERER_URL = 'http://mbglrenderer' +MBGLRENDERER_MAX_ZOOM = 22 +MAPBOX_ACCESS_TOKEN = None + +DEFAULT_MAP_CENTER_LAT = 46.0 +DEFAULT_MAP_CENTER_LNG = 2.0 +DEFAULT_MAP_CENTER_ZOOM = 2 +DEFAULT_MAP_MAX_ZOOM = 18 +DEFAULT_MAP_MIN_ZOOM = 3 + +MAP_EXTENT_SW_LAT = -90.0 +MAP_EXTENT_SW_LNG = -180.0 +MAP_EXTENT_NE_LAT = 90.0 +MAP_EXTENT_NE_LNG = 180.0 + +DEFAULT_STYLE_LINE = { + 'type': 'line', + 'paint': { + 'line-color': '#000', + 'line-width': 3 + } +} -_DEFAULT_TERRA_GEOCRUD = { - # default extent to world - 'EXTENT': [-90.0, -180.0, 90.0, 180.0], - 'DATA_FILE_STORAGE_CLASS': 'django.core.files.storage.FileSystemStorage', - # Do not finish the url with a slash - 'MBGLRENDERER_URL': 'http://mbglrenderer', - # We should automatically get the source of layers from a model - 'map': { - "mapbox_access_token": None, - }, - 'STYLES': { - 'line': { - 'type': 'line', - 'paint': { - 'line-color': '#000', - 'line-width': 3 - } - }, - 'point': { - 'type': 'circle', - 'paint': { - 'circle-color': '#000', - 'circle-radius': 8 - } - }, - 'polygon': { - 'type': 'fill', - 'paint': { - 'fill-color': '#000' - } - }, - }, - 'MAX_ZOOM': 15 +DEFAULT_STYLE_POINT = { + 'type': 'circle', + 'paint': { + 'circle-color': '#000', + 'circle-radius': 8 + } } -_DEFAULT_TERRA_GEOCRUD.update(getattr(settings, 'TERRA_GEOCRUD', {})) -TERRA_GEOCRUD = deepcopy(_DEFAULT_TERRA_GEOCRUD) + +DEFAULT_STYLE_POLYGON = { + 'type': 'fill', + 'paint': { + 'fill-color': '#000' + } +} + +if 'siteprefs' in settings.INSTALLED_APPS: + # Respect those users who doesn't have siteprefs installed. + + from siteprefs.toolbox import preferences + + with preferences() as prefs: + prefs( # Now we register our settings to make them available as siteprefs. + # First we define a group of related settings, and mark them non-static (editable). + prefs.group( + 'Map General settings', + (prefs.one( + MAPBOX_ACCESS_TOKEN, + field=CharField(max_length=1024), + verbose_name='Customize mbglrenderer url', static=False, + help_text='This enable picture map rendering. (ex: http://mbglrender)', ), + prefs.one( + DEFAULT_MAP_CENTER_LAT, + verbose_name='Default map center latitude', static=False, + help_text='In decimal WGS84', ), + prefs.one( + DEFAULT_MAP_CENTER_LNG, + verbose_name='Default map center longitude', static=False, + help_text='In decimal WGS84', ), + prefs.one( + DEFAULT_MAP_CENTER_ZOOM, + verbose_name='Default map zoom', static=False), + prefs.one( + DEFAULT_MAP_MAX_ZOOM, + verbose_name='Map max zoom', static=False), + prefs.one( + DEFAULT_MAP_MIN_ZOOM, + verbose_name='Map min zoom', static=False), + prefs.one( + DEFAULT_STYLE_LINE, + field=JSONField(default=dict), + verbose_name='Default style for lines', static=False), + prefs.one( + DEFAULT_STYLE_POINT, + field=JSONField(default=dict), + verbose_name='Default style for points', static=False), + prefs.one( + DEFAULT_STYLE_POLYGON, + field=JSONField(default=dict), + verbose_name='Default style for polygons', static=False), + prefs.one( + MAP_EXTENT_SW_LAT, + verbose_name='Extent : SW latitude', + help_text="in decimal WGS84", + static=False), + prefs.one( + MAP_EXTENT_SW_LNG, + verbose_name='Extent : SW longitude', + help_text="in decimal WGS84", + static=False), + prefs.one( + MAP_EXTENT_NE_LAT, + verbose_name='Extent : NE latitude', + help_text="in decimal WGS84", + static=False), + prefs.one( + MAP_EXTENT_NE_LNG, + verbose_name='Extent : NE longitude', + help_text="in decimal WGS84", + static=False), + ), + static=False), + prefs.one( + DATA_FILE_STORAGE_CLASS, + field=CharField(max_length=1024), + verbose_name='Features data file storage class', + help_text="WARNING ! Be careful with this settings. Make sure it exists", + static=False), + prefs.one( + MBGLRENDERER_URL, + field=CharField(max_length=2048), + verbose_name='Customize mbglrenderer url', static=False, + help_text="WARNING ! Be careful with this settings. Make sure it exists", ), + prefs.one( + MBGLRENDERER_MAX_ZOOM, + verbose_name='Max zoom for map captures', static=False, + help_text="Zoom is computed by extent, but required a max value for points", ), + ) diff --git a/terra_geocrud/templatetags/map_tags.py b/terra_geocrud/templatetags/map_tags.py index 1fcaab3e..e133c36a 100644 --- a/terra_geocrud/templatetags/map_tags.py +++ b/terra_geocrud/templatetags/map_tags.py @@ -35,7 +35,7 @@ def get_data(self, context): feature = context['object'] style = self.get_style(feature, feature_included, extras_included, base_layer) - token = app_settings.TERRA_GEOCRUD.get('map', {}).get('mapbox_access_token') + token = app_settings.MAPBOX_ACCESS_TOKEN final_style = { 'style': dumps(style), 'width': width, @@ -52,7 +52,7 @@ def get_data(self, context): if not collections: return final_style elif len(collections) == 1 and isinstance(collections[0], Point): - final_style['zoom'] = app_settings.TERRA_GEOCRUD.get('MAX_ZOOM', 22) + final_style['zoom'] = app_settings.MBGLRENDERER_MAX_ZOOM final_style['center'] = list(feature.geom.centroid) else: final_style['center'] = list(collections.centroid) @@ -97,8 +97,7 @@ def get_style_base_layer(self, base_layer): if map_base_layer.base_layer_type == 'mapbox': response = requests.get(map_base_layer.map_box_url.replace("mapbox://styles", "https://api.mapbox.com/styles/v1"), - params={"access_token": app_settings.TERRA_GEOCRUD.get('map', {}).get( - 'mapbox_access_token')}) + params={"access_token": app_settings.MAPBOX_ACCESS_TOKEN}) if response.status_code == 200: return response.json() else: @@ -147,7 +146,7 @@ def map_image_url_loader(parser, token): - feature_included : Primary feature will be shown - extra_features : List of the extra feature you wan to add on your map - width : Width of the picture rendered - - heigth : Height of the picture rendered + - height : Height of the picture rendered - anchor : Type of anchor, paragraph, as-char, char, frame, page """ tag_name, args, kwargs = parse_tag(token, parser) @@ -162,7 +161,7 @@ def map_image_url_loader(parser, token): 'width': kwargs.pop('width', None), 'height': kwargs.pop('height', None), 'base_layer': kwargs.pop('base_layer', None)} - return MapImageLoaderNodeURL(f"{app_settings.TERRA_GEOCRUD['MBGLRENDERER_URL']}/render", **kwargs) + return MapImageLoaderNodeURL(f"{app_settings.MBGLRENDERER_URL}/render", **kwargs) @register.filter diff --git a/terra_geocrud/tests/test_template_tags.py b/terra_geocrud/tests/test_template_tags.py index ffeb6568..1aebc041 100644 --- a/terra_geocrud/tests/test_template_tags.py +++ b/terra_geocrud/tests/test_template_tags.py @@ -6,18 +6,15 @@ from django.template.base import FilterExpression, Parser from django.template.exceptions import TemplateSyntaxError from django.test import TestCase -from django.test.utils import override_settings - -from . import factories -from .settings import FEATURE_PROPERTIES, LAYER_SCHEMA, SMALL_PICTURE - -from geostore.models import Feature, FeatureExtraGeom, LayerExtraGeom from geostore import GeometryTypes - +from geostore.models import Feature, FeatureExtraGeom, LayerExtraGeom from mapbox_baselayer.models import BaseLayerTile, MapBaseLayer + +from terra_geocrud import settings as app_settings from terra_geocrud.models import ExtraLayerStyle from terra_geocrud.templatetags.map_tags import MapImageLoaderNodeURL -from terra_geocrud import settings as app_settings +from . import factories +from .settings import FEATURE_PROPERTIES, LAYER_SCHEMA, SMALL_PICTURE class MapImageUrlLoaderTestCase(TestCase): @@ -55,7 +52,7 @@ def setUp(self): self.node = MapImageLoaderNodeURL('http://mbglrenderer/render') - self.token_mapbox = app_settings.TERRA_GEOCRUD.get('map', {}).get('mapbox_access_token') + self.token_mapbox = app_settings.MAPBOX_ACCESS_TOKEN @mock.patch('secrets.token_hex', side_effect=['primary', 'test']) @@ -220,17 +217,14 @@ def test_get_value_context_line(self, token): self.assertDictEqual(dict_style_post, style) def test_get_value_context_point(self, token): - self.maxDiff = None - settings_terra = app_settings.TERRA_GEOCRUD - settings_terra['MAX_ZOOM'] = 20 - self.node = MapImageLoaderNodeURL('http://mbglrenderer/render', data={'width': None, - 'height': None, - 'feature_included': None, - 'extra_features': None, - 'base_layer': None}) - - with override_settings(TERRA_GEOCRUD=settings_terra): - style = self.node.get_data(Context({'object': self.point})) + self.node = MapImageLoaderNodeURL('http://mbglrenderer/render', + data={'width': None, + 'height': None, + 'feature_included': None, + 'extra_features': None, + 'base_layer': None}) + + style = self.node.get_data(Context({'object': self.point})) dict_style = { "version": 8, "sources": @@ -247,7 +241,7 @@ def test_get_value_context_point(self, token): } dict_style_post = {'style': json.dumps(dict_style), 'center': [-0.246322800072846, 44.5562461167907], - 'zoom': app_settings.TERRA_GEOCRUD['MAX_ZOOM'], + 'zoom': app_settings.MBGLRENDERER_MAX_ZOOM, 'width': 1024, 'height': 512, 'token': self.token_mapbox} diff --git a/terra_geocrud/tests/test_views.py b/terra_geocrud/tests/test_views.py index c3f035c0..7e4c689e 100644 --- a/terra_geocrud/tests/test_views.py +++ b/terra_geocrud/tests/test_views.py @@ -71,7 +71,7 @@ def test_default_point_style(self): response = self.client.get(reverse('crudview-detail', args=(crud_view.pk,))) self.assertEqual(response.status_code, status.HTTP_200_OK) data = response.json() - self.assertDictEqual(data['map_style'], app_settings.TERRA_GEOCRUD['STYLES']['point']) + self.assertDictEqual(data['map_style'], app_settings.DEFAULT_STYLE_POINT) def test_override_point_style(self): custom_style = { @@ -93,7 +93,7 @@ def test_default_line_style(self): response = self.client.get(reverse('crudview-detail', args=(crud_view.pk,))) self.assertEqual(response.status_code, status.HTTP_200_OK) data = response.json() - self.assertDictEqual(data['map_style'], app_settings.TERRA_GEOCRUD['STYLES']['line']) + self.assertDictEqual(data['map_style'], app_settings.DEFAULT_STYLE_LINE) def test_override_line_style(self): custom_style = { @@ -115,7 +115,7 @@ def test_default_polygon_style(self): response = self.client.get(reverse('crudview-detail', args=(crud_view.pk,))) self.assertEqual(response.status_code, status.HTTP_200_OK) data = response.json() - self.assertDictEqual(data['map_style'], app_settings.TERRA_GEOCRUD['STYLES']['polygon']) + self.assertDictEqual(data['map_style'], app_settings.DEFAULT_STYLE_POLYGON) def test_override_polygon_style(self): custom_style = { diff --git a/terra_geocrud/views.py b/terra_geocrud/views.py index 515a0806..90a3b27e 100644 --- a/terra_geocrud/views.py +++ b/terra_geocrud/views.py @@ -1,9 +1,7 @@ import mimetypes -from copy import deepcopy from pathlib import Path import reversion -from django.conf import settings from django.db import transaction from django.shortcuts import get_object_or_404 from django.template.response import TemplateResponse @@ -74,8 +72,27 @@ def get_menu_section(self): return data def get(self, request, *args, **kwargs): - default_config = deepcopy(app_settings.TERRA_GEOCRUD) - default_config.update(getattr(settings, 'TERRA_GEOCRUD', {})) + default_config = { + # default extent to world + 'EXTENT': [app_settings.MAP_EXTENT_SW_LNG, + app_settings.MAP_EXTENT_SW_LAT, + app_settings.MAP_EXTENT_NE_LNG, + app_settings.MAP_EXTENT_NE_LAT], + # We should automatically get the source of layers from a model + 'map': { + "mapbox_access_token": app_settings.MAPBOX_ACCESS_TOKEN, + "center": [app_settings.DEFAULT_MAP_CENTER_LNG, + app_settings.DEFAULT_MAP_CENTER_LAT], + "zoom": app_settings.DEFAULT_MAP_CENTER_ZOOM, + "maxZoom": app_settings.DEFAULT_MAP_MAX_ZOOM, + "minZoom": app_settings.DEFAULT_MAP_MIN_ZOOM, + }, + 'STYLES': { + 'line': app_settings.DEFAULT_STYLE_LINE, + 'point': app_settings.DEFAULT_STYLE_POINT, + 'polygon': app_settings.DEFAULT_STYLE_POLYGON, + } + } data = { "menu": self.get_menu_section(), diff --git a/test_terra_geocrud/settings/__init__.py b/test_terra_geocrud/settings/__init__.py index 81e51e2e..3820abe9 100644 --- a/test_terra_geocrud/settings/__init__.py +++ b/test_terra_geocrud/settings/__init__.py @@ -46,6 +46,7 @@ 'reversion', 'sorl.thumbnail', 'geostore', + 'siteprefs', 'mapbox_baselayer', 'terra_accounts', 'terra_geocrud', From eef3a90bd612a06b8d9236f92db6eb90813f1013 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Tue, 11 Feb 2020 14:53:25 +0100 Subject: [PATCH 02/19] new way to manage settings --- terra_geocrud/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/terra_geocrud/settings.py b/terra_geocrud/settings.py index 1722aa1a..47aa90f8 100644 --- a/terra_geocrud/settings.py +++ b/terra_geocrud/settings.py @@ -54,8 +54,8 @@ (prefs.one( MAPBOX_ACCESS_TOKEN, field=CharField(max_length=1024), - verbose_name='Customize mbglrenderer url', static=False, - help_text='This enable picture map rendering. (ex: http://mbglrender)', ), + verbose_name='MapBox token', static=False, + help_text='To access to MapBox services.', ), prefs.one( DEFAULT_MAP_CENTER_LAT, verbose_name='Default map center latitude', static=False, From 159a6f9e50988a7681fbf06b80a52ef5487432dd Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Tue, 11 Feb 2020 15:00:25 +0100 Subject: [PATCH 03/19] fix default values --- terra_geocrud/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/terra_geocrud/settings.py b/terra_geocrud/settings.py index 47aa90f8..06bb0d54 100644 --- a/terra_geocrud/settings.py +++ b/terra_geocrud/settings.py @@ -7,8 +7,8 @@ MBGLRENDERER_MAX_ZOOM = 22 MAPBOX_ACCESS_TOKEN = None -DEFAULT_MAP_CENTER_LAT = 46.0 -DEFAULT_MAP_CENTER_LNG = 2.0 +DEFAULT_MAP_CENTER_LAT = 0 +DEFAULT_MAP_CENTER_LNG = 0 DEFAULT_MAP_CENTER_ZOOM = 2 DEFAULT_MAP_MAX_ZOOM = 18 DEFAULT_MAP_MIN_ZOOM = 3 From 814a3ce8f5bec6026bd5c317b9e9ae4fe17573ec Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Tue, 11 Feb 2020 15:02:01 +0100 Subject: [PATCH 04/19] fix default values --- terra_geocrud/views.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/terra_geocrud/views.py b/terra_geocrud/views.py index 90a3b27e..9b537567 100644 --- a/terra_geocrud/views.py +++ b/terra_geocrud/views.py @@ -1,3 +1,4 @@ +import json import mimetypes from pathlib import Path @@ -88,9 +89,9 @@ def get(self, request, *args, **kwargs): "minZoom": app_settings.DEFAULT_MAP_MIN_ZOOM, }, 'STYLES': { - 'line': app_settings.DEFAULT_STYLE_LINE, - 'point': app_settings.DEFAULT_STYLE_POINT, - 'polygon': app_settings.DEFAULT_STYLE_POLYGON, + 'line': json.loads(app_settings.DEFAULT_STYLE_LINE), + 'point': json.loads(app_settings.DEFAULT_STYLE_POINT), + 'polygon': json.loads(app_settings.DEFAULT_STYLE_POLYGON), } } From 3cf950c8d8ecd448bf320604b9b98145676cfd36 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Tue, 11 Feb 2020 15:06:07 +0100 Subject: [PATCH 05/19] fix default values --- terra_geocrud/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/terra_geocrud/settings.py b/terra_geocrud/settings.py index 06bb0d54..e2318eae 100644 --- a/terra_geocrud/settings.py +++ b/terra_geocrud/settings.py @@ -7,8 +7,8 @@ MBGLRENDERER_MAX_ZOOM = 22 MAPBOX_ACCESS_TOKEN = None -DEFAULT_MAP_CENTER_LAT = 0 -DEFAULT_MAP_CENTER_LNG = 0 +DEFAULT_MAP_CENTER_LAT = 0.0 +DEFAULT_MAP_CENTER_LNG = 0.0 DEFAULT_MAP_CENTER_ZOOM = 2 DEFAULT_MAP_MAX_ZOOM = 18 DEFAULT_MAP_MIN_ZOOM = 3 From a452eebf33129e281e19962c74cb4acd6b0ca9e6 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Tue, 11 Feb 2020 15:26:20 +0100 Subject: [PATCH 06/19] fix default values --- terra_geocrud/settings.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/terra_geocrud/settings.py b/terra_geocrud/settings.py index e2318eae..0950e9ba 100644 --- a/terra_geocrud/settings.py +++ b/terra_geocrud/settings.py @@ -19,25 +19,25 @@ MAP_EXTENT_NE_LNG = 180.0 DEFAULT_STYLE_LINE = { - 'type': 'line', - 'paint': { - 'line-color': '#000', - 'line-width': 3 + "type": "line", + "paint": { + "line-color": "#000", + "line-width": 3 } } DEFAULT_STYLE_POINT = { - 'type': 'circle', - 'paint': { - 'circle-color': '#000', - 'circle-radius': 8 + "type": "circle", + "paint": { + "circle-color": "#000", + "circle-radius": 8 } } DEFAULT_STYLE_POLYGON = { - 'type': 'fill', - 'paint': { - 'fill-color': '#000' + "type": "fill", + "paint": { + "fill-color": "#000" } } From 818af606df3b03b6435d7b0de31e61cf75df1329 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Tue, 11 Feb 2020 16:12:46 +0100 Subject: [PATCH 07/19] fix default values --- terra_geocrud/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/terra_geocrud/views.py b/terra_geocrud/views.py index 9b537567..ba4fec55 100644 --- a/terra_geocrud/views.py +++ b/terra_geocrud/views.py @@ -89,9 +89,9 @@ def get(self, request, *args, **kwargs): "minZoom": app_settings.DEFAULT_MAP_MIN_ZOOM, }, 'STYLES': { - 'line': json.loads(app_settings.DEFAULT_STYLE_LINE), - 'point': json.loads(app_settings.DEFAULT_STYLE_POINT), - 'polygon': json.loads(app_settings.DEFAULT_STYLE_POLYGON), + 'line': eval(app_settings.DEFAULT_STYLE_LINE), + 'point': eval(app_settings.DEFAULT_STYLE_POINT), + 'polygon': eval(app_settings.DEFAULT_STYLE_POLYGON), } } From c46bb51b2bf5ea800e048ed0aa19721ffb929669 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Tue, 11 Feb 2020 16:33:00 +0100 Subject: [PATCH 08/19] fix json from settings --- terra_geocrud/map/styles.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/terra_geocrud/map/styles.py b/terra_geocrud/map/styles.py index 67ff8aa0..75adbb15 100644 --- a/terra_geocrud/map/styles.py +++ b/terra_geocrud/map/styles.py @@ -21,17 +21,15 @@ class MapStyleModelMixin: @cached_property def map_style_with_default(self): - response = get_default_style(self.get_layer()) - style = self.map_style - return deepcopy(style) if style else response + return deepcopy(self.map_style) if self.map_style else get_default_style(self.get_layer()) def get_default_style(layer): response = {} if layer.is_point: - response = app_settings.DEFAULT_STYLE_POINT + response = eval(app_settings.DEFAULT_STYLE_POINT) elif layer.is_linestring: - response = app_settings.DEFAULT_STYLE_LINE + response = eval(app_settings.DEFAULT_STYLE_LINE) elif layer.is_polygon: - response = app_settings.DEFAULT_STYLE_POLYGON + response = eval(app_settings.DEFAULT_STYLE_POLYGON) return deepcopy(response) From 8c9ada415be375abb21135702f6cb3001f0a9600 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Tue, 11 Feb 2020 17:34:09 +0100 Subject: [PATCH 09/19] pep8 --- terra_geocrud/settings.py | 260 +++++++++++++++++++++++--------------- terra_geocrud/views.py | 1 - 2 files changed, 156 insertions(+), 105 deletions(-) diff --git a/terra_geocrud/settings.py b/terra_geocrud/settings.py index 0950e9ba..b8487586 100644 --- a/terra_geocrud/settings.py +++ b/terra_geocrud/settings.py @@ -2,44 +2,70 @@ from django.contrib.postgres.fields import JSONField from django.db.models import CharField -DATA_FILE_STORAGE_CLASS = 'django.core.files.storage.FileSystemStorage' -MBGLRENDERER_URL = 'http://mbglrenderer' -MBGLRENDERER_MAX_ZOOM = 22 -MAPBOX_ACCESS_TOKEN = None +DATA_FILE_STORAGE_CLASS = getattr(settings, + 'GEOCRUD_DATA_FILE_STORAGE_CLASS', + 'django.core.files.storage.FileSystemStorage') +MBGLRENDERER_URL = getattr(settings, + 'GEOCRUD_MBGLRENDERER_URL', + 'http://mbglrenderer') +MBGLRENDERER_MAX_ZOOM = getattr(settings, + 'GEOCRUD_MBGLRENDERER_MAX_ZOOM', + 22) +MAPBOX_ACCESS_TOKEN = getattr(settings, + 'GEOCRUD_MAPBOX_ACCESS_TOKEN', + None) -DEFAULT_MAP_CENTER_LAT = 0.0 -DEFAULT_MAP_CENTER_LNG = 0.0 -DEFAULT_MAP_CENTER_ZOOM = 2 -DEFAULT_MAP_MAX_ZOOM = 18 -DEFAULT_MAP_MIN_ZOOM = 3 +DEFAULT_MAP_CENTER_LAT = float(getattr(settings, + 'GEOCRUD_DEFAULT_MAP_CENTER_LAT', + 0.0)) +DEFAULT_MAP_CENTER_LNG = float(getattr(settings, + 'GEOCRUD_DEFAULT_MAP_CENTER_LNG', + 0.0)) +DEFAULT_MAP_CENTER_ZOOM = getattr(settings, + 'GEOCRUD_DEFAULT_MAP_CENTER_ZOOM', + 2) +DEFAULT_MAP_MAX_ZOOM = getattr(settings, + 'GEOCRUD_DEFAULT_MAP_MAX_ZOOM', + 18) +DEFAULT_MAP_MIN_ZOOM = getattr(settings, + 'GEOCRUD_DEFAULT_MAP_MIN_ZOOM', + 3) -MAP_EXTENT_SW_LAT = -90.0 -MAP_EXTENT_SW_LNG = -180.0 -MAP_EXTENT_NE_LAT = 90.0 -MAP_EXTENT_NE_LNG = 180.0 +MAP_EXTENT_SW_LAT = getattr(settings, + 'GEOCRUD_MAP_EXTENT_SW_LAT', + -90.0) +MAP_EXTENT_SW_LNG = getattr(settings, + 'GEOCRUD_MAP_EXTENT_SW_LNG', + -180.0) +MAP_EXTENT_NE_LAT = getattr(settings, + 'GEOCRUD_MAP_EXTENT_NE_LAT', + 90.0) +MAP_EXTENT_NE_LNG = getattr(settings, + 'GEOCRUD_MAP_EXTENT_NE_LNG', + 180.0) -DEFAULT_STYLE_LINE = { - "type": "line", - "paint": { - "line-color": "#000", - "line-width": 3 - } -} +DEFAULT_STYLE_LINE = getattr(settings, + 'GEOCRUD_DEFAULT_STYLE_LINE', + {"type": "line", + "paint": { + "line-color": "#000", + "line-width": 3 + }}) -DEFAULT_STYLE_POINT = { - "type": "circle", - "paint": { - "circle-color": "#000", - "circle-radius": 8 - } -} +DEFAULT_STYLE_POINT = getattr(settings, + 'GEOCRUD_DEFAULT_STYLE_POINT', + {"type": "circle", + "paint": { + "circle-color": "#000", + "circle-radius": 8 + }}) -DEFAULT_STYLE_POLYGON = { - "type": "fill", - "paint": { - "fill-color": "#000" - } -} +DEFAULT_STYLE_POLYGON = getattr(settings, + 'GEOCRUD_DEFAULT_STYLE_POLYGON', + {"type": "fill", + "paint": { + "fill-color": "#000" + }}) if 'siteprefs' in settings.INSTALLED_APPS: # Respect those users who doesn't have siteprefs installed. @@ -47,79 +73,105 @@ from siteprefs.toolbox import preferences with preferences() as prefs: - prefs( # Now we register our settings to make them available as siteprefs. - # First we define a group of related settings, and mark them non-static (editable). + prefs( prefs.group( 'Map General settings', - (prefs.one( - MAPBOX_ACCESS_TOKEN, - field=CharField(max_length=1024), - verbose_name='MapBox token', static=False, - help_text='To access to MapBox services.', ), - prefs.one( - DEFAULT_MAP_CENTER_LAT, - verbose_name='Default map center latitude', static=False, - help_text='In decimal WGS84', ), - prefs.one( - DEFAULT_MAP_CENTER_LNG, - verbose_name='Default map center longitude', static=False, - help_text='In decimal WGS84', ), - prefs.one( - DEFAULT_MAP_CENTER_ZOOM, - verbose_name='Default map zoom', static=False), - prefs.one( - DEFAULT_MAP_MAX_ZOOM, - verbose_name='Map max zoom', static=False), - prefs.one( - DEFAULT_MAP_MIN_ZOOM, - verbose_name='Map min zoom', static=False), - prefs.one( - DEFAULT_STYLE_LINE, - field=JSONField(default=dict), - verbose_name='Default style for lines', static=False), - prefs.one( - DEFAULT_STYLE_POINT, - field=JSONField(default=dict), - verbose_name='Default style for points', static=False), - prefs.one( - DEFAULT_STYLE_POLYGON, - field=JSONField(default=dict), - verbose_name='Default style for polygons', static=False), - prefs.one( - MAP_EXTENT_SW_LAT, - verbose_name='Extent : SW latitude', - help_text="in decimal WGS84", - static=False), - prefs.one( - MAP_EXTENT_SW_LNG, - verbose_name='Extent : SW longitude', - help_text="in decimal WGS84", - static=False), - prefs.one( - MAP_EXTENT_NE_LAT, - verbose_name='Extent : NE latitude', - help_text="in decimal WGS84", - static=False), - prefs.one( - MAP_EXTENT_NE_LNG, - verbose_name='Extent : NE longitude', - help_text="in decimal WGS84", - static=False), - ), + ( + prefs.one( + MAPBOX_ACCESS_TOKEN, + field=CharField(max_length=1024), + verbose_name='MapBox token', static=False, + help_text='To access to MapBox services.', + ), + prefs.one( + DEFAULT_MAP_CENTER_LAT, + verbose_name='Default map center latitude', static=False, + help_text='In decimal WGS84', + ), + prefs.one( + DEFAULT_MAP_CENTER_LNG, + verbose_name='Default map center longitude', static=False, + help_text='In decimal WGS84', + ), + prefs.one( + DEFAULT_MAP_CENTER_ZOOM, + verbose_name='Default map zoom', static=False + ), + prefs.one( + DEFAULT_MAP_MAX_ZOOM, + verbose_name='Map max zoom', static=False + ), + prefs.one( + DEFAULT_MAP_MIN_ZOOM, + verbose_name='Map min zoom', static=False + ), + prefs.one( + DEFAULT_STYLE_LINE, + field=JSONField(default=dict), + verbose_name='Default style for lines', static=False + ), + prefs.one( + DEFAULT_STYLE_POINT, + field=JSONField(default=dict), + verbose_name='Default style for points', static=False + ), + prefs.one( + DEFAULT_STYLE_POLYGON, + field=JSONField(default=dict), + verbose_name='Default style for polygons', static=False + ), + prefs.one( + DATA_FILE_STORAGE_CLASS, + field=CharField(max_length=1024), + verbose_name='Features data file storage class', + help_text="Only overridable with settings GEOCRUD_DATA_FILE_STORAGE_CLASS", + static=True + ), + ), static=False), - prefs.one( - DATA_FILE_STORAGE_CLASS, - field=CharField(max_length=1024), - verbose_name='Features data file storage class', - help_text="WARNING ! Be careful with this settings. Make sure it exists", + prefs.group( + 'Default map extent', + ( + prefs.one( + MAP_EXTENT_SW_LAT, + verbose_name='SW latitude', + help_text="in decimal WGS84", + static=False + ), + prefs.one( + MAP_EXTENT_SW_LNG, + verbose_name='SW longitude', + help_text="in decimal WGS84", + static=False + ), + prefs.one( + MAP_EXTENT_NE_LAT, + verbose_name='NE latitude', + help_text="in decimal WGS84", + static=False + ), + prefs.one( + MAP_EXTENT_NE_LNG, + verbose_name='NE longitude', + help_text="in decimal WGS84", + static=False + ), + ), + static=False), + prefs.group( + 'Map Capture service', + ( + prefs.one( + MBGLRENDERER_URL, + field=CharField(max_length=2048), + verbose_name='Customize mbglrenderer url', static=True, + help_text="Only overridable with settings GEOCRUD_MBGLRENDERER_URL", + ), + prefs.one( + MBGLRENDERER_MAX_ZOOM, + verbose_name='Max zoom for map captures', static=False, + help_text="Zoom is computed by feature geometry extent, but a max zoom value is required to fix zoom level for points", + ), + ), static=False), - prefs.one( - MBGLRENDERER_URL, - field=CharField(max_length=2048), - verbose_name='Customize mbglrenderer url', static=False, - help_text="WARNING ! Be careful with this settings. Make sure it exists", ), - prefs.one( - MBGLRENDERER_MAX_ZOOM, - verbose_name='Max zoom for map captures', static=False, - help_text="Zoom is computed by extent, but required a max value for points", ), ) diff --git a/terra_geocrud/views.py b/terra_geocrud/views.py index ba4fec55..0b4ebdf6 100644 --- a/terra_geocrud/views.py +++ b/terra_geocrud/views.py @@ -1,4 +1,3 @@ -import json import mimetypes from pathlib import Path From 03cbf136339475021c6c89d22d68409c12f4b202 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Tue, 11 Feb 2020 17:39:33 +0100 Subject: [PATCH 10/19] organize settings --- terra_geocrud/settings.py | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/terra_geocrud/settings.py b/terra_geocrud/settings.py index b8487586..6e235cd8 100644 --- a/terra_geocrud/settings.py +++ b/terra_geocrud/settings.py @@ -105,21 +105,6 @@ DEFAULT_MAP_MIN_ZOOM, verbose_name='Map min zoom', static=False ), - prefs.one( - DEFAULT_STYLE_LINE, - field=JSONField(default=dict), - verbose_name='Default style for lines', static=False - ), - prefs.one( - DEFAULT_STYLE_POINT, - field=JSONField(default=dict), - verbose_name='Default style for points', static=False - ), - prefs.one( - DEFAULT_STYLE_POLYGON, - field=JSONField(default=dict), - verbose_name='Default style for polygons', static=False - ), prefs.one( DATA_FILE_STORAGE_CLASS, field=CharField(max_length=1024), @@ -158,6 +143,26 @@ ), ), static=False), + prefs.group( + 'Default geometry styles', + ( + prefs.one( + DEFAULT_STYLE_LINE, + field=JSONField(default=dict), + verbose_name='Default style for lines', static=False + ), + prefs.one( + DEFAULT_STYLE_POINT, + field=JSONField(default=dict), + verbose_name='Default style for points', static=False + ), + prefs.one( + DEFAULT_STYLE_POLYGON, + field=JSONField(default=dict), + verbose_name='Default style for polygons', static=False + ), + ), + static=False), prefs.group( 'Map Capture service', ( From de29feb6ca518e3c59097e6cf0c43559c09e634a Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Tue, 11 Feb 2020 17:59:24 +0100 Subject: [PATCH 11/19] improve documentation --- doc/configuration.rst | 88 ++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 39 deletions(-) diff --git a/doc/configuration.rst b/doc/configuration.rst index 77460c87..abeddbcc 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -9,7 +9,15 @@ In your project : :: INSTALLED_APPS = [ - # apps required by terralego base + # basic django apps + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + + # apps required by terralego stack 'django.contrib.gis', 'django.contrib.postgres', 'rest_framework_gis', @@ -18,7 +26,7 @@ In your project : 'terra_accounts', # apps required by CRUD - 'siteprefs', # set preferences directly in admin + 'siteprefs', # set some preferences directly in admin 'geostore', # store geographic data 'template_model', # store template in model 'template_engines', # generate odt and docx templates @@ -72,56 +80,58 @@ Run migrations - ADMIN : -you can disable and / or customize admin +Some configured views are available in terra_geocrud.admin, but are not enabled by default. Enable them in a custom app in your project. - SETTINGS : -Waiting for settings definition directly in models. - -Settings should be overrided directly in django admin +Some settings are available in django admin, Geographic Editor Config -> Preferences, if admin has been enabled in your project. + + +GEOCRUD_MBGLRENDERER_MAX_ZOOM = 22 # define zoom level max for point map capture (other based on extent) +GEOCRUD_MAPBOX_ACCESS_TOKEN = None # define token to handle mapbox service +GEOCRUD_DEFAULT_MAP_CENTER_LAT = 0.0 # Latitude wgs84 for default empty map center +GEOCRUD_DEFAULT_MAP_CENTER_LNG = 0.0 # Longitude wgs84 for default empty map center +GEOCRUD_DEFAULT_MAP_CENTER_ZOOM = 2 # Zoom level for default empty map +GEOCRUD_DEFAULT_MAP_MAX_ZOOM = 18 # Max zoom level for maps +GEOCRUD_DEFAULT_MAP_MIN_ZOOM = 3 # Min zoom level for maps +GEOCRUD_MAP_EXTENT_SW_LAT = -90.0 # SW latitude wgs84 for empty map extent +GEOCRUD_MAP_EXTENT_SW_LNG = -180.0 # SW lonitude wgs84 for empty map extent +GEOCRUD_MAP_EXTENT_NE_LAT = 90.0 # NE latitude wgs84 for empty map extent +GEOCRUD_MAP_EXTENT_NE_LNG = 180.0 # NE longitude wgs84 for empty map extent +GEOCRUD_DEFAULT_STYLE_LINE = {"type": "line", # Default line style used if not defined in crud view + "paint": { + "line-color": "#000", + "line-width": 3 + }} +GEOCRUD_DEFAULT_STYLE_POINT = {"type": "circle", # Default point style used if not defined in crud view + "paint": { + "circle-color": "#000", + "circle-radius": 8 + }} +GEOCRUD_DEFAULT_STYLE_POLYGON = {"type": "fill", # Default polygon style used if not defined in crud view + "paint": { + "fill-color": "#000" + }} + +These settings should be override in your project settings file only : :: - ... - TERRA_GEOCRUD = { - # default value for map extent. API serialize this for layer extent if there is no features in it (as default) - 'EXTENT': [-90.0, -180.0, 90.0, 180.0], - # default storage for file stored in json properties. It is recommended to configure a private web storage in your project (as S3Storage -> see django-storages) - 'DATA_FILE_STORAGE_CLASS': 'django.core.files.storage.FileSystemStorage', - # default mapbox style provided by api if no custom style defined in crud view - 'STYLES': { - 'line': { - 'type': 'line', - 'paint': { - 'line-color': '#000', - 'line-width': 3 - } - }, - 'point': { - 'type': 'circle', - 'paint': { - 'circle-color': '#000', - 'circle-radius': 8 - } - }, - 'polygon': { - 'type': 'fill', - 'paint': { - 'fill-color': '#000' - } - }, - } - } - ... + GEOCRUD_MBGLRENDERER_URL = 'http://mbglrenderer' * If you want to generate map on your template with the geometry of your feature, and/or extra features, you should use mbglrenderer. Check https://github.com/consbio/mbgl-renderer. - Change the url in the settings to use your instance of mbglrenderer : + Change the url in the settings to use external instance of mbglrenderer : + :: + GEOCRUD_DATA_FILE_STORAGE_CLASS = 'django.core.files.storage.FileSystemStorage' + +* This settings manage storage class for feature data files. It will be more secure if you choose a custom private storage backend, like s3 with signature +* Configure this with python doted path to your custom storage backend definition. +* -> See django-storages - MBGLRENDERER_URL = 'http://mbglrenderer' From 60164e469edbb452047d9abb2d704633da44259a Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Tue, 11 Feb 2020 18:11:03 +0100 Subject: [PATCH 12/19] admin enabled by default --- CHANGES.md | 2 +- doc/configuration.rst | 75 ++++++++++++------------- terra_geocrud/admin.py | 1 + terra_geocrud/apps.py | 5 +- test_terra_geocrud/settings/__init__.py | 1 - test_terra_geocrud/test_app/__init__.py | 0 test_terra_geocrud/test_app/admin.py | 13 ----- 7 files changed, 40 insertions(+), 57 deletions(-) delete mode 100644 test_terra_geocrud/test_app/__init__.py delete mode 100644 test_terra_geocrud/test_app/admin.py diff --git a/CHANGES.md b/CHANGES.md index cd0ee4c7..709c649a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,7 +7,7 @@ CHANGELOG !! Breaking changes !! -New settings system. +* New settings system. After install, please reset your settings in Django admin / GEOCRUD / Preference section (superuser only) * Fix way to generate templates diff --git a/doc/configuration.rst b/doc/configuration.rst index abeddbcc..532b6d19 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -6,7 +6,7 @@ In your project : * settings -:: +.. code-block:: python INSTALLED_APPS = [ # basic django apps @@ -51,72 +51,66 @@ In your project : * urls -:: +.. code-block:: python urlpatterns = [ ... # admin - path('', admin.site.urls), # some base admin views are available in geocrud. But you need to register them yourself in a custom app + path('', admin.site.urls), # some base admin views are available in geocrud. # terralego based urls path('api/', include('terra_utils.urls')), path('api/', include('terra_accounts.urls')), - # urls required for gecrud + # urls required for geocrud path('api/mapbox_baselayer/', include('mapbox_baselayer.urls')), path('api/crud/', include('terra_geocrud.urls')), ... ] -You can customize default url and namespace by including terra_geocrud.views directly Run migrations -:: +.. code-block:: bash ./manage.py migrate - -- ADMIN : - -Some configured views are available in terra_geocrud.admin, but are not enabled by default. Enable them in a custom app in your project. - - - SETTINGS : Some settings are available in django admin, Geographic Editor Config -> Preferences, if admin has been enabled in your project. - -GEOCRUD_MBGLRENDERER_MAX_ZOOM = 22 # define zoom level max for point map capture (other based on extent) -GEOCRUD_MAPBOX_ACCESS_TOKEN = None # define token to handle mapbox service -GEOCRUD_DEFAULT_MAP_CENTER_LAT = 0.0 # Latitude wgs84 for default empty map center -GEOCRUD_DEFAULT_MAP_CENTER_LNG = 0.0 # Longitude wgs84 for default empty map center -GEOCRUD_DEFAULT_MAP_CENTER_ZOOM = 2 # Zoom level for default empty map -GEOCRUD_DEFAULT_MAP_MAX_ZOOM = 18 # Max zoom level for maps -GEOCRUD_DEFAULT_MAP_MIN_ZOOM = 3 # Min zoom level for maps -GEOCRUD_MAP_EXTENT_SW_LAT = -90.0 # SW latitude wgs84 for empty map extent -GEOCRUD_MAP_EXTENT_SW_LNG = -180.0 # SW lonitude wgs84 for empty map extent -GEOCRUD_MAP_EXTENT_NE_LAT = 90.0 # NE latitude wgs84 for empty map extent -GEOCRUD_MAP_EXTENT_NE_LNG = 180.0 # NE longitude wgs84 for empty map extent -GEOCRUD_DEFAULT_STYLE_LINE = {"type": "line", # Default line style used if not defined in crud view - "paint": { - "line-color": "#000", - "line-width": 3 - }} -GEOCRUD_DEFAULT_STYLE_POINT = {"type": "circle", # Default point style used if not defined in crud view - "paint": { - "circle-color": "#000", - "circle-radius": 8 - }} -GEOCRUD_DEFAULT_STYLE_POLYGON = {"type": "fill", # Default polygon style used if not defined in crud view - "paint": { - "fill-color": "#000" - }} +.. code-block:: python + + GEOCRUD_MBGLRENDERER_MAX_ZOOM = 22 # define zoom level max for point map capture (other based on extent) + GEOCRUD_MAPBOX_ACCESS_TOKEN = None # define token to handle mapbox service + GEOCRUD_DEFAULT_MAP_CENTER_LAT = 0.0 # Latitude wgs84 for default empty map center + GEOCRUD_DEFAULT_MAP_CENTER_LNG = 0.0 # Longitude wgs84 for default empty map center + GEOCRUD_DEFAULT_MAP_CENTER_ZOOM = 2 # Zoom level for default empty map + GEOCRUD_DEFAULT_MAP_MAX_ZOOM = 18 # Max zoom level for maps + GEOCRUD_DEFAULT_MAP_MIN_ZOOM = 3 # Min zoom level for maps + GEOCRUD_MAP_EXTENT_SW_LAT = -90.0 # SW latitude wgs84 for empty map extent + GEOCRUD_MAP_EXTENT_SW_LNG = -180.0 # SW lonitude wgs84 for empty map extent + GEOCRUD_MAP_EXTENT_NE_LAT = 90.0 # NE latitude wgs84 for empty map extent + GEOCRUD_MAP_EXTENT_NE_LNG = 180.0 # NE longitude wgs84 for empty map extent + GEOCRUD_DEFAULT_STYLE_LINE = {"type": "line", # Default line style used if not defined in crud view + "paint": { + "line-color": "#000", + "line-width": 3 + }} + GEOCRUD_DEFAULT_STYLE_POINT = {"type": "circle", # Default point style used if not defined in crud view + "paint": { + "circle-color": "#000", + "circle-radius": 8 + }} + GEOCRUD_DEFAULT_STYLE_POLYGON = {"type": "fill", # Default polygon style used if not defined in crud view + "paint": { + "fill-color": "#000" + }} These settings should be override in your project settings file only : -:: +.. code-block:: python GEOCRUD_MBGLRENDERER_URL = 'http://mbglrenderer' @@ -128,7 +122,8 @@ These settings should be override in your project settings file only : Change the url in the settings to use external instance of mbglrenderer : -:: +.. code-block:: python + GEOCRUD_DATA_FILE_STORAGE_CLASS = 'django.core.files.storage.FileSystemStorage' * This settings manage storage class for feature data files. It will be more secure if you choose a custom private storage backend, like s3 with signature diff --git a/terra_geocrud/admin.py b/terra_geocrud/admin.py index d05d5493..836416d8 100644 --- a/terra_geocrud/admin.py +++ b/terra_geocrud/admin.py @@ -3,6 +3,7 @@ from django.contrib.postgres import fields from django.utils.translation import gettext_lazy as _ from geostore.models import LayerExtraGeom + from reversion.admin import VersionAdmin from sorl.thumbnail.admin import AdminInlineImageMixin diff --git a/terra_geocrud/apps.py b/terra_geocrud/apps.py index 66933708..a6ee3d28 100644 --- a/terra_geocrud/apps.py +++ b/terra_geocrud/apps.py @@ -7,7 +7,7 @@ class TerraCrudConfig(PermissionRegistrationMixin, AppConfig): name = 'terra_geocrud' - verbose_name = 'Geographic Editor Config' + verbose_name = 'Geographic Editor (CRUD)' permissions = ( ("can_manage_views", _("GEOCRUD: Can create / edit / delete views / groups and associated layers.")), ("can_view_feature", _("GEOCRUD: Can read feature detail.")), @@ -18,11 +18,12 @@ class TerraCrudConfig(PermissionRegistrationMixin, AppConfig): def ready(self): super().ready() - # in terra lego context, we assume to render module url terra_settings = getattr(settings, 'TERRA_APPLIANCE_SETTINGS', {}) modules = terra_settings.get('modules', {}) + # auto enable CRUD in terralego modules settings modules.update({ 'CRUD': { + # in terra lego context, we assume to render module url "settings": reverse_lazy('settings'), } }) diff --git a/test_terra_geocrud/settings/__init__.py b/test_terra_geocrud/settings/__init__.py index 3820abe9..07ee4f7d 100644 --- a/test_terra_geocrud/settings/__init__.py +++ b/test_terra_geocrud/settings/__init__.py @@ -50,7 +50,6 @@ 'mapbox_baselayer', 'terra_accounts', 'terra_geocrud', - 'test_terra_geocrud.test_app', ] MIDDLEWARE = [ diff --git a/test_terra_geocrud/test_app/__init__.py b/test_terra_geocrud/test_app/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/test_terra_geocrud/test_app/admin.py b/test_terra_geocrud/test_app/admin.py deleted file mode 100644 index a7bcd1b4..00000000 --- a/test_terra_geocrud/test_app/admin.py +++ /dev/null @@ -1,13 +0,0 @@ -from django.contrib import admin -from geostore.models import Layer, Feature -from mapbox_baselayer.admin import MapBaseLayerAdmin -from mapbox_baselayer.models import MapBaseLayer - -from terra_geocrud import admin as geocrud_admin, models - -admin.site.register(models.CrudGroupView, geocrud_admin.CrudGroupViewAdmin) -admin.site.register(models.CrudView, geocrud_admin.CrudViewAdmin) -admin.site.register(models.AttachmentCategory, geocrud_admin.AttachmentCategoryAdmin) -admin.site.register(Layer, geocrud_admin.CrudLayerAdmin) -admin.site.register(Feature, geocrud_admin.CrudFeatureAdmin) -admin.site.register(MapBaseLayer, MapBaseLayerAdmin) From c5c3000c84fa974a1a3e3a58ef6117d40f8f3c5e Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Tue, 11 Feb 2020 18:20:07 +0100 Subject: [PATCH 13/19] fix case --- terra_geocrud/map/styles.py | 9 ++++++--- terra_geocrud/views.py | 12 +++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/terra_geocrud/map/styles.py b/terra_geocrud/map/styles.py index 75adbb15..1430b125 100644 --- a/terra_geocrud/map/styles.py +++ b/terra_geocrud/map/styles.py @@ -27,9 +27,12 @@ def map_style_with_default(self): def get_default_style(layer): response = {} if layer.is_point: - response = eval(app_settings.DEFAULT_STYLE_POINT) + response = eval(app_settings.DEFAULT_STYLE_POINT) if isinstance(app_settings.DEFAULT_STYLE_POINT, str) \ + else app_settings.DEFAULT_STYLE_POINT elif layer.is_linestring: - response = eval(app_settings.DEFAULT_STYLE_LINE) + response = eval(app_settings.DEFAULT_STYLE_LINE) if isinstance(app_settings.DEFAULT_STYLE_LINE, str) \ + else app_settings.DEFAULT_STYLE_LINE elif layer.is_polygon: - response = eval(app_settings.DEFAULT_STYLE_POLYGON) + response = eval(app_settings.DEFAULT_STYLE_POLYGON) if isinstance(app_settings.DEFAULT_STYLE_POLYGON, str) \ + else app_settings.DEFAULT_STYLE_POLYGON return deepcopy(response) diff --git a/terra_geocrud/views.py b/terra_geocrud/views.py index 0b4ebdf6..45d139b8 100644 --- a/terra_geocrud/views.py +++ b/terra_geocrud/views.py @@ -88,9 +88,15 @@ def get(self, request, *args, **kwargs): "minZoom": app_settings.DEFAULT_MAP_MIN_ZOOM, }, 'STYLES': { - 'line': eval(app_settings.DEFAULT_STYLE_LINE), - 'point': eval(app_settings.DEFAULT_STYLE_POINT), - 'polygon': eval(app_settings.DEFAULT_STYLE_POLYGON), + 'line': eval(app_settings.DEFAULT_STYLE_LINE) if isinstance(app_settings.DEFAULT_STYLE_LINE, + str) + else app_settings.DEFAULT_STYLE_LINE, + 'point': eval(app_settings.DEFAULT_STYLE_POINT) if isinstance(app_settings.DEFAULT_STYLE_POINT, + str) + else app_settings.DEFAULT_STYLE_POINT, + 'polygon': eval(app_settings.DEFAULT_STYLE_POLYGON) if isinstance(app_settings.DEFAULT_STYLE_POLYGON, + str) + else app_settings.DEFAULT_STYLE_POLYGON, } } From 1c5ed06c32ece951ee4bcd37d906ed6b716ddd42 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Wed, 25 Mar 2020 10:05:42 +0100 Subject: [PATCH 14/19] enable admin test --- test_terra_geocrud/settings/__init__.py | 1 + test_terra_geocrud/test_app/__init__.py | 0 test_terra_geocrud/test_app/admin.py | 13 +++++++++++++ 3 files changed, 14 insertions(+) create mode 100644 test_terra_geocrud/test_app/__init__.py create mode 100644 test_terra_geocrud/test_app/admin.py diff --git a/test_terra_geocrud/settings/__init__.py b/test_terra_geocrud/settings/__init__.py index 07ee4f7d..64754e9f 100644 --- a/test_terra_geocrud/settings/__init__.py +++ b/test_terra_geocrud/settings/__init__.py @@ -50,6 +50,7 @@ 'mapbox_baselayer', 'terra_accounts', 'terra_geocrud', + 'test_terra_geocrud.test_app' ] MIDDLEWARE = [ diff --git a/test_terra_geocrud/test_app/__init__.py b/test_terra_geocrud/test_app/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/test_terra_geocrud/test_app/admin.py b/test_terra_geocrud/test_app/admin.py new file mode 100644 index 00000000..a7bcd1b4 --- /dev/null +++ b/test_terra_geocrud/test_app/admin.py @@ -0,0 +1,13 @@ +from django.contrib import admin +from geostore.models import Layer, Feature +from mapbox_baselayer.admin import MapBaseLayerAdmin +from mapbox_baselayer.models import MapBaseLayer + +from terra_geocrud import admin as geocrud_admin, models + +admin.site.register(models.CrudGroupView, geocrud_admin.CrudGroupViewAdmin) +admin.site.register(models.CrudView, geocrud_admin.CrudViewAdmin) +admin.site.register(models.AttachmentCategory, geocrud_admin.AttachmentCategoryAdmin) +admin.site.register(Layer, geocrud_admin.CrudLayerAdmin) +admin.site.register(Feature, geocrud_admin.CrudFeatureAdmin) +admin.site.register(MapBaseLayer, MapBaseLayerAdmin) From 3782d92853a7cc80754bff3699aab6945131ae15 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Wed, 25 Mar 2020 10:54:44 +0100 Subject: [PATCH 15/19] factorize and securize config access --- terra_geocrud/map/styles.py | 20 ++++++++++++++------ terra_geocrud/views.py | 26 ++++++++++++++++---------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/terra_geocrud/map/styles.py b/terra_geocrud/map/styles.py index 1430b125..bda58b81 100644 --- a/terra_geocrud/map/styles.py +++ b/terra_geocrud/map/styles.py @@ -1,3 +1,4 @@ +from ast import literal_eval from copy import deepcopy from django.utils.functional import cached_property @@ -17,6 +18,16 @@ "source": "DEFAULT_MBGL_RENDERER_STYLE"}] } +DEFAULT_STYLE_LINE = literal_eval(app_settings.DEFAULT_STYLE_LINE) \ + if isinstance(app_settings.DEFAULT_STYLE_LINE, str) \ + else app_settings.DEFAULT_STYLE_LINE +DEFAULT_STYLE_POINT = literal_eval(app_settings.DEFAULT_STYLE_POINT) \ + if isinstance(app_settings.DEFAULT_STYLE_POINT, str) \ + else app_settings.DEFAULT_STYLE_POINT +DEFAULT_STYLE_POLYGON = literal_eval(app_settings.DEFAULT_STYLE_POLYGON) \ + if isinstance(app_settings.DEFAULT_STYLE_POLYGON, str) \ + else app_settings.DEFAULT_STYLE_POLYGON + class MapStyleModelMixin: @cached_property @@ -27,12 +38,9 @@ def map_style_with_default(self): def get_default_style(layer): response = {} if layer.is_point: - response = eval(app_settings.DEFAULT_STYLE_POINT) if isinstance(app_settings.DEFAULT_STYLE_POINT, str) \ - else app_settings.DEFAULT_STYLE_POINT + response = DEFAULT_STYLE_POINT elif layer.is_linestring: - response = eval(app_settings.DEFAULT_STYLE_LINE) if isinstance(app_settings.DEFAULT_STYLE_LINE, str) \ - else app_settings.DEFAULT_STYLE_LINE + response = DEFAULT_STYLE_LINE elif layer.is_polygon: - response = eval(app_settings.DEFAULT_STYLE_POLYGON) if isinstance(app_settings.DEFAULT_STYLE_POLYGON, str) \ - else app_settings.DEFAULT_STYLE_POLYGON + response = DEFAULT_STYLE_POLYGON return deepcopy(response) diff --git a/terra_geocrud/views.py b/terra_geocrud/views.py index 45d139b8..16a33a17 100644 --- a/terra_geocrud/views.py +++ b/terra_geocrud/views.py @@ -1,4 +1,5 @@ import mimetypes +from ast import literal_eval from pathlib import Path import reversion @@ -18,6 +19,7 @@ from rest_framework.views import APIView from . import models, serializers, settings as app_settings +from .map.styles import DEFAULT_STYLE_LINE, DEFAULT_STYLE_POINT, DEFAULT_STYLE_POLYGON def set_reversion_user(_reversion, user): @@ -73,7 +75,7 @@ def get_menu_section(self): def get(self, request, *args, **kwargs): default_config = { - # default extent to world + # to deprecate in frontend, use map['max_extent'] 'EXTENT': [app_settings.MAP_EXTENT_SW_LNG, app_settings.MAP_EXTENT_SW_LAT, app_settings.MAP_EXTENT_NE_LNG, @@ -86,17 +88,21 @@ def get(self, request, *args, **kwargs): "zoom": app_settings.DEFAULT_MAP_CENTER_ZOOM, "maxZoom": app_settings.DEFAULT_MAP_MAX_ZOOM, "minZoom": app_settings.DEFAULT_MAP_MIN_ZOOM, + "max_extent": [app_settings.MAP_EXTENT_SW_LNG, + app_settings.MAP_EXTENT_SW_LAT, + app_settings.MAP_EXTENT_NE_LNG, + app_settings.MAP_EXTENT_NE_LAT], + "default_styles": { + 'line': DEFAULT_STYLE_LINE, + 'point': DEFAULT_STYLE_POINT, + 'polygon': DEFAULT_STYLE_POLYGON, + } }, + # to deprecate in frontend, use map['default_styles'] 'STYLES': { - 'line': eval(app_settings.DEFAULT_STYLE_LINE) if isinstance(app_settings.DEFAULT_STYLE_LINE, - str) - else app_settings.DEFAULT_STYLE_LINE, - 'point': eval(app_settings.DEFAULT_STYLE_POINT) if isinstance(app_settings.DEFAULT_STYLE_POINT, - str) - else app_settings.DEFAULT_STYLE_POINT, - 'polygon': eval(app_settings.DEFAULT_STYLE_POLYGON) if isinstance(app_settings.DEFAULT_STYLE_POLYGON, - str) - else app_settings.DEFAULT_STYLE_POLYGON, + 'line': DEFAULT_STYLE_LINE, + 'point': DEFAULT_STYLE_POINT, + 'polygon': DEFAULT_STYLE_POLYGON, } } From e153b25b2619e351a38018c2c23fb500d30d23f7 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Wed, 25 Mar 2020 10:54:56 +0100 Subject: [PATCH 16/19] update translations --- terra_geocrud/apps.py | 2 +- terra_geocrud/locale/en/LC_MESSAGES/django.po | 17 +++------ terra_geocrud/locale/fr/LC_MESSAGES/django.po | 36 ++++++++----------- 3 files changed, 19 insertions(+), 36 deletions(-) diff --git a/terra_geocrud/apps.py b/terra_geocrud/apps.py index a6ee3d28..ca7efd20 100644 --- a/terra_geocrud/apps.py +++ b/terra_geocrud/apps.py @@ -7,7 +7,7 @@ class TerraCrudConfig(PermissionRegistrationMixin, AppConfig): name = 'terra_geocrud' - verbose_name = 'Geographic Editor (CRUD)' + verbose_name = _('Geographic Editor (CRUD)') permissions = ( ("can_manage_views", _("GEOCRUD: Can create / edit / delete views / groups and associated layers.")), ("can_view_feature", _("GEOCRUD: Can read feature detail.")), diff --git a/terra_geocrud/locale/en/LC_MESSAGES/django.po b/terra_geocrud/locale/en/LC_MESSAGES/django.po index 6e174245..5f2e55ce 100644 --- a/terra_geocrud/locale/en/LC_MESSAGES/django.po +++ b/terra_geocrud/locale/en/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-02-26 10:40+0000\n" +"POT-Creation-Date: 2020-03-25 09:26+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -24,12 +24,6 @@ msgstr "" msgid "Display groups for feature property display and form." msgstr "" -msgid "Custom widget" -msgstr "" - -msgid "Custom widgets for property content display rendering" -msgstr "" - msgid "UI schema & properties" msgstr "" @@ -51,6 +45,9 @@ msgstr "" msgid "Attachments" msgstr "" +msgid "Geographic Editor (CRUD)" +msgstr "" + msgid "" "GEOCRUD: Can create / edit / delete views / groups and associated layers." msgstr "" @@ -115,12 +112,6 @@ msgstr "" msgid "Feature properties display groups" msgstr "" -msgid "Custom feature property rendering" -msgstr "" - -msgid "Custom feature properties rendering" -msgstr "" - msgid "Attachment category" msgstr "" diff --git a/terra_geocrud/locale/fr/LC_MESSAGES/django.po b/terra_geocrud/locale/fr/LC_MESSAGES/django.po index ffcf40ba..7d6827f0 100644 --- a/terra_geocrud/locale/fr/LC_MESSAGES/django.po +++ b/terra_geocrud/locale/fr/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-02-26 10:40+0000\n" +"POT-Creation-Date: 2020-03-25 09:26+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -24,12 +24,6 @@ msgstr "Groupe d'affichage" msgid "Display groups for feature property display and form." msgstr "Group de propriété pour l'affichage / formulaire de features" -msgid "Custom widget" -msgstr "Rendu personnalisé" - -msgid "Custom widgets for property content display rendering" -msgstr "Rendu personnalisé pour l'affichage des propriétés d'une feature" - msgid "UI schema & properties" msgstr "Propriété et UI schema" @@ -51,10 +45,14 @@ msgstr "Pièce-jointe" msgid "Attachments" msgstr "Pièces-jointes" +msgid "Geographic Editor (CRUD)" +msgstr "Éditeur géographique (CRUD)" + msgid "" "GEOCRUD: Can create / edit / delete views / groups and associated layers." msgstr "" -"GEOCRUD: Peut créer / éditier / supprimer les vues / groupes et layers associés." +"GEOCRUD: Peut créer / éditer / supprimer les vues / groupes et layers " +"associés." msgid "GEOCRUD: Can read feature detail." msgstr "GEOCRUD: Peut lire les détails d'une feature" @@ -105,7 +103,7 @@ msgid "Schema property used to define feature title." msgstr "Propriété du schema utilisée pour le titre de la feature" msgid "Keep visible if ungrouped." -msgstr "" +msgstr "Garder visible si non-groupé" msgid "View" msgstr "Vue" @@ -119,12 +117,6 @@ msgstr "Groupe d'affichage de propriétés" msgid "Feature properties display groups" msgstr "Groupes d'affichage de propriétés" -msgid "Custom feature property rendering" -msgstr "Rendu perssonalisé de propriété" - -msgid "Custom feature properties rendering" -msgstr "Rendus personnalisés de propriétés" - msgid "Attachment category" msgstr "Catégorie de pièces-jointes" @@ -132,25 +124,25 @@ msgid "Attachment categories" msgstr "Catégories de pièces-jointes" msgid "Feature attachment" -msgstr "" +msgstr "Pièce jointe d'un objet" msgid "Feature attachments" -msgstr "" +msgstr "Pièces jointes d'un objet" msgid "Feature picture" -msgstr "" +msgstr "Image d'un objet" msgid "Feature pictures" -msgstr "" +msgstr "Images d'un objet" msgid "ExtraLayer style" -msgstr "" +msgstr "Styles de la Géométrie annexe" msgid "ExtraLayer styles" -msgstr "" +msgstr "Styles des Géométries annexes" msgid "VT styles and definitions" -msgstr "" +msgstr "Styles et définition des tuiles vectorielles" msgid "Url endpoint for view's features" msgstr "URL de la liste des features de la vue." From 3fd06a5b69e3b8df283cfb0d74b3ea50ad3581e5 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Wed, 25 Mar 2020 10:55:05 +0100 Subject: [PATCH 17/19] update doc --- doc/configuration.rst | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/doc/configuration.rst b/doc/configuration.rst index 532b6d19..4a3d162a 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -26,7 +26,6 @@ In your project : 'terra_accounts', # apps required by CRUD - 'siteprefs', # set some preferences directly in admin 'geostore', # store geographic data 'template_model', # store template in model 'template_engines', # generate odt and docx templates @@ -36,6 +35,9 @@ In your project : 'mapbox_baselayer', # store and configure mapbox base layers 'reversion', # used to store every change on data (run ./manage.py createinitialrevisions first) + # optional + 'siteprefs', # set some preferences directly in admin + # CRUD app 'terra_geocrud', ... @@ -110,10 +112,6 @@ Some settings are available in django admin, Geographic Editor Config -> Prefere These settings should be override in your project settings file only : -.. code-block:: python - - GEOCRUD_MBGLRENDERER_URL = 'http://mbglrenderer' - * If you want to generate map on your template with the geometry of your feature, and/or extra features, you should use mbglrenderer. @@ -121,6 +119,10 @@ These settings should be override in your project settings file only : Change the url in the settings to use external instance of mbglrenderer : +.. code-block:: python + + GEOCRUD_MBGLRENDERER_URL = 'http://mbglrenderer' + .. code-block:: python From 3753535465e9ec9832d33e9c718411e0f48d1d64 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Wed, 25 Mar 2020 11:08:44 +0100 Subject: [PATCH 18/19] fix --- terra_geocrud/map/styles.py | 2 +- terra_geocrud/views.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/terra_geocrud/map/styles.py b/terra_geocrud/map/styles.py index bda58b81..69858009 100644 --- a/terra_geocrud/map/styles.py +++ b/terra_geocrud/map/styles.py @@ -3,7 +3,7 @@ from django.utils.functional import cached_property -from terra_geocrud import settings as app_settings +from .. import settings as app_settings DEFAULT_MBGL_RENDERER_STYLE = { 'version': 8, diff --git a/terra_geocrud/views.py b/terra_geocrud/views.py index 16a33a17..01007b8b 100644 --- a/terra_geocrud/views.py +++ b/terra_geocrud/views.py @@ -19,7 +19,16 @@ from rest_framework.views import APIView from . import models, serializers, settings as app_settings -from .map.styles import DEFAULT_STYLE_LINE, DEFAULT_STYLE_POINT, DEFAULT_STYLE_POLYGON + +DEFAULT_STYLE_LINE = literal_eval(app_settings.DEFAULT_STYLE_LINE) \ + if isinstance(app_settings.DEFAULT_STYLE_LINE, str) \ + else app_settings.DEFAULT_STYLE_LINE +DEFAULT_STYLE_POINT = literal_eval(app_settings.DEFAULT_STYLE_POINT) \ + if isinstance(app_settings.DEFAULT_STYLE_POINT, str) \ + else app_settings.DEFAULT_STYLE_POINT +DEFAULT_STYLE_POLYGON = literal_eval(app_settings.DEFAULT_STYLE_POLYGON) \ + if isinstance(app_settings.DEFAULT_STYLE_POLYGON, str) \ + else app_settings.DEFAULT_STYLE_POLYGON def set_reversion_user(_reversion, user): From dbcf62f6cc2c6d76e2c5f24dd31ed6c32eb1a7fd Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Wed, 25 Mar 2020 11:18:33 +0100 Subject: [PATCH 19/19] fix --- terra_geocrud/admin.py | 1 - .../commands/create_default_crud_views.py | 2 +- terra_geocrud/map/styles.py | 23 ++++++++++--------- terra_geocrud/migrations/0001_initial.py | 2 +- .../migrations/0002_auto_20190723_1156.py | 2 +- .../migrations/0007_auto_20190725_1256.py | 2 +- .../migrations/0008_crudview_template.py | 2 +- .../migrations/0009_auto_20190830_1018.py | 2 +- .../0013_featurepropertydisplaygroup.py | 2 +- .../migrations/0020_auto_20190927_1430.py | 2 +- .../0024_propertydisplayrendering.py | 2 +- ...tegory_featureattachment_featurepicture.py | 2 +- .../migrations/0028_auto_20191017_1351.py | 3 ++- .../migrations/0029_auto_20191017_1427.py | 3 ++- .../migrations/0033_extralayerstyle.py | 2 +- .../migrations/0034_auto_20191204_1017.py | 2 +- .../migrations/0035_auto_20191204_1146.py | 2 +- terra_geocrud/serializers.py | 1 - terra_geocrud/tests/factories.py | 4 ++-- terra_geocrud/tests/test_commands.py | 2 +- terra_geocrud/tests/test_models.py | 4 ++-- .../tests/test_properties/test_files.py | 3 +-- terra_geocrud/thumbnail_backends.py | 3 ++- terra_geocrud/views.py | 19 +++++++-------- 24 files changed, 47 insertions(+), 45 deletions(-) diff --git a/terra_geocrud/admin.py b/terra_geocrud/admin.py index 836416d8..d05d5493 100644 --- a/terra_geocrud/admin.py +++ b/terra_geocrud/admin.py @@ -3,7 +3,6 @@ from django.contrib.postgres import fields from django.utils.translation import gettext_lazy as _ from geostore.models import LayerExtraGeom - from reversion.admin import VersionAdmin from sorl.thumbnail.admin import AdminInlineImageMixin diff --git a/terra_geocrud/management/commands/create_default_crud_views.py b/terra_geocrud/management/commands/create_default_crud_views.py index 0739824d..a474457d 100644 --- a/terra_geocrud/management/commands/create_default_crud_views.py +++ b/terra_geocrud/management/commands/create_default_crud_views.py @@ -1,6 +1,6 @@ from django.core.management.base import BaseCommand - from geostore.models import Layer + from ...models import CrudView diff --git a/terra_geocrud/map/styles.py b/terra_geocrud/map/styles.py index 69858009..d6f9adde 100644 --- a/terra_geocrud/map/styles.py +++ b/terra_geocrud/map/styles.py @@ -3,7 +3,18 @@ from django.utils.functional import cached_property -from .. import settings as app_settings +from terra_geocrud.settings import DEFAULT_STYLE_LINE, DEFAULT_STYLE_POINT, DEFAULT_STYLE_POLYGON + +DEFAULT_STYLE_LINE = literal_eval(DEFAULT_STYLE_LINE) \ + if isinstance(DEFAULT_STYLE_LINE, str) \ + else DEFAULT_STYLE_LINE +DEFAULT_STYLE_POINT = literal_eval(DEFAULT_STYLE_POINT) \ + if isinstance(DEFAULT_STYLE_POINT, str) \ + else DEFAULT_STYLE_POINT +DEFAULT_STYLE_POLYGON = literal_eval(DEFAULT_STYLE_POLYGON) \ + if isinstance(DEFAULT_STYLE_POLYGON, str) \ + else DEFAULT_STYLE_POLYGON + DEFAULT_MBGL_RENDERER_STYLE = { 'version': 8, @@ -18,16 +29,6 @@ "source": "DEFAULT_MBGL_RENDERER_STYLE"}] } -DEFAULT_STYLE_LINE = literal_eval(app_settings.DEFAULT_STYLE_LINE) \ - if isinstance(app_settings.DEFAULT_STYLE_LINE, str) \ - else app_settings.DEFAULT_STYLE_LINE -DEFAULT_STYLE_POINT = literal_eval(app_settings.DEFAULT_STYLE_POINT) \ - if isinstance(app_settings.DEFAULT_STYLE_POINT, str) \ - else app_settings.DEFAULT_STYLE_POINT -DEFAULT_STYLE_POLYGON = literal_eval(app_settings.DEFAULT_STYLE_POLYGON) \ - if isinstance(app_settings.DEFAULT_STYLE_POLYGON, str) \ - else app_settings.DEFAULT_STYLE_POLYGON - class MapStyleModelMixin: @cached_property diff --git a/terra_geocrud/migrations/0001_initial.py b/terra_geocrud/migrations/0001_initial.py index 92a223c1..145e7529 100644 --- a/terra_geocrud/migrations/0001_initial.py +++ b/terra_geocrud/migrations/0001_initial.py @@ -1,8 +1,8 @@ # Generated by Django 2.2.3 on 2019-07-23 11:35 import django.contrib.postgres.fields.jsonb -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/terra_geocrud/migrations/0002_auto_20190723_1156.py b/terra_geocrud/migrations/0002_auto_20190723_1156.py index 653542f3..cec6a269 100644 --- a/terra_geocrud/migrations/0002_auto_20190723_1156.py +++ b/terra_geocrud/migrations/0002_auto_20190723_1156.py @@ -1,7 +1,7 @@ # Generated by Django 2.2.3 on 2019-07-23 11:56 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/terra_geocrud/migrations/0007_auto_20190725_1256.py b/terra_geocrud/migrations/0007_auto_20190725_1256.py index ce148379..c338eebe 100644 --- a/terra_geocrud/migrations/0007_auto_20190725_1256.py +++ b/terra_geocrud/migrations/0007_auto_20190725_1256.py @@ -1,7 +1,7 @@ # Generated by Django 2.1.10 on 2019-07-25 12:56 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/terra_geocrud/migrations/0008_crudview_template.py b/terra_geocrud/migrations/0008_crudview_template.py index 9ce491df..45927076 100644 --- a/terra_geocrud/migrations/0008_crudview_template.py +++ b/terra_geocrud/migrations/0008_crudview_template.py @@ -1,7 +1,7 @@ # Generated by Django 2.1 on 2019-08-21 15:48 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/terra_geocrud/migrations/0009_auto_20190830_1018.py b/terra_geocrud/migrations/0009_auto_20190830_1018.py index bb651aae..65293d70 100644 --- a/terra_geocrud/migrations/0009_auto_20190830_1018.py +++ b/terra_geocrud/migrations/0009_auto_20190830_1018.py @@ -1,7 +1,7 @@ # Generated by Django 2.1.11 on 2019-08-30 10:18 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/terra_geocrud/migrations/0013_featurepropertydisplaygroup.py b/terra_geocrud/migrations/0013_featurepropertydisplaygroup.py index 8d7bb15c..a6892fc2 100644 --- a/terra_geocrud/migrations/0013_featurepropertydisplaygroup.py +++ b/terra_geocrud/migrations/0013_featurepropertydisplaygroup.py @@ -1,8 +1,8 @@ # Generated by Django 2.2.5 on 2019-09-27 09:55 import django.contrib.postgres.fields -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/terra_geocrud/migrations/0020_auto_20190927_1430.py b/terra_geocrud/migrations/0020_auto_20190927_1430.py index 66d65ca1..98717cf4 100644 --- a/terra_geocrud/migrations/0020_auto_20190927_1430.py +++ b/terra_geocrud/migrations/0020_auto_20190927_1430.py @@ -1,8 +1,8 @@ # Generated by Django 2.2.5 on 2019-09-27 14:30 import django.contrib.postgres.fields.jsonb -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/terra_geocrud/migrations/0024_propertydisplayrendering.py b/terra_geocrud/migrations/0024_propertydisplayrendering.py index 5e900d4e..4eccce08 100644 --- a/terra_geocrud/migrations/0024_propertydisplayrendering.py +++ b/terra_geocrud/migrations/0024_propertydisplayrendering.py @@ -1,8 +1,8 @@ # Generated by Django 2.2.6 on 2019-10-07 11:52 import django.contrib.postgres.fields.jsonb -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/terra_geocrud/migrations/0027_attachmentcategory_featureattachment_featurepicture.py b/terra_geocrud/migrations/0027_attachmentcategory_featureattachment_featurepicture.py index 143a0df9..eb1118fa 100644 --- a/terra_geocrud/migrations/0027_attachmentcategory_featureattachment_featurepicture.py +++ b/terra_geocrud/migrations/0027_attachmentcategory_featureattachment_featurepicture.py @@ -1,7 +1,7 @@ # Generated by Django 2.2.6 on 2019-10-17 09:50 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/terra_geocrud/migrations/0028_auto_20191017_1351.py b/terra_geocrud/migrations/0028_auto_20191017_1351.py index 474b1557..bc34685a 100644 --- a/terra_geocrud/migrations/0028_auto_20191017_1351.py +++ b/terra_geocrud/migrations/0028_auto_20191017_1351.py @@ -1,7 +1,8 @@ # Generated by Django 2.2.6 on 2019-10-17 13:51 -from django.db import migrations, models import sorl.thumbnail.fields +from django.db import migrations, models + import terra_geocrud.models from terra_geocrud.properties.files import get_storage diff --git a/terra_geocrud/migrations/0029_auto_20191017_1427.py b/terra_geocrud/migrations/0029_auto_20191017_1427.py index 564fb074..19a3a2f7 100644 --- a/terra_geocrud/migrations/0029_auto_20191017_1427.py +++ b/terra_geocrud/migrations/0029_auto_20191017_1427.py @@ -1,7 +1,8 @@ # Generated by Django 2.2.6 on 2019-10-17 14:27 -from django.db import migrations import sorl.thumbnail.fields +from django.db import migrations + import terra_geocrud.models from terra_geocrud.properties.files import get_storage diff --git a/terra_geocrud/migrations/0033_extralayerstyle.py b/terra_geocrud/migrations/0033_extralayerstyle.py index 8371e84a..640e375d 100644 --- a/terra_geocrud/migrations/0033_extralayerstyle.py +++ b/terra_geocrud/migrations/0033_extralayerstyle.py @@ -1,8 +1,8 @@ # Generated by Django 2.2.7 on 2019-11-22 17:21 import django.contrib.postgres.fields.jsonb -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/terra_geocrud/migrations/0034_auto_20191204_1017.py b/terra_geocrud/migrations/0034_auto_20191204_1017.py index 4c15a1ee..97eaf90b 100644 --- a/terra_geocrud/migrations/0034_auto_20191204_1017.py +++ b/terra_geocrud/migrations/0034_auto_20191204_1017.py @@ -1,7 +1,7 @@ # Generated by Django 2.2.8 on 2019-12-04 10:17 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/terra_geocrud/migrations/0035_auto_20191204_1146.py b/terra_geocrud/migrations/0035_auto_20191204_1146.py index 04fa3de9..5a38c1ea 100644 --- a/terra_geocrud/migrations/0035_auto_20191204_1146.py +++ b/terra_geocrud/migrations/0035_auto_20191204_1146.py @@ -1,7 +1,7 @@ # Generated by Django 2.2.8 on 2019-12-04 11:46 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/terra_geocrud/serializers.py b/terra_geocrud/serializers.py index 89d1e596..4d09298f 100644 --- a/terra_geocrud/serializers.py +++ b/terra_geocrud/serializers.py @@ -18,7 +18,6 @@ get_storage_path_from_infos, store_feature_files from .thumbnail_backends import ThumbnailDataFileBackend - thumbnail_backend = ThumbnailDataFileBackend() diff --git a/terra_geocrud/tests/factories.py b/terra_geocrud/tests/factories.py index 4bf57afe..8107d869 100644 --- a/terra_geocrud/tests/factories.py +++ b/terra_geocrud/tests/factories.py @@ -1,8 +1,8 @@ import factory -from template_model.models import Template - from geostore import GeometryTypes from geostore.tests.factories import LayerFactory +from template_model.models import Template + from terra_geocrud.models import CrudView, FeaturePicture, AttachmentCategory, FeatureAttachment from terra_geocrud.tests.settings import DOCX_TEMPLATE diff --git a/terra_geocrud/tests/test_commands.py b/terra_geocrud/tests/test_commands.py index 27b6345a..0b41bb85 100644 --- a/terra_geocrud/tests/test_commands.py +++ b/terra_geocrud/tests/test_commands.py @@ -1,8 +1,8 @@ from django.core.management import call_command from django.test.testcases import TestCase - from geostore import GeometryTypes from geostore.models import Layer + from terra_geocrud.models import CrudView diff --git a/terra_geocrud/tests/test_models.py b/terra_geocrud/tests/test_models.py index a0bbc41b..24a3d158 100644 --- a/terra_geocrud/tests/test_models.py +++ b/terra_geocrud/tests/test_models.py @@ -4,12 +4,12 @@ from django.core.exceptions import ValidationError from django.test import override_settings from django.test.testcases import TestCase -from terra_geocrud.tests.factories import CrudViewFactory, FeaturePictureFactory - from geostore.models import Feature + from terra_geocrud.models import AttachmentCategory, AttachmentMixin, \ feature_attachment_directory_path, feature_picture_directory_path from terra_geocrud.tests import factories +from terra_geocrud.tests.factories import CrudViewFactory, FeaturePictureFactory from .. import models diff --git a/terra_geocrud/tests/test_properties/test_files.py b/terra_geocrud/tests/test_properties/test_files.py index 583654f8..49c8f811 100644 --- a/terra_geocrud/tests/test_properties/test_files.py +++ b/terra_geocrud/tests/test_properties/test_files.py @@ -2,11 +2,10 @@ from django.test import override_settings from django.urls import reverse +from geostore.tests.factories import FeatureFactory from rest_framework import status from rest_framework.test import APITestCase -from geostore.tests.factories import FeatureFactory - from terra_geocrud.properties.files import get_info_content, generate_storage_file_path, get_storage from terra_geocrud.tests import factories diff --git a/terra_geocrud/thumbnail_backends.py b/terra_geocrud/thumbnail_backends.py index 1d2f4b9f..90b4f231 100644 --- a/terra_geocrud/thumbnail_backends.py +++ b/terra_geocrud/thumbnail_backends.py @@ -1,9 +1,10 @@ import logging +from sorl.thumbnail import default from sorl.thumbnail.base import ThumbnailBackend from sorl.thumbnail.conf import settings, defaults as default_settings from sorl.thumbnail.images import ImageFile, DummyImageFile -from sorl.thumbnail import default + from terra_geocrud.properties.files import get_storage logger = logging.getLogger(__name__) diff --git a/terra_geocrud/views.py b/terra_geocrud/views.py index 01007b8b..1a2ca4b0 100644 --- a/terra_geocrud/views.py +++ b/terra_geocrud/views.py @@ -18,17 +18,18 @@ from rest_framework.settings import api_settings from rest_framework.views import APIView +from terra_geocrud.settings import DEFAULT_STYLE_LINE, DEFAULT_STYLE_POINT, DEFAULT_STYLE_POLYGON from . import models, serializers, settings as app_settings -DEFAULT_STYLE_LINE = literal_eval(app_settings.DEFAULT_STYLE_LINE) \ - if isinstance(app_settings.DEFAULT_STYLE_LINE, str) \ - else app_settings.DEFAULT_STYLE_LINE -DEFAULT_STYLE_POINT = literal_eval(app_settings.DEFAULT_STYLE_POINT) \ - if isinstance(app_settings.DEFAULT_STYLE_POINT, str) \ - else app_settings.DEFAULT_STYLE_POINT -DEFAULT_STYLE_POLYGON = literal_eval(app_settings.DEFAULT_STYLE_POLYGON) \ - if isinstance(app_settings.DEFAULT_STYLE_POLYGON, str) \ - else app_settings.DEFAULT_STYLE_POLYGON +DEFAULT_STYLE_LINE = literal_eval(DEFAULT_STYLE_LINE) \ + if isinstance(DEFAULT_STYLE_LINE, str) \ + else DEFAULT_STYLE_LINE +DEFAULT_STYLE_POINT = literal_eval(DEFAULT_STYLE_POINT) \ + if isinstance(DEFAULT_STYLE_POINT, str) \ + else DEFAULT_STYLE_POINT +DEFAULT_STYLE_POLYGON = literal_eval(DEFAULT_STYLE_POLYGON) \ + if isinstance(DEFAULT_STYLE_POLYGON, str) \ + else DEFAULT_STYLE_POLYGON def set_reversion_user(_reversion, user):