From ff5fcf91ab7437883afc0a2f3a4a702981ec7426 Mon Sep 17 00:00:00 2001 From: Maxime Bouveron Date: Thu, 21 Dec 2023 18:25:55 +0100 Subject: [PATCH 1/7] Add variables to group and layer models --- .../migrations/0013_layergroup_byvariable.py | 17 +++++++++++++++++ .../migrations/0014_layergroup_variables.py | 17 +++++++++++++++++ .../migrations/0015_layer_variables.py | 17 +++++++++++++++++ project/terra_layer/models.py | 6 ++++++ project/terra_layer/views/layers.py | 3 +++ 5 files changed, 60 insertions(+) create mode 100644 project/terra_layer/migrations/0013_layergroup_byvariable.py create mode 100644 project/terra_layer/migrations/0014_layergroup_variables.py create mode 100644 project/terra_layer/migrations/0015_layer_variables.py diff --git a/project/terra_layer/migrations/0013_layergroup_byvariable.py b/project/terra_layer/migrations/0013_layergroup_byvariable.py new file mode 100644 index 00000000..9deb9616 --- /dev/null +++ b/project/terra_layer/migrations/0013_layergroup_byvariable.py @@ -0,0 +1,17 @@ +# Generated by Django 4.1.13 on 2023-12-18 17:49 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("terra_layer", "0012_layer_advanced_style"), + ] + + operations = [ + migrations.AddField( + model_name="layergroup", + name="byVariable", + field=models.BooleanField(default=False), + ), + ] diff --git a/project/terra_layer/migrations/0014_layergroup_variables.py b/project/terra_layer/migrations/0014_layergroup_variables.py new file mode 100644 index 00000000..cbe82910 --- /dev/null +++ b/project/terra_layer/migrations/0014_layergroup_variables.py @@ -0,0 +1,17 @@ +# Generated by Django 4.1.13 on 2023-12-18 17:51 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("terra_layer", "0013_layergroup_byvariable"), + ] + + operations = [ + migrations.AddField( + model_name="layergroup", + name="variables", + field=models.JSONField(default=list), + ), + ] diff --git a/project/terra_layer/migrations/0015_layer_variables.py b/project/terra_layer/migrations/0015_layer_variables.py new file mode 100644 index 00000000..da02a673 --- /dev/null +++ b/project/terra_layer/migrations/0015_layer_variables.py @@ -0,0 +1,17 @@ +# Generated by Django 4.1.13 on 2023-12-18 17:57 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("terra_layer", "0014_layergroup_variables"), + ] + + operations = [ + migrations.AddField( + model_name="layer", + name="variables", + field=models.JSONField(blank=True, default=list), + ), + ] diff --git a/project/terra_layer/models.py b/project/terra_layer/models.py index df61a023..60095b68 100644 --- a/project/terra_layer/models.py +++ b/project/terra_layer/models.py @@ -90,6 +90,8 @@ def tree2models(self, current_node=None, parent=None, order=0): view=self, label=current_node["label"], exclusive=current_node.get("exclusive", False), + variables=current_node.get("variables", []), + byVariable=current_node.get("byVariable", False), selectors=current_node.get("selectors"), settings=current_node.get("settings", {}), order=order, @@ -102,6 +104,7 @@ def tree2models(self, current_node=None, parent=None, order=0): # Handle layers layer = Layer.objects.get(pk=current_node["geolayer"]) layer.group = parent + layer.variables = current_node.get("variables", []) layer.order = order layer.save(wizard_update=False) @@ -164,6 +167,8 @@ class LayerGroup(models.Model): ) order = models.IntegerField(default=0) exclusive = models.BooleanField(default=False) + byVariable = models.BooleanField(default=False) + variables = models.JSONField(default=list) selectors = models.JSONField(null=True, default=None) settings = models.JSONField(default=dict) created_at = models.DateTimeField(auto_now_add=True) @@ -220,6 +225,7 @@ class Layer(CloneMixin, models.Model): ) interactions = models.JSONField(default=list, blank=True) advanced_style = models.JSONField(default=dict, blank=True) + variables = models.JSONField(default=list, blank=True) fields = models.ManyToManyField(Field, through="FilterField") created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) diff --git a/project/terra_layer/views/layers.py b/project/terra_layer/views/layers.py index 4544e74d..ae4a91cd 100644 --- a/project/terra_layer/views/layers.py +++ b/project/terra_layer/views/layers.py @@ -466,6 +466,8 @@ def get_group_dict(self, group): group_content = { "group": group.label, "exclusive": group.exclusive, + "byVariable": group.byVariable, + "variables": group.variables, "selectors": group.selectors, "order": group.order, "layers": [], @@ -524,6 +526,7 @@ def get_layer_dict(self, layer): "source_filter": layer.source_filter, "layers": self.get_layers_list_for_layer(layer), "legends": layer.legends, + "variables": layer.variables, "mainField": main_field, "filters": { "layer": layer.source.slug, From ac5c9e412e2f9033592073923972d955077342b3 Mon Sep 17 00:00:00 2001 From: Maxime Bouveron Date: Wed, 3 Jan 2024 17:36:29 +0100 Subject: [PATCH 2/7] update model parameters to snake_case --- ...ariable_layergroup_by_variable_and_more.py | 22 +++++++++++++++++++ project/terra_layer/models.py | 6 ++--- project/terra_layer/views/layers.py | 2 +- 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 project/terra_layer/migrations/0016_rename_byvariable_layergroup_by_variable_and_more.py diff --git a/project/terra_layer/migrations/0016_rename_byvariable_layergroup_by_variable_and_more.py b/project/terra_layer/migrations/0016_rename_byvariable_layergroup_by_variable_and_more.py new file mode 100644 index 00000000..3d6c37a6 --- /dev/null +++ b/project/terra_layer/migrations/0016_rename_byvariable_layergroup_by_variable_and_more.py @@ -0,0 +1,22 @@ +# Generated by Django 4.1.13 on 2024-01-03 16:31 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("terra_layer", "0015_layer_variables"), + ] + + operations = [ + migrations.RenameField( + model_name="layergroup", + old_name="byVariable", + new_name="by_variable", + ), + migrations.AlterField( + model_name="layergroup", + name="variables", + field=models.JSONField(blank=True, default=list), + ), + ] diff --git a/project/terra_layer/models.py b/project/terra_layer/models.py index 60095b68..342e4345 100644 --- a/project/terra_layer/models.py +++ b/project/terra_layer/models.py @@ -91,7 +91,7 @@ def tree2models(self, current_node=None, parent=None, order=0): label=current_node["label"], exclusive=current_node.get("exclusive", False), variables=current_node.get("variables", []), - byVariable=current_node.get("byVariable", False), + by_variable=current_node.get("byVariable", False), selectors=current_node.get("selectors"), settings=current_node.get("settings", {}), order=order, @@ -167,8 +167,8 @@ class LayerGroup(models.Model): ) order = models.IntegerField(default=0) exclusive = models.BooleanField(default=False) - byVariable = models.BooleanField(default=False) - variables = models.JSONField(default=list) + by_variable = models.BooleanField(default=False) + variables = models.JSONField(default=list, blank=True) selectors = models.JSONField(null=True, default=None) settings = models.JSONField(default=dict) created_at = models.DateTimeField(auto_now_add=True) diff --git a/project/terra_layer/views/layers.py b/project/terra_layer/views/layers.py index ae4a91cd..7a55510d 100644 --- a/project/terra_layer/views/layers.py +++ b/project/terra_layer/views/layers.py @@ -466,7 +466,7 @@ def get_group_dict(self, group): group_content = { "group": group.label, "exclusive": group.exclusive, - "byVariable": group.byVariable, + "byVariable": group.by_variable, "variables": group.variables, "selectors": group.selectors, "order": group.order, From ab20db4fee91d1c424e34ec478570805532d9edd Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Fri, 12 Jan 2024 15:51:48 +0100 Subject: [PATCH 3/7] fix migrations --- ...riables_layergroup_by_variable_and_more.py | 27 +++++++++++++++++++ .../migrations/0013_layergroup_byvariable.py | 17 ------------ .../migrations/0014_layergroup_variables.py | 17 ------------ .../migrations/0015_layer_variables.py | 17 ------------ ...ariable_layergroup_by_variable_and_more.py | 22 --------------- 5 files changed, 27 insertions(+), 73 deletions(-) create mode 100644 project/terra_layer/migrations/0013_layer_variables_layergroup_by_variable_and_more.py delete mode 100644 project/terra_layer/migrations/0013_layergroup_byvariable.py delete mode 100644 project/terra_layer/migrations/0014_layergroup_variables.py delete mode 100644 project/terra_layer/migrations/0015_layer_variables.py delete mode 100644 project/terra_layer/migrations/0016_rename_byvariable_layergroup_by_variable_and_more.py diff --git a/project/terra_layer/migrations/0013_layer_variables_layergroup_by_variable_and_more.py b/project/terra_layer/migrations/0013_layer_variables_layergroup_by_variable_and_more.py new file mode 100644 index 00000000..bdd41635 --- /dev/null +++ b/project/terra_layer/migrations/0013_layer_variables_layergroup_by_variable_and_more.py @@ -0,0 +1,27 @@ +# Generated by Django 4.1.13 on 2024-01-12 14:51 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("terra_layer", "0012_layer_advanced_style"), + ] + + operations = [ + migrations.AddField( + model_name="layer", + name="variables", + field=models.JSONField(blank=True, default=list), + ), + migrations.AddField( + model_name="layergroup", + name="by_variable", + field=models.BooleanField(default=False), + ), + migrations.AddField( + model_name="layergroup", + name="variables", + field=models.JSONField(blank=True, default=list), + ), + ] diff --git a/project/terra_layer/migrations/0013_layergroup_byvariable.py b/project/terra_layer/migrations/0013_layergroup_byvariable.py deleted file mode 100644 index 9deb9616..00000000 --- a/project/terra_layer/migrations/0013_layergroup_byvariable.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 4.1.13 on 2023-12-18 17:49 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("terra_layer", "0012_layer_advanced_style"), - ] - - operations = [ - migrations.AddField( - model_name="layergroup", - name="byVariable", - field=models.BooleanField(default=False), - ), - ] diff --git a/project/terra_layer/migrations/0014_layergroup_variables.py b/project/terra_layer/migrations/0014_layergroup_variables.py deleted file mode 100644 index cbe82910..00000000 --- a/project/terra_layer/migrations/0014_layergroup_variables.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 4.1.13 on 2023-12-18 17:51 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("terra_layer", "0013_layergroup_byvariable"), - ] - - operations = [ - migrations.AddField( - model_name="layergroup", - name="variables", - field=models.JSONField(default=list), - ), - ] diff --git a/project/terra_layer/migrations/0015_layer_variables.py b/project/terra_layer/migrations/0015_layer_variables.py deleted file mode 100644 index da02a673..00000000 --- a/project/terra_layer/migrations/0015_layer_variables.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 4.1.13 on 2023-12-18 17:57 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("terra_layer", "0014_layergroup_variables"), - ] - - operations = [ - migrations.AddField( - model_name="layer", - name="variables", - field=models.JSONField(blank=True, default=list), - ), - ] diff --git a/project/terra_layer/migrations/0016_rename_byvariable_layergroup_by_variable_and_more.py b/project/terra_layer/migrations/0016_rename_byvariable_layergroup_by_variable_and_more.py deleted file mode 100644 index 3d6c37a6..00000000 --- a/project/terra_layer/migrations/0016_rename_byvariable_layergroup_by_variable_and_more.py +++ /dev/null @@ -1,22 +0,0 @@ -# Generated by Django 4.1.13 on 2024-01-03 16:31 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("terra_layer", "0015_layer_variables"), - ] - - operations = [ - migrations.RenameField( - model_name="layergroup", - old_name="byVariable", - new_name="by_variable", - ), - migrations.AlterField( - model_name="layergroup", - name="variables", - field=models.JSONField(blank=True, default=list), - ), - ] From fac932b316281db0f521db861a8443851919d56d Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Fri, 12 Jan 2024 16:11:42 +0100 Subject: [PATCH 4/7] fix test warning --- project/geosource/models.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/project/geosource/models.py b/project/geosource/models.py index 4ce40753..351fcc4e 100644 --- a/project/geosource/models.py +++ b/project/geosource/models.py @@ -256,6 +256,8 @@ def update_fields(self): records, _ = self._get_records(50) fields = {} + if records is None: + return {"count": 0} for record in records: record.pop(self.SOURCE_GEOM_ATTRIBUTE) From 8257e0cba337b83f49cb1575b91e114f9c2598df Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Fri, 12 Jan 2024 16:11:48 +0100 Subject: [PATCH 5/7] fix import --- project/geosource/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/geosource/serializers.py b/project/geosource/serializers.py index 4ff52928..c75f8f04 100644 --- a/project/geosource/serializers.py +++ b/project/geosource/serializers.py @@ -6,6 +6,7 @@ from django.contrib.gis.geos import GEOSGeometry from django.db import transaction from django.utils.translation import gettext as _ +from geostore import GeometryTypes from psycopg2 import sql from rest_framework import serializers from rest_framework.exceptions import ValidationError @@ -15,7 +16,6 @@ CSVSource, Field, GeoJSONSource, - GeometryTypes, PostGISSource, ShapefileSource, Source, From b4965e180018422419ab2f58333d31fccadfcbff Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Fri, 12 Jan 2024 16:17:40 +0100 Subject: [PATCH 6/7] fix import --- project/terra_layer/tests/test_commands/test_layer_dump.py | 1 + 1 file changed, 1 insertion(+) diff --git a/project/terra_layer/tests/test_commands/test_layer_dump.py b/project/terra_layer/tests/test_commands/test_layer_dump.py index bf03e9f9..75b1fe41 100644 --- a/project/terra_layer/tests/test_commands/test_layer_dump.py +++ b/project/terra_layer/tests/test_commands/test_layer_dump.py @@ -66,6 +66,7 @@ def test_command_launch_without_custom_style(self, mock_sdout): "main_field": None, "view": None, "style_images": [], + "variables": [] }, ) From 6ae1be042a29663ddcccd8e282a666ffc933c9d0 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Fri, 12 Jan 2024 16:20:59 +0100 Subject: [PATCH 7/7] fix import --- project/terra_layer/tests/test_commands/test_layer_dump.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/terra_layer/tests/test_commands/test_layer_dump.py b/project/terra_layer/tests/test_commands/test_layer_dump.py index 75b1fe41..403c7f72 100644 --- a/project/terra_layer/tests/test_commands/test_layer_dump.py +++ b/project/terra_layer/tests/test_commands/test_layer_dump.py @@ -66,7 +66,7 @@ def test_command_launch_without_custom_style(self, mock_sdout): "main_field": None, "view": None, "style_images": [], - "variables": [] + "variables": [], }, )