summaryrefslogtreecommitdiff
path: root/archaeological_operations/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_operations/models.py')
-rw-r--r--archaeological_operations/models.py48
1 files changed, 25 insertions, 23 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index d933944d1..74efe2104 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -223,11 +223,15 @@ class GeographicTownItem(GeoItem):
class Meta:
abstract = True
- 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):
# 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_towns = self.towns.filter(main_geodata__multi_polygon__isnull=False)
q_towns_nb = q_towns.count()
@@ -330,9 +334,11 @@ class GeographicTownItem(GeoItem):
if changed and save:
self.no_post_process()
+ self.timestamp_geo = timestamp
self.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 changed
@@ -1048,6 +1054,8 @@ class ArchaeologicalSite(
def site_post_save(sender, **kwargs):
+ timestamp = int(datetime.datetime.now().timestamp())
+ kwargs["timestamp"] = timestamp
cached_label_changed(sender=sender, **kwargs)
post_save_geo(sender=sender, **kwargs)
@@ -1546,9 +1554,11 @@ class Operation(
POST_PROCESS_REQUEST = {
"towns__numero_insee__startswith": "_get_department_code",
}
-
DOWN_MODEL_UPDATE = ["parcels", "context_record"]
-
+ DOWN_MODEL_REVERSE_QUERY = {
+ "context_record": "operation_id",
+ "parcels": "operation_id"
+ }
HISTORICAL_M2M = [
"remains",
"towns",
@@ -2675,6 +2685,8 @@ for attr in Operation.HISTORICAL_M2M:
def operation_post_save(sender, **kwargs):
if not kwargs["instance"]:
return
+ timestamp = int(datetime.datetime.now().timestamp())
+ kwargs["timestamp"] = timestamp
post_save_geo(sender=sender, **kwargs)
operation = kwargs["instance"]
@@ -2702,39 +2714,27 @@ def operation_post_save(sender, **kwargs):
for parcel in operation.parcels.all():
parcel.copy_to_file()
+ """
+ # TODO: delete - should be managed with DOWN_MODEL_UPDATE
# external id, cached_labels update
for parcel in operation.parcels.all():
- cached_label_changed(Parcel, instance=parcel)
+ cached_label_changed(Parcel, instance=parcel, timestamp=timestamp)
ContextRecord = apps.get_model("archaeological_context_records", "ContextRecord")
BaseFind = apps.get_model("archaeological_finds", "BaseFind")
Find = apps.get_model("archaeological_finds", "Find")
for cr in operation.context_record.all():
- cached_label_changed(ContextRecord, instance=cr)
+ cached_label_changed(ContextRecord, instance=cr, timestamp=timestamp)
for bf in cr.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(operation_post_save, sender=Operation)
-def operation_town_m2m_changed(sender, **kwargs):
- operation = kwargs.get("instance", None)
- if not operation:
- return
- operation._prevent_loop = False
- operation.regenerate_all_ids()
- geotown_attached_changed(sender, **kwargs)
- force_cached_label_changed(sender, **kwargs)
-
-
-m2m_changed.connect(
- operation_town_m2m_changed, sender=Operation.towns.through
-)
-
-
class RelationType(GeneralRelationType):
class Meta:
verbose_name = _("Operation relation type")
@@ -3706,6 +3706,8 @@ def parcel_post_save(sender, **kwargs):
if not kwargs["instance"]:
return
parcel = kwargs["instance"]
+ timestamp = int(datetime.datetime.now().timestamp())
+ kwargs["timestamp"] = timestamp
cached_label_changed(sender, **kwargs)
if (