From f3764eea1ac4a6cdb12095322a00fd93d377c2c5 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 15 Nov 2024 11:51:49 +0100 Subject: ✨ adapt sheet to manage sheet filters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ishtar_common/models_common.py | 2 +- .../templates/ishtar/blocks/sheet_geographic.html | 6 +++++- ishtar_common/templates/ishtar/sheet_organization.html | 4 ++++ ishtar_common/templates/ishtar/sheet_person.html | 4 +++- ishtar_common/templatetags/window_field.py | 4 +++- ishtar_common/views_item.py | 15 +++++++++++---- 6 files changed, 27 insertions(+), 8 deletions(-) (limited to 'ishtar_common') diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index e2fa9988c..ed7cae234 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -881,7 +881,7 @@ class SheetFilter(BaseSheetFilter): _("Exclude or include"), default="E", max_length=1, - choices=(("E", _("exclude")), ("I", _("Include"))) + choices=(("E", _("exclude")), ("I", _("include"))) ) class Meta: diff --git a/ishtar_common/templates/ishtar/blocks/sheet_geographic.html b/ishtar_common/templates/ishtar/blocks/sheet_geographic.html index ae9d2bdf5..d5f8a4d84 100644 --- a/ishtar_common/templates/ishtar/blocks/sheet_geographic.html +++ b/ishtar_common/templates/ishtar/blocks/sheet_geographic.html @@ -36,6 +36,10 @@ {% endautoescape %} {% endif %} +{% empty %} + + {% trans "No geo items" %} + {% endfor %} {% if not IS_HISTORY and permission_change_geo and output != "ODT" and output != "PDF" %} @@ -43,4 +47,4 @@  {% trans "geo item" %} {% endif %} -{% endwith %} \ No newline at end of file +{% endwith %} diff --git a/ishtar_common/templates/ishtar/sheet_organization.html b/ishtar_common/templates/ishtar/sheet_organization.html index b6d18469d..ad629b21b 100644 --- a/ishtar_common/templates/ishtar/sheet_organization.html +++ b/ishtar_common/templates/ishtar/sheet_organization.html @@ -19,6 +19,7 @@ {% field_flex_detail_multiple "Biographical notes" item.biographical_notes %} +{% if item.members.count %}

{%trans "Person in the organization"%}

@@ -39,6 +40,7 @@ {% endfor %}
{% trans "No person in this organization" %}
+{% endif %} {% trans "Associated operations as operator" as ao %} {% if item.operator.count %} @@ -80,10 +82,12 @@ {% endif %} {% if not is_external %} +{% if item.history_creator or item.last_edition_date or item.created %}

{% trans "Sheet"%}

{% include "ishtar/blocks/sheet_creation_section.html" %}
{% endif %} +{% endif %} {% endblock %} diff --git a/ishtar_common/templates/ishtar/sheet_person.html b/ishtar_common/templates/ishtar/sheet_person.html index c34997d30..e0ec0d887 100644 --- a/ishtar_common/templates/ishtar/sheet_person.html +++ b/ishtar_common/templates/ishtar/sheet_person.html @@ -1,7 +1,7 @@ {% extends "ishtar/sheet.html" %} {% load i18n window_field window_tables window_header %} -{% block head_title %}{% trans "Person"%} - {{item}}{% endblock %} +{% block head_title %}{% trans "Person"%} - {{item.raw_name}}{% endblock %} {% block toolbar %} {% window_nav item window_id 'show-person' 'person_modify' %} @@ -173,11 +173,13 @@ {% endif %} {% if not is_external %} +{% if item.history_creator or item.last_edition_date or item.created %}

{% trans "Sheet"%}

{% include "ishtar/blocks/sheet_creation_section.html" %}
{% endif %} +{% endif %} {% endblock %} diff --git a/ishtar_common/templatetags/window_field.py b/ishtar_common/templatetags/window_field.py index 359330eb7..576a7d3cc 100644 --- a/ishtar_common/templatetags/window_field.py +++ b/ishtar_common/templatetags/window_field.py @@ -230,4 +230,6 @@ def m2m_listing(item, key): if key in item: return item[key] return [] - return item.m2m_listing(key) + if callable(item.m2m_listing): + return item.m2m_listing(key) + return [] diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py index 9570687bf..639af1e88 100644 --- a/ishtar_common/views_item.py +++ b/ishtar_common/views_item.py @@ -386,11 +386,13 @@ def filter_sheet(ishtar_user, item): if exclude is None: return item base_keys = [ - "id", "pk", "locked", "is_locked", "SLUG", "APP", "MODEL", - "HAS_QR_CODE", "get_absolute_url", "get_extra_actions", - "get_extra_templates", "can_edit", "can_delete", "DELETE_URL" + "SLUG", "APP", "MODEL", "DELETE_URL" "HAS_QR_CODE", + "id", "pk", "app_label", "model_name", "locked", "is_locked", + "get_absolute_url", "get_extra_actions", "get_extra_templates", + "can_edit", "can_delete" ] base_keys += getattr(item, "SHEET_BASE_KEYS", []) + empty_keys = getattr(item, "SHEET_EMPTY_KEYS", []) if exclude: # cannot exclude base keys len_keys = len(keys) @@ -401,9 +403,14 @@ def filter_sheet(ishtar_user, item): keys += base_keys if exclude: for key in keys: - setattr(item, key, None) + try: + setattr(item, key, None) + except TypeError: + pass return item new_item = type("BaseObject", (object,), {}) + for empty_key in empty_keys: + setattr(new_item, empty_key, None) for key in keys: setattr(new_item, key, getattr(item, key, None)) return new_item -- cgit v1.2.3