diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-10-11 10:19:58 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-12-12 12:23:18 +0100 |
commit | e9193d8d29e9b18e0d553302f3e94053021fc622 (patch) | |
tree | 7ccc9e40dfa66e0e0e2da40a75f9af0ef4df0c2f /ishtar_common | |
parent | 58f281c8d31f939f07ed0f2d34799f476750fbb6 (diff) | |
download | Ishtar-e9193d8d29e9b18e0d553302f3e94053021fc622.tar.bz2 Ishtar-e9193d8d29e9b18e0d553302f3e94053021fc622.zip |
Geodata: manage m2m signal town association
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/models_common.py | 17 | ||||
-rw-r--r-- | ishtar_common/tests.py | 13 |
2 files changed, 26 insertions, 4 deletions
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index 0c763965b..a7dc8464e 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -2930,6 +2930,23 @@ def town_child_changed(sender, **kwargs): m2m_changed.connect(town_child_changed, sender=Town.children.through) +def geotown_attached_changed(sender, **kwargs): + # manage associated geoitem + 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) + action = kwargs.get("action", None) + if not instance or not model or not hasattr(instance, "post_save_geo"): + return + + instance._post_save_geo_ok = False + if action in ("post_add", "post_remove", "post_clear"): + instance.post_save_geo(save=True) + + class Address(BaseHistorizedItem): FIELDS = ( "address", diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index cfd3544dd..7671f2fe4 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -3518,9 +3518,6 @@ class GeoVectorTest(TestCase): self.assertEqual(town.main_geodata, geo_vector_town) self.operation.towns.add(town) - self._reinit_objects() - # save need to be forced... keep it? - self.operation.save() self._reinit_objects() self.assertEqual(self.operation.geodata.count(), 1) @@ -3530,7 +3527,15 @@ class GeoVectorTest(TestCase): self.assertEqual(self.base_find.geodata.count(), 1) self.assertEqual(self.base_find.main_geodata, geo_vector_town) - # test town remove + self.operation.towns.remove(town) + + self._reinit_objects() + self.assertIsNone(self.operation.main_geodata) + self.assertEqual(self.operation.geodata.count(), 0) + self.assertIsNone(self.context_record.main_geodata) + self.assertEqual(self.context_record.geodata.count(), 0) + self.assertIsNone(self.base_find.main_geodata) + self.assertEqual(self.base_find.geodata.count(), 0) class NewItems(TestCase): |