diff options
Diffstat (limited to 'archaeological_context_records/models.py')
-rw-r--r-- | archaeological_context_records/models.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 29e8b56a8..406c50057 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -18,6 +18,7 @@ # See the file COPYING for details. from collections import OrderedDict +import datetime import uuid from django.apps import apps @@ -435,11 +436,15 @@ class GeographicSubTownItem(GeoItem): def _get_geo_town(self): raise NotImplementedError() - def post_save_geo(self, save=True): + def post_save_geo(self, save=True, timestamp=None): # manage geodata towns if getattr(self, "_post_save_geo_ok", False) or not self.pk: # prevent infinite loop - should not happen, but... return + if not timestamp: + timestamp = int(datetime.datetime.now().timestamp()) + if hasattr(self, "timestamp_geo") and (self.timestamp_geo or 0) >= timestamp: + return self._post_save_geo_ok = True q_geodata_current_town = self.geodata.filter( @@ -512,7 +517,8 @@ class GeographicSubTownItem(GeoItem): return False if save: post_save_geo(self.__class__, instance=self, created=False, - update_fields=False, raw=False, using="default") + update_fields=False, raw=False, using="default", + timestamp=timestamp) return True @@ -1431,20 +1437,22 @@ class ContextRecord( def context_record_post_save(sender, **kwargs): - cached_label_changed(sender=sender, **kwargs) - post_save_geo(sender=sender, **kwargs) instance = kwargs.get("instance", None) if not instance or not instance.pk: return + timestamp = int(datetime.datetime.now().timestamp()) + kwargs["timestamp"] = timestamp + cached_label_changed(sender=sender, **kwargs) + post_save_geo(sender=sender, **kwargs) profile = get_current_profile() if profile.parent_relations_engine == "T": ContextRecordTree._update_self_relation(instance.pk) # on creation: manage self relation BaseFind = apps.get_model("archaeological_finds", "BaseFind") Find = apps.get_model("archaeological_finds", "Find") for bf in instance.base_finds.all(): - cached_label_changed(BaseFind, instance=bf) + cached_label_changed(BaseFind, instance=bf, timestamp=timestamp) for f in bf.find.all(): - cached_label_changed(Find, instance=f) + cached_label_changed(Find, instance=f, timestamp=timestamp) post_save.connect(context_record_post_save, sender=ContextRecord) |