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 | |
parent | 43e629c861fe5f73d4a0db94c9c49ac9592228c8 (diff) | |
download | Ishtar-32b4271ea9e7540a7613429563fffde20e57690d.tar.bz2 Ishtar-32b4271ea9e7540a7613429563fffde20e57690d.zip |
🐛 more robust filters for sheets (refs #6109)
11 files changed, 53 insertions, 38 deletions
diff --git a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html index 5c2f46664..29d7f80c6 100644 --- a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html +++ b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html @@ -20,15 +20,15 @@ {% with dating_list=item|m2m_listing:"datings" %} {% with can_view_documents=permission_view_own_document|or_:permission_view_document %} -{% with has_documents=item|safe_or:"documents.count" %} +{% 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 %} -{% with display_relations=item|safe_or:"right_relations.count|left_relations.count" %} -{% with has_image=item|safe_or:"images.count" %} -{% with has_cultural_attributions=item|safe_or:"cultural_attributions.count" %} +{% with display_relations=item|safe_or:"right_relations.count|left_relations.count"|safe_and_not:"right_relations_not_available"|safe_and_not:"left_relations_not_available" %} +{% with has_image=item|safe_or:"images.count"|safe_and_not:"images_not_available" %} +{% with has_cultural_attributions=item|safe_or:"cultural_attributions.count"|safe_and_not:"cultural_attributions_not_available" %} {% with display_interpretation=item|safe_or:"identifications.count"|or_:item.interpretation|or_:item.activity %} {% with display_datations=dating_list|or_:item.taq|or_:item.taq_estimated|or_:item.tpq|or_:item.tpq_estimated|or_:has_cultural_attributions %} {% with can_view_finds=permission_view_own_find|or_:permission_view_find %} -{% with has_finds=item|safe_or:"base_finds.count" %} +{% with has_finds=item|safe_or:"base_finds.count"|safe_and_not:"base_finds_not_available" %} {% with display_finds=has_finds|and_:can_view_finds %} {% with display_data=item.data %} @@ -287,7 +287,7 @@ role="tabpanel" aria-labelledby="{{window_id}}-finds-tab"> {% trans "Finds" as finds %} - {% if item.all_base_finds.count %} + {% if item.all_base_finds.count and not item.base_finds_not_available %} {% dynamic_table_document finds 'finds_for_cr' 'all_base_finds__context_record' item.pk 'TABLE_COLS_FOR_CR' output %} {% else %} <div class="alert alert-info"> diff --git a/archaeological_files/templates/ishtar/sheet_file.html b/archaeological_files/templates/ishtar/sheet_file.html index c29a9ebc1..3cd693320 100644 --- a/archaeological_files/templates/ishtar/sheet_file.html +++ b/archaeological_files/templates/ishtar/sheet_file.html @@ -9,7 +9,7 @@ {% block content %} {% with can_view_documents=permission_view_own_document|or_:permission_view_document %} -{% with has_documents=item.documents.count %} +{% 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 %} {% with has_costs=item.has_equipment_costs|or_:item.has_ground_jobs|or_:item.has_jobs %} @@ -243,7 +243,7 @@ {% trans "Document for this archaeological file" as fle_docs %} {% if permission_view_own_document or permission_view_document %} - {% if item.documents.count %} + {% if has_documents %} {% dynamic_table_document fle_docs 'documents' 'files' item.pk '' output %} {% endif %} {% endif %} @@ -289,7 +289,7 @@ {% endif %} </div> <h3>{% trans "Human and technical requirements" %}</h3> - {% if item.ground_jobs.count %} + {% if item.ground_jobs.count and not item.ground_jobs_not_available%} <div class="col-12"> <h4>{% trans "Ground jobs" %}</h4> <table class="table table-striped"> @@ -341,7 +341,7 @@ </table> </div> {% endif %} - {% if item.jobs.count %} + {% if item.jobs.count and not item.jobs_not_available%} <div class="col-12"> <h4>{% trans "Post-excavation jobs" %}</h4> <table class="table table-striped"> diff --git a/archaeological_finds/templates/ishtar/sheet_find.html b/archaeological_finds/templates/ishtar/sheet_find.html index 787051efb..d7d2b423f 100644 --- a/archaeological_finds/templates/ishtar/sheet_find.html +++ b/archaeological_finds/templates/ishtar/sheet_find.html @@ -29,7 +29,8 @@ {% with can_view_container=permission_view_own_container|or_:permission_view_container %} {% with display_warehouse_treatments=item.container|or_:item.container_ref|or_:item.upstream_treatment|or_:item.downstream_treatment|or_:non_modif_treatments_count|or_:associated_treatment_files_count %} {% with can_view_documents=permission_view_own_document|or_:permission_view_document %} -{% with display_documents=can_view_documents|and_:item.documents_count %} +{% 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 %} {% with has_image=item.images_number %} {% if output != "ODT" and output != "PDF"%} @@ -577,7 +578,7 @@ {% endif %} </div> -{% endwith %} {% endwith %} {% endwith %} {% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %} +{% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %} {% endblock %} diff --git a/archaeological_operations/templates/ishtar/sheet_operation.html b/archaeological_operations/templates/ishtar/sheet_operation.html index a74c78ab1..86c425979 100644 --- a/archaeological_operations/templates/ishtar/sheet_operation.html +++ b/archaeological_operations/templates/ishtar/sheet_operation.html @@ -24,17 +24,18 @@ {% with permission_change_geo=permission_change_own_geovectordata|or_:permission_change_geovectordata %} {% with display_data=item.data %} -{% with display_relations=item|safe_or:"right_relations.count|left_relations.count" %} +{% with display_relations=item|safe_or:"right_relations.count|left_relations.count"|safe_and_not:"right_relations_not_available"|safe_and_not:"left_relations_not_available" %} {% with display_sites=item|safe_or:"archaeological_sites.count|grouped_parcels|administrative_act.count|archaeological_sites_list" %} {% with perm_documents=permission_view_own_document|or_:permission_view_document %} -{% with has_documents=item|safe_or:"documents.count|documents_list" %} +{% with has_documents=item|safe_or:"documents.count|documents_list"|safe_and_not:"documents_not_available" %} {% with display_documents=perm_documents|and_:has_documents %} {% with perm_context_records=permission_view_own_contextrecord|or_:permission_view_contextrecord %} -{% with has_context_records=item|safe_or:"context_record.count" %} +{% with has_context_records=item|safe_or:"context_record.count"|safe_and_not:"context_record_not_available" %} {% with display_context_records=perm_context_records|and_:has_context_records %} {% with perm_find=permission_view_own_find|or_:permission_view_find %} {% with has_finds=item|safe_or:"has_finds" %} {% with display_finds=perm_find|and_:has_finds %} +{% with has_image=item|safe_or:"images.count"|safe_and_not:"images_not_available" %} {% if output != "ODT" and output != "PDF" %} <ul class="nav nav-tabs" id="{{window_id}}-tabs" role="tablist"> @@ -194,7 +195,6 @@ {% field_flex_2 "Code DRASSM" item.drassm_code %} {% field_flex_2 "Old code" item.old_code %} - {% with has_image=item.images.count %} {% if not has_image %} </div> </div> @@ -239,7 +239,6 @@ {% if has_image %} </div> {# <div> #} {% endif %} - {% endwith %} <hr class="clearfix"> {% field_flex_multiple_obj "Remains" item 'remains' %} {% field_flex_multiple_obj "Chronological period" item 'periods' %} @@ -368,7 +367,7 @@ <div class="tab-pane fade" id="{{window_id}}-sites" role="tabpanel" aria-labelledby="{{window_id}}-sites-tab"> {% trans "Archaeological sites" as archaeologicalsites_label %} - {% if item.archaeological_sites.count %} + {% if item.archaeological_sites.count and not item.archaeological_sites_not_available %} {% dynamic_table_document archaeologicalsites_label 'sites' 'operations' item.pk '' output %} {% elif item.archaeological_sites_list %} <h3>{{archaeologicalsites_label}}</h3> @@ -387,12 +386,12 @@ </table> {% endif %} - {% if item.parcels.count %} + {% if item.parcels.count and not item.parcels_not_available %} {% trans "Associated parcels" as parcels_label %} {% include "ishtar/blocks/window_tables/parcels.html" %} {% endif %} - {% if item.administrative_act.count %} + {% if item.administrative_act.count and not item.administrative_act_not_available %} <h3>{% trans "Administrative acts" %}</h3> {% table_administrativact "" item.administrative_act.all %} {% endif %} @@ -403,7 +402,7 @@ <div class="tab-pane fade" id="{{window_id}}-documents" role="tabpanel" aria-labelledby="{{window_id}}-documents-tab"> {% trans "Document from this operation" as operation_docs %} - {% if item.documents.count %} + {% if item.documents.count and not item.documents_not_available %} {% dynamic_table_document operation_docs 'documents' 'operations' item.pk '' output %} {% elif item.documents_list %} <h3>{{operation_docs}}</h3> @@ -416,7 +415,7 @@ <div class="tab-pane fade" id="{{window_id}}-relations" role="tabpanel" aria-labelledby="{{window_id}}-relations-tab"> - {% if item.right_relations.count %} + {% if item.right_relations.count and not item.right_relations_not_available %} <h3>{% trans "Relations"%}</h3> {% for rel in item.right_relations.all %} {% ifchanged rel.relation_type %} @@ -443,8 +442,10 @@ {% if display_context_records %} <div class="tab-pane fade" id="{{window_id}}-cr" role="tabpanel" aria-labelledby="{{window_id}}-cr-tab"> + {% if item.context_record.count %} {% trans "Context records" as cr_lab %} {% dynamic_table_document cr_lab 'context_records_for_ope' 'operation_id' item.pk 'TABLE_COLS_FOR_OPE' output %} + {% endif %} {% if item.context_record_relations_q.count %} {% trans "Context record relations" as cr_rels %} @@ -653,6 +654,6 @@ $(document).ready( function () { } ); {% endlocalize %}</script> -{% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} +{% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endblock %} diff --git a/archaeological_operations/templates/ishtar/sheet_site.html b/archaeological_operations/templates/ishtar/sheet_site.html index c3154fdf5..f1c5b6ec8 100644 --- a/archaeological_operations/templates/ishtar/sheet_site.html +++ b/archaeological_operations/templates/ishtar/sheet_site.html @@ -96,18 +96,18 @@ {% include "ishtar/blocks/sheet_json.html" %} {% trans "Operations" as operations %} -{% if item.operations.count %} +{% if item.operations.count and not item.operations_not_available %} {% dynamic_table_document operations 'operations' 'archaeological_sites' item.pk '' output %} {% endif %} -{% if item.finds.count %} +{% if item.finds.count and not item.finds_not_available %} {% trans "Finds" as finds %} {% dynamic_table_document finds 'finds' 'base_finds__context_record__archaeological_site' item.pk '' output %} {% endif %} {% trans "Documents" as docs %} {% if permission_view_own_document or permission_view_document %} -{% if item.documents.count %} +{% if item.documents.count and not item.documents_not_available %} {% dynamic_table_document docs 'documents' 'sites' item.pk '' output %} {% endif %} {% endif %} diff --git a/archaeological_warehouse/templates/ishtar/sheet_container.html b/archaeological_warehouse/templates/ishtar/sheet_container.html index c34e5de7c..a3acd20e7 100644 --- a/archaeological_warehouse/templates/ishtar/sheet_container.html +++ b/archaeological_warehouse/templates/ishtar/sheet_container.html @@ -10,9 +10,9 @@ {% endblock %} {% block content %} -{% with has_image=item.images.count %} +{% with has_image=item|safe_or:"images.count"|safe_and_not:"images_not_available" %} {% with can_view_documents=permission_view_own_document|or_:permission_view_document %} -{% with has_documents=item.documents.count %} +{% 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 %} {% with permission_change_own_geovectordata=permission_change_own_geovectordata %} @@ -69,7 +69,7 @@ role="tabpanel" aria-labelledby="{{window_id}}-general-tab"> <div class="clearfix"> - {% if has_image %} + {% if has_image and item.images.count %} <div class="card float-left col-12 col-md-4"> {% include "ishtar/blocks/window_image.html" %} </div> @@ -186,19 +186,19 @@ role="tabpanel" aria-labelledby="{{window_id}}-content-tab"> {% if item.container_content.count or item.children.count or item.contained_documents.count %} - {% if item.children.count %} + {% if item.children.count and not item.children_not_available %} <h4>{% trans "Divisions" %}</h4> {% dynamic_table_document '' 'divisions' 'container_tree_child__container_parent__id' item.pk 'TABLE_COLS' output %} <h4>{% trans "Containers" %}</h4> {% dynamic_table_document '' 'non-divisions' 'container_tree_child__container_parent__id' item.pk 'TABLE_COLS' output %} {% endif %} - {% if item.container_content.count %} + {% if item.container_content.count and not item.container_content_not_available %} <h4>{% trans "Finds" %}</h4> {% dynamic_table_document '' 'finds_inside_container' 'container' item.pk 'TABLE_COLS' output 'large' %} {% endif %} - {% if item.contained_documents.count %} + {% if item.contained_documents.count and not item.contained_documents_not_available %} {% trans "Documents" as document_lbl %} {% dynamic_table_document document_lbl 'documents' 'container_id' item.pk 'TABLE_COLS' output 'large' %} {% endif %} diff --git a/archaeological_warehouse/templates/ishtar/sheet_warehouse.html b/archaeological_warehouse/templates/ishtar/sheet_warehouse.html index 377f3a5d3..68e0c0174 100644 --- a/archaeological_warehouse/templates/ishtar/sheet_warehouse.html +++ b/archaeological_warehouse/templates/ishtar/sheet_warehouse.html @@ -8,7 +8,7 @@ {% block content %} {% with can_view_documents=permission_view_own_document|or_:permission_view_document %} -{% with has_documents=item.documents.count %} +{% 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 %} {% with permission_change_own_geovectordata=permission_change_own_geovectordata %} @@ -138,7 +138,7 @@ <div class="tab-pane fade" id="{{window_id}}-content" role="tabpanel" aria-labelledby="{{window_id}}-content-tab"> - {% if item.containers.count %} + {% if item.containers.count and not item.containers_not_available %} <h4>{% trans "Divisions" %}</h4> {% dynamic_table_document '' 'divisions' 'location_id' item.pk 'TABLE_COLS' output %} <h4>{% trans "Containers" %}</h4> 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,), {}) |