From ce71f7f286819ee1399fef5f1819f9cc812149a6 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 13 Mar 2025 13:30:02 +0100 Subject: ✨ sheets: refactor document listing - add edit and unlink actions (refs #6221) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/ishtar/sheet_contextrecord.html | 9 ++-- archaeological_finds/models_treatments.py | 5 +- .../templates/ishtar/sheet_exhibition.html | 5 +- .../templates/ishtar/sheet_find.html | 10 ++-- .../templates/ishtar/sheet_museum_find.html | 10 ++-- .../templates/ishtar/sheet_treatment.html | 19 +++++--- .../templates/ishtar/sheet_treatmentfile.html | 5 +- .../templates/ishtar/sheet_operation.html | 10 ++-- .../templates/ishtar/sheet_container.html | 9 ++-- .../templates/ishtar/sheet_warehouse.html | 9 ++-- ishtar_common/models.py | 4 ++ ishtar_common/models_common.py | 4 ++ .../templates/ishtar/blocks/api_document_list.html | 4 +- .../ishtar/blocks/sheet_document_list.html | 53 +++++++++++++++++++++ .../templates/ishtar/blocks/sheet_geographic.html | 16 +++---- ishtar_common/templates/ishtar/sheet_area.html | 7 +-- ishtar_common/templates/ishtar/sheet_document.html | 2 +- ishtar_common/templates/ishtar/sheet_town.html | 7 +-- ishtar_common/templatetags/ishtar_helpers.py | 12 +++++ ishtar_common/templatetags/link_to_window.py | 2 +- ishtar_common/urls.py | 7 +++ ishtar_common/views.py | 55 +++++++++++++++++++++- ishtar_common/views_item.py | 1 + 23 files changed, 195 insertions(+), 70 deletions(-) create mode 100644 ishtar_common/templates/ishtar/blocks/sheet_document_list.html diff --git a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html index 29d7f80c6..f43df6c4e 100644 --- a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html +++ b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html @@ -346,12 +346,9 @@ {% if display_documents %}
- {% trans "Document from this context record" as cr_docs %} - {% if permission_view_own_document or permission_view_document %} - {% if item.documents.count %} - {% dynamic_table_document cr_docs 'documents' 'context_records' item.pk '' output %} - {% endif %} - {% endif %} + {% with permission_change_item=item|can_edit_item:request %} + {% include "ishtar/blocks/sheet_document_list.html" %} + {% endwith %}
{% endif %} diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py index 0c684d98a..69a8b899c 100644 --- a/archaeological_finds/models_treatments.py +++ b/archaeological_finds/models_treatments.py @@ -196,14 +196,13 @@ class AssociatedFindBasket: class Treatment( DashboardFormItem, AssociatedFindBasket, - ValueGetter, DocumentItem, BaseHistorizedItem, CompleteIdentifierItem, ImageModel, OwnPerms, - ShortMenuItem, - SheetItem, + ValueGetter, + MainItem, ): SLUG = "treatment" APP = "archaeological-finds" diff --git a/archaeological_finds/templates/ishtar/sheet_exhibition.html b/archaeological_finds/templates/ishtar/sheet_exhibition.html index 820391a9e..76cf7c495 100644 --- a/archaeological_finds/templates/ishtar/sheet_exhibition.html +++ b/archaeological_finds/templates/ishtar/sheet_exhibition.html @@ -78,8 +78,9 @@ {% if display_documents %} - {% trans "Associated documents" as associated_docs %} - {% dynamic_table_document associated_docs 'documents' 'treatment_files' item.pk '' output %} + {% with permission_change_item=item|can_edit_item:request %} + {% include "ishtar/blocks/sheet_document_list.html" %} + {% endwith %} {% endif %} {% if item.administrative_act.count %} diff --git a/archaeological_finds/templates/ishtar/sheet_find.html b/archaeological_finds/templates/ishtar/sheet_find.html index d38b0060f..9b439825c 100644 --- a/archaeological_finds/templates/ishtar/sheet_find.html +++ b/archaeological_finds/templates/ishtar/sheet_find.html @@ -280,13 +280,9 @@ {% if display_documents %}
- {% trans "Associated documents" as finds_docs %} - {% if item.documents.count %} - {% dynamic_table_document finds_docs 'documents' 'finds' item.pk '' output %} - {% elif item.documents_list %} -

{{finds_docs}}

- {% include "ishtar/blocks/api_document_list.html" %} - {% endif %} + {% with permission_change_item=item|can_edit_item:request %} + {% include "ishtar/blocks/sheet_document_list.html" %} + {% endwith %}
{% endif %} diff --git a/archaeological_finds/templates/ishtar/sheet_museum_find.html b/archaeological_finds/templates/ishtar/sheet_museum_find.html index 2f313f0a1..fb5e2adca 100644 --- a/archaeological_finds/templates/ishtar/sheet_museum_find.html +++ b/archaeological_finds/templates/ishtar/sheet_museum_find.html @@ -304,13 +304,9 @@ {% if display_documents %}
- {% trans "Associated documents" as finds_docs %} - {% if item.documents.count %} - {% dynamic_table_document finds_docs 'documents' 'finds' item.pk '' output %} - {% elif item.documents_list %} -

{{finds_docs}}

- {% include "ishtar/blocks/api_document_list.html" %} - {% endif %} + {% with permission_change_item=item|can_edit_item:request %} + {% include "ishtar/blocks/sheet_document_list.html" %} + {% endwith %}
{% endif %} diff --git a/archaeological_finds/templates/ishtar/sheet_treatment.html b/archaeological_finds/templates/ishtar/sheet_treatment.html index 7fa2097f0..ae180dd5e 100644 --- a/archaeological_finds/templates/ishtar/sheet_treatment.html +++ b/archaeological_finds/templates/ishtar/sheet_treatment.html @@ -1,5 +1,5 @@ {% extends "ishtar/sheet.html" %} -{% load i18n l10n window_field from_dict link_to_window window_tables window_ope_tables window_header humanize %} +{% load i18n l10n ishtar_helpers window_field from_dict link_to_window window_tables window_ope_tables window_header humanize %} {% block head_title %}{% trans "Treatment" %} - {{ item.cached_label|default:"" }}{% endblock %} @@ -8,6 +8,12 @@ {% endblock %} {% block content %} +{# trick to set to null non existing variable #} +{% with permission_view_document=permission_view_document %} +{% with permission_view_own_document=permission_view_own_document %} +{% with can_view_documents=permission_view_own_document|or_:permission_view_document %} +{% with has_documents=item|safe_or:"documents.count|documents_list"|safe_and_not:"documents_not_available" %} +{% with display_documents=can_view_documents|and_:has_documents %}