diff options
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/models_common.py | 3 | ||||
-rw-r--r-- | ishtar_common/utils.py | 50 |
2 files changed, 50 insertions, 3 deletions
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index 84b46d2c6..c5c550b5a 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -3319,6 +3319,8 @@ class MainItem(ShortMenuItem, SerializeItem): def cascade_update(self, changed=True): if not changed: return + if getattr(self, "_no_down_model_update", False): + return for down_model in self.DOWN_MODEL_UPDATE: if not settings.USE_BACKGROUND_TASK: rel = getattr(self, down_model) @@ -3338,6 +3340,7 @@ class MainItem(ShortMenuItem, SerializeItem): self._external_id_checked = True self._search_updated = True self._no_move = True + self._no_down_model_update = True @classmethod def app_label(cls): diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index 2becd20ce..bbefd085e 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -544,7 +544,26 @@ def load_task(task_func, task_name, checks, sender, **kwargs): def cached_label_changed(sender, **kwargs): - load_task(_external_id_changed, "external_id_changed", None, sender, **kwargs) + if "instance" not in kwargs: + return + instance = kwargs["instance"] + if not instance: + return + if hasattr(instance, "external_id") and hasattr(instance, "auto_external_id") \ + and hasattr(instance, "SLUG") and not getattr(instance, "_external_id_checked", None): + changed = load_task(_external_id_changed, "external_id_changed", None, sender, **kwargs) + if changed and ( + not settings.USE_BACKGROUND_TASK + or not instance.pk + or not sender.objects.filter(pk=instance.pk).count() + ): # cached_label_changed re-triggered + return + + force_update = kwargs.get("force_update", False) + if getattr(instance, "need_update", False): + force_update = True + if not force_update and getattr(instance, "_cached_label_checked", False): + return return load_task(_cached_label_changed, "cached_label_changed", None, sender, **kwargs) @@ -627,6 +646,15 @@ def regenerate_all_cached_labels(model): def external_id_changed(sender, **kwargs): + if "instance" not in kwargs: + return + instance = kwargs["instance"] + if not instance or not hasattr(instance, "external_id") \ + or not hasattr(instance, "auto_external_id") \ + or not hasattr(instance, "SLUG"): + return + if getattr(instance, "_external_id_checked", None): + return return load_task(_external_id_changed, "external_id_changed", ["_external_id_changed"], sender, **kwargs) @@ -651,7 +679,13 @@ def _external_id_changed(sender, **kwargs): updated |= instance.regenerate_all_ids(save=False) or False instance._external_id_checked = True if updated: + if settings.USE_BACKGROUND_TASK and hasattr(instance, "no_post_process"): + instance.no_post_process() + else: + instance._no_move = True + instance.skip_history_when_saving = True instance.save() + return True def shortify(lbl, number=20): @@ -849,6 +883,13 @@ def post_save_geo(sender, **kwargs): """ Convert raw x, y, z point to real geo field """ + if "instance" not in kwargs: + return + instance = kwargs["instance"] + if not instance: + return + if getattr(instance, "_post_saved_geo", False): + return return load_task(_post_save_geo, "post_save_geo", ["_no_geo_check"], sender, **kwargs) @@ -880,8 +921,11 @@ def _post_save_geo(sender, **kwargs): modified = True if modified: - instance.skip_history_when_saving = True - instance._post_saved_geo = True + if hasattr(instance, "no_post_process"): + instance.no_post_process() + else: + instance.skip_history_when_saving = True + instance._post_saved_geo = True instance._cached_label_checked = False instance.save() if hasattr(instance, "cascade_update"): |