summaryrefslogtreecommitdiff
path: root/ishtar_common/models_common.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2022-10-10 14:19:23 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-12-12 12:23:18 +0100
commit42e058c40b07672d20d680bb9c79c06d8c88a8bc (patch)
tree7cf605894d071e4d6138000935f114cd3cd0c280 /ishtar_common/models_common.py
parent3eff515b8f1159a96326a12ebd05d8e9cc8866bb (diff)
downloadIshtar-42e058c40b07672d20d680bb9c79c06d8c88a8bc.tar.bz2
Ishtar-42e058c40b07672d20d680bb9c79c06d8c88a8bc.zip
Geodata: clean - test town association
Diffstat (limited to 'ishtar_common/models_common.py')
-rw-r--r--ishtar_common/models_common.py13
1 files changed, 5 insertions, 8 deletions
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py
index adf1c1516..0c763965b 100644
--- a/ishtar_common/models_common.py
+++ b/ishtar_common/models_common.py
@@ -2626,15 +2626,10 @@ def geodata_attached_remove(model, instance, pk_set=None, clear=False):
return
# use a cache to manage during geodata attach
- if not hasattr(instance, "_geodata"):
- instance._geodata = []
if instance.main_geodata_id in item_pks:
instance.main_geodata_id = None
instance.skip_history_when_saving = True
instance._no_move = True
- if not hasattr(instance, "_geodata"):
- instance._geodata = []
- instance._geodata += [pk for pk in item_pks if pk not in instance._geodata]
instance.save()
# for all sub item verify that the geo items are present
@@ -2658,6 +2653,9 @@ def geodata_attached_remove(model, instance, pk_set=None, clear=False):
def geodata_attached_changed(sender, **kwargs):
# manage main geoitem and cascade association
+ profile = get_current_profile()
+ if not profile.mapping:
+ return
instance = kwargs.get("instance", None)
model = kwargs.get("model", None)
pk_set = kwargs.get("pk_set", None)
@@ -2711,15 +2709,14 @@ class GeographicItem(models.Model):
using=using,
update_fields=update_fields,
)
- if not hasattr(self, "_geodata"): # use a cache to manage during geodata attach
- self._geodata = []
if self.main_geodata and not self.geodata.filter(pk=self.main_geodata.pk) and\
self.main_geodata.pk not in self._geodata:
self.geodata.add(self.main_geodata)
- self._geodata.append(self.main_geodata.pk)
elif not self.main_geodata and self.geodata.count():
# arbitrary associate the first to geodata
self.main_geodata = self.geodata.order_by("pk").all()[0]
+ self.skip_history_when_saving = True
+ self._no_move = True
self.save()
@property