diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-01-27 17:31:00 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-01-27 17:31:00 +0100 |
commit | 466398d76996c5219491807e28709ec17706e8d3 (patch) | |
tree | dc2627a86507fe03bf42b21bcc5fe21183573cf4 /ishtar_common/utils.py | |
parent | fe841330a8811a6a5b828c93520aae2727661dcb (diff) | |
download | Ishtar-466398d76996c5219491807e28709ec17706e8d3.tar.bz2 Ishtar-466398d76996c5219491807e28709ec17706e8d3.zip |
Add custom cached_label configuration for each main item
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r-- | ishtar_common/utils.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index 2ce8a5f9b..7c7e6a6a5 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -555,9 +555,11 @@ def _cached_label_changed(sender, **kwargs): instance.refresh_cache() instance._cached_label_checked = True - cached_labels = ["cached_label"] + cached_labels = [] if hasattr(instance, "CACHED_LABELS"): cached_labels = instance.CACHED_LABELS + if hasattr(instance, "cached_label") and "cached_label" not in cached_labels: + cached_labels.append("cached_label") changed = [] for cached_label in cached_labels: gen_func = "_generate_" + cached_label @@ -1929,7 +1931,7 @@ def _update_gen_id_dct(item, dct, initial_key, fkey=None, filters=None): if not fkey: fkey = initial_key[:] if fkey.startswith("settings__"): - dct[fkey] = getattr(settings, fkey[len("settings__") :]) or "" + dct[fkey] = getattr(settings, fkey[len("settings__"):]) or "" return obj = item for k in fkey.split("__"): @@ -1965,11 +1967,13 @@ def get_generated_id(key, item): if not hasattr(profile, key): return formula = getattr(profile, key) + if not formula: + return "" dct = {} # jinja2 style if "{{" in formula or "{%" in formula: - # naive parse - only simple jija2 is managed + # naive parse - only simple jinja2 is managed key_list = [] for key in PARSE_JINJA.findall(formula): key = key.strip().split("|")[0] @@ -1986,7 +1990,7 @@ def get_generated_id(key, item): new_keys = [] for key in key_list: if key.startswith("not "): - key = key[len("not ") :].strip() + key = key[len("not "):].strip() key = key.split(".")[0] if " % " in key: keys = key.split(" % ")[1] |