summaryrefslogtreecommitdiff
path: root/ishtar_common/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r--ishtar_common/utils.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py
index a2fdd36f3..f3df5c282 100644
--- a/ishtar_common/utils.py
+++ b/ishtar_common/utils.py
@@ -419,6 +419,11 @@ EXTRA_KWARGS_TRIGGER = [
]
+def cached_label_and_geo_changed(sender, **kwargs):
+ cached_label_changed(sender=sender, **kwargs)
+ post_save_geo(sender=sender, **kwargs)
+
+
def cached_label_changed(sender, **kwargs):
if not kwargs.get('instance'):
return
@@ -454,11 +459,13 @@ def _cached_label_changed(sender, **kwargs):
return
force_update = kwargs.get('force_update', False)
+ if hasattr(instance, "need_update") and instance.need_update:
+ force_update = True
+ instance.skip_history_when_saving = True
+
if not force_update and getattr(instance, '_cached_label_checked', False):
return
- force_update = kwargs.get('force_update', False)
-
if hasattr(instance, "refresh_cache"):
instance.refresh_cache()
@@ -475,12 +482,19 @@ def _cached_label_changed(sender, **kwargs):
if lbl != getattr(instance, cached_label):
changed.append((cached_label, lbl))
setattr(instance, cached_label, lbl) # update for cache
+
+ if hasattr(instance, "need_update") and instance.need_update:
+ changed.append(("need_update", False))
+ instance.need_update = False
+
if changed:
instance._search_updated = False
if hasattr(instance, '_cascade_change') and instance._cascade_change:
instance.skip_history_when_saving = True
instance.__class__.objects.filter(pk=instance.pk).update(
**dict(changed))
+ if (changed or not cached_labels) and hasattr(instance, "cascade_update"):
+ instance.cascade_update()
updated = False
if force_update or hasattr(instance, 'update_search_vector'):
updated = instance.update_search_vector()
@@ -837,11 +851,17 @@ def _post_save_geo(sender, **kwargs):
instance.point_source = None
modified = True
+ if hasattr(instance, "need_update") and instance.need_update:
+ instance.need_update = False
+ modified = True
+
if modified:
instance.skip_history_when_saving = True
instance._post_saved_geo = True
instance._cached_label_checked = False
instance.save()
+ if hasattr(instance, "cascade_update"):
+ instance.cascade_update()
cache_key, __ = get_cache(
sender, ["post_save_geo", instance.pk]
)