diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-03-18 14:19:18 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-06-17 13:21:27 +0200 |
commit | 13e9facb3b34b82c38ebf2615c34b1c6e151b365 (patch) | |
tree | f306620c09ebfa6c4ba4237ac06fbcf9019a3944 | |
parent | 05bc5da025839537ed0ca5c4b465ccab5a7b57b3 (diff) | |
download | Ishtar-13e9facb3b34b82c38ebf2615c34b1c6e151b365.tar.bz2 Ishtar-13e9facb3b34b82c38ebf2615c34b1c6e151b365.zip |
Fix cached_label update
-rw-r--r-- | ishtar_common/models.py | 10 | ||||
-rw-r--r-- | ishtar_common/utils.py | 16 |
2 files changed, 13 insertions, 13 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index e07dbf930..adad232d5 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -3578,10 +3578,7 @@ class Organization(Address, Merge, OwnPerms, ValueGetter): return (self.name, self.organization_type.txt_idx) def __str__(self): - if self.cached_label: - return self.cached_label - self.save() - return self.cached_label + return self.cached_label or "" def _generate_cached_label(self): if self.name: @@ -3793,10 +3790,7 @@ class Person(Address, Merge, OwnPerms, ValueGetter, MainItem): return " ".join(values) def __str__(self): - if self.cached_label: - return self.cached_label - self.save() - return self.cached_label + return self.cached_label or "" def _generate_cached_label(self): lbl = get_external_id('person_raw_name', self) diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index 828a03da3..4e5259001 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -325,8 +325,6 @@ def force_cached_label_changed(sender, **kwargs): def serialize_args_for_tasks(sender, instance, kwargs, extra_kwargs=None): - if 'signal' in kwargs: - kwargs.pop('signal') if 'instance' in kwargs: kwargs['instance'] = kwargs["instance"].pk sender = (sender._meta.app_label, sender._meta.object_name) @@ -334,6 +332,13 @@ def serialize_args_for_tasks(sender, instance, kwargs, extra_kwargs=None): for kw in extra_kwargs: if getattr(instance, kw, None): kwargs[kw] = getattr(instance, kw) + for k in list(kwargs.keys()): + if k in ["model", "signal", + "_cached_labels_bulk_update"] or kwargs[k] is None: + kwargs.pop(k) + continue + if isinstance(kwargs[k], set): + kwargs[k] = list(kwargs[k]) return sender, kwargs @@ -404,8 +409,8 @@ def _cached_label_changed(sender, **kwargs): instance._cached_label_checked = True cached_labels = ['cached_label'] - if hasattr(sender, 'CACHED_LABELS'): - cached_labels = sender.CACHED_LABELS + if hasattr(instance, 'CACHED_LABELS'): + cached_labels = instance.CACHED_LABELS changed = [] for cached_label in cached_labels: lbl = getattr(instance, '_generate_' + cached_label)() @@ -415,7 +420,8 @@ def _cached_label_changed(sender, **kwargs): instance._search_updated = False if hasattr(instance, '_cascade_change') and instance._cascade_change: instance.skip_history_when_saving = True - sender.objects.filter(pk=instance.pk).update(**dict(changed)) + instance.__class__.objects.filter(pk=instance.pk).update( + **dict(changed)) updated = False if force_update or hasattr(instance, 'update_search_vector'): updated = instance.update_search_vector() |