diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-02-06 15:24:37 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-02-19 14:45:57 +0100 |
commit | 32b4271ea9e7540a7613429563fffde20e57690d (patch) | |
tree | b99b9d116e9c0a64b18fbf3c24d32ed58db6238d /ishtar_common | |
parent | 43e629c861fe5f73d4a0db94c9c49ac9592228c8 (diff) | |
download | Ishtar-32b4271ea9e7540a7613429563fffde20e57690d.tar.bz2 Ishtar-32b4271ea9e7540a7613429563fffde20e57690d.zip |
🐛 more robust filters for sheets (refs #6109)
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/models_common.py | 2 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/sheet_ishtaruser.html | 2 | ||||
-rw-r--r-- | ishtar_common/templatetags/ishtar_helpers.py | 10 | ||||
-rw-r--r-- | ishtar_common/views_item.py | 7 |
4 files changed, 17 insertions, 4 deletions
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index 4bea24ab5..49c69e9e1 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -881,7 +881,7 @@ class BaseSheetFilter(models.Model): with open(tpl.template.origin.name, "r") as fle: sub_content = fle.read() keys += attrs.findall(sub_content) - return sorted(set(keys)) + return sorted(set([k.replace("_not_available", "") for k in keys])) class SheetFilter(BaseSheetFilter): diff --git a/ishtar_common/templates/ishtar/sheet_ishtaruser.html b/ishtar_common/templates/ishtar/sheet_ishtaruser.html index e30df5278..ce351c720 100644 --- a/ishtar_common/templates/ishtar/sheet_ishtaruser.html +++ b/ishtar_common/templates/ishtar/sheet_ishtaruser.html @@ -69,7 +69,7 @@ <dt>{% trans "Profile(s)" %}</dt> <dd> {% for profile in item.person.profiles.all %} - {% if forloop.counter0 %}; {% endif %}{{profile}} <a target="_blank" href="{{ profile.profile_type.admin_url }}{{profile.profile_type.id}}" title="Modifier"> + {% if forloop.counter0 %}; {% endif %}{{profile.profile_type}} <a target="_blank" href="{{ profile.profile_type.admin_url }}{{profile.profile_type.id}}" title="Modifier"> <i class="fa fa-pencil"></i> </a> {% endfor %} diff --git a/ishtar_common/templatetags/ishtar_helpers.py b/ishtar_common/templatetags/ishtar_helpers.py index bfe7efc2a..cfd04a5d7 100644 --- a/ishtar_common/templatetags/ishtar_helpers.py +++ b/ishtar_common/templatetags/ishtar_helpers.py @@ -52,6 +52,14 @@ def and_(value1, value2): @register.filter +def safe_and_not(item, value): + try: + return item and not getattr(item, value, None) and item + except AttributeError: + return item + + +@register.filter def safe_or(item, args): if not item: return False @@ -72,7 +80,7 @@ def safe_or(item, args): if callable(current_item): result = current_item() if result: - return True + return item return False diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py index b30a9e525..cecc0318d 100644 --- a/ishtar_common/views_item.py +++ b/ishtar_common/views_item.py @@ -446,9 +446,14 @@ def filter_sheet(ishtar_user, item): keys += base_keys if exclude: for key in keys: + param = getattr(item, key, None) + if hasattr(param, "count"): + # set a key_not_available variable in order to filter on the + # sheet non setable variable such as queryset or properties + setattr(item, key + "_not_available", True) try: setattr(item, key, None) - except TypeError: + except (TypeError, AttributeError): pass return item new_item = type("BaseObject", (object,), {}) |