From 57039f95d7ae27850fc1630e61152b26109ad29c Mon Sep 17 00:00:00 2001 From: Irwan Fathurrahman Date: Mon, 14 Aug 2023 17:26:55 +0700 Subject: [PATCH] Fix error when save dashboard --- .../data/models/dashboard/dashboard.py | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/django_project/geosight/data/models/dashboard/dashboard.py b/django_project/geosight/data/models/dashboard/dashboard.py index f5a7254b7..44b35c3e4 100644 --- a/django_project/geosight/data/models/dashboard/dashboard.py +++ b/django_project/geosight/data/models/dashboard/dashboard.py @@ -308,21 +308,23 @@ def save_relations(self, data): rules_ids = [] rules = model.dashboardindicatorlayerrule_set.all() - for idx, rule in enumerate(layer_data.get('style', [])): - if 'indicator' in rule: - continue - _rule, created = DSLayerRule.objects.get_or_create( - object=model, - name=rule['name'] - ) - _rule.rule = rule['rule'] - _rule.color = rule['color'] - _rule.outline_color = rule['outline_color'] - _rule.outline_size = rule['outline_size'] - _rule.active = rule['active'] - _rule.order = idx - _rule.save() - rules_ids.append(_rule.id) + layer_data_style = layer_data.get('style', []) + if isinstance(layer_data_style, list): + for idx, rule in enumerate(layer_data_style): + if 'indicator' in rule: + continue + _rule, created = DSLayerRule.objects.get_or_create( + object=model, + name=rule['name'] + ) + _rule.rule = rule['rule'] + _rule.color = rule['color'] + _rule.outline_color = rule['outline_color'] + _rule.outline_size = rule['outline_size'] + _rule.active = rule['active'] + _rule.order = idx + _rule.save() + rules_ids.append(_rule.id) rules.exclude(id__in=rules_ids).delete() # -----------------------------------------------------