From 362df5dd42f41237ed1545571704a56db59e4d46 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 23 Dec 2016 17:01:35 +0100 Subject: Add index to containers (refs #3391) - manage multiple cached labels --- ishtar_common/utils.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'ishtar_common/utils.py') diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index 44112bca3..9b3c85694 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -60,11 +60,18 @@ def cached_label_changed(sender, **kwargs): and instance._cached_label_checked: return instance._cached_label_checked = True - lbl = instance._generate_cached_label() - if lbl != instance.cached_label: + cached_labels = ['cached_label'] + if hasattr(sender, 'CACHED_LABELS'): + cached_labels = sender.CACHED_LABELS + changed = False + for cached_label in cached_labels: + lbl = getattr(instance, '_generate_' + cached_label)() + if lbl != getattr(instance, cached_label): + setattr(instance, cached_label, lbl) + changed = True + if changed: if hasattr(instance, '_cascade_change') and instance._cascade_change: instance.skip_history_when_saving = True - instance.cached_label = lbl instance.save() if hasattr(instance, '_get_associated_cached_labels'): for item in instance._get_associated_cached_labels(): -- cgit v1.2.3