Skip to content

Commit

Permalink
Merge pull request #505 from Terralego/group_byvariables
Browse files Browse the repository at this point in the history
Add variables to group and layer models
  • Loading branch information
submarcos authored Jan 12, 2024
2 parents 6afcbd3 + 6ae1be0 commit dafc491
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 1 deletion.
2 changes: 2 additions & 0 deletions project/geosource/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion project/geosource/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,7 +16,6 @@
CSVSource,
Field,
GeoJSONSource,
GeometryTypes,
PostGISSource,
ShapefileSource,
Source,
Expand Down
Original file line number Diff line number Diff line change
@@ -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),
),
]
6 changes: 6 additions & 0 deletions project/terra_layer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions project/terra_layer/tests/test_commands/test_layer_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def test_command_launch_without_custom_style(self, mock_sdout):
"main_field": None,
"view": None,
"style_images": [],
"variables": [],
},
)

Expand Down
3 changes: 3 additions & 0 deletions project/terra_layer/views/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit dafc491

Please sign in to comment.