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) 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, 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/models.py b/project/terra_layer/models.py index df61a023..342e4345 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", []), + by_variable=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) + 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) @@ -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/tests/test_commands/test_layer_dump.py b/project/terra_layer/tests/test_commands/test_layer_dump.py index bf03e9f9..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,6 +66,7 @@ def test_command_launch_without_custom_style(self, mock_sdout): "main_field": None, "view": None, "style_images": [], + "variables": [], }, ) diff --git a/project/terra_layer/views/layers.py b/project/terra_layer/views/layers.py index 4544e74d..7a55510d 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.by_variable, + "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,