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 --- archaeological_context_records/models.py | 4 ++++ .../templates/ishtar/sheet_contextrecord.html | 10 +++++++++- archaeological_files/models.py | 13 ++++++++++++ .../templates/ishtar/sheet_file.html | 23 ++++++++++++++++------ archaeological_finds/models_finds.py | 2 ++ archaeological_finds/models_treatments.py | 1 + .../templates/ishtar/sheet_basefind.html | 2 ++ .../templates/ishtar/sheet_find.html | 4 ++++ .../templates/ishtar/sheet_findbasket.html | 3 ++- .../templates/ishtar/sheet_museum_find.html | 4 ++++ .../templates/ishtar/sheet_treatment.html | 4 +++- .../templates/ishtar/sheet_treatmentfile.html | 2 ++ archaeological_operations/models.py | 2 ++ .../templates/ishtar/sheet_administrativeact.html | 2 ++ .../templates/ishtar/sheet_operation.html | 16 ++++++++++----- .../templates/ishtar/sheet_site.html | 2 ++ archaeological_warehouse/models.py | 6 +++--- .../templates/ishtar/sheet_container.html | 4 +++- .../templates/ishtar/sheet_warehouse.html | 2 ++ ishtar_common/models_common.py | 2 +- .../templates/ishtar/blocks/sheet_geographic.html | 6 +++++- .../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 ++++++++++---- 25 files changed, 115 insertions(+), 26 deletions(-) diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index dbd7bc463..8046cef7e 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -836,6 +836,10 @@ class ContextRecord( ] UPPER_GEO = ["operation", "archaeological_site"] UPPER_PERMISSIONS = [(Operation, "operation_id")] + SHEET_EMPTY_KEYS = [ + "m2m_listing", "interpretation", "activity", "taq", "taq_estimated", "tpq", + "tpq_estimated" + ] history = HistoricalRecords(bases=[HistoryModel]) objects = UUIDModelManager() diff --git a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html index ff2877176..5c2f46664 100644 --- a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html +++ b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html @@ -139,9 +139,10 @@
+ {% if item.excavation_technics or item.documentations or item.opening_date or item.closing_date or item.structures or item.textures or item.inclusions or item.colors or item.details_on_color or item.filling or item.description %}

{% trans "Description" %}

- {% field_flex_multiple_obj "Excavation techniques" item 'excavation_technics' %} + {% field_flex_multiple_obj _("Excavation technics") item 'excavation_technics' %} {% field_flex_multiple_obj "Documentation" item 'documentations' %} {% field_flex "Opening date" item.opening_date|date:"DATE_FORMAT" %} {% field_flex "Closing date" item.closing_date|date:"DATE_FORMAT" %} @@ -153,6 +154,8 @@ {% field_flex_full "Filling" item.filling "
" "
" %} {% field_flex_full "Description" item.description "
" "
" %}
+ {% endif %} + {% if item.surface or item.length or item.excavated_length or item.width or item.excavated_width or item.diameter or item.depth or item.thickness or item.depth_of_appearance %}

{% trans "Dimensions" %}

{% if item.surface %} @@ -172,6 +175,7 @@ {% field_flex "Thickness (m)" item.thickness %} {% field_flex "Depth of appearance (m)" item.depth_of_appearance %}
+ {% endif %} {% if item.main_geodata or item.town or item.location %}

{% trans "Geographic localisation" %}

@@ -186,10 +190,14 @@ {% 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 %} {% if display_interpretation %}
@@ -65,12 +65,14 @@ {% field_flex "Reception date" item.reception_date|date:"DATE_FORMAT" %} {% field_flex _("Instruction deadline") item.instruction_deadline|date:"DATE_FORMAT" %} {% field_flex_detail _("File managed by") item.in_charge %} + {% if item.is_active != None %}
{%trans "State of the file"%}
{% if item.is_active %}{%trans "Active file"%}{% else %}{%trans "Closed file"%}{% endif %}
+ {% endif %} {% if item.closing %}
{%trans "Closing date"%}
@@ -86,6 +88,7 @@ {% include "ishtar/blocks/sheet_json.html" %} + {% if item.geodata_list or item.towns or item.departments or item.address or item.locality or item.associated_file.address_complement or item.associated_file.postal_code or item.total_surface %}

{% trans "Geographic localisation" %}

{% field_flex_detail_multiple_full "Towns" item.towns %} @@ -103,9 +106,9 @@
{% endif %}
+ {% endif %} {% if item.is_preventive %} -

{% trans "Preventive archaeological file"%}

@@ -143,7 +146,7 @@
{% else %} - + {% if item.scientist or item.requested_operation_type or item.organization or item.cira_advised or item.mh_register or item.mh_listing or item.classified_area or item.protected_area or item.research_comment %}

{% trans "Research archaeology"%}

{% field_flex_detail "Head scientist" item.scientist %} @@ -173,16 +176,19 @@ {% field_flex_full _("Research archaeology comment") item.research_comment "
" "
" %}
+ {% endif %} {% endif %} {% if not next %} - + {% if item.has_parcels %} {% trans "Associated parcels" as parcels_label %} {% include "ishtar/blocks/window_tables/parcels.html" %} - + {% endif %} + {% if item.administrative_act.exists %} {% trans "Administrative acts" as administrativeacts_label %} {% table_administrativact administrativeacts_label item.administrative_act.all %} - + {% endif %} + {% if item.operations.exists %}

{%trans "Associated operations"%}

@@ -209,7 +215,9 @@ {% endfor %}
{% trans "No operation associated to this archaeological file" %}
+ {% endif %} + {% if item.operations_acts %}

{%trans "Admninistrative acts linked to associated operations"%}

@@ -230,6 +238,7 @@ {% endfor %}
+ {% endif %} {% endif %} {% trans "Document for this archaeological file" as fle_docs %} @@ -240,11 +249,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 %} {% if has_costs %}
{% 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 %}
diff --git a/archaeological_finds/templates/ishtar/sheet_find.html b/archaeological_finds/templates/ishtar/sheet_find.html index a3ecbdc67..787051efb 100644 --- a/archaeological_finds/templates/ishtar/sheet_find.html +++ b/archaeological_finds/templates/ishtar/sheet_find.html @@ -259,6 +259,8 @@ {% endif %} {% endwith %} + {% if not is_external %} + {% if item.history_creator or item.last_edition_date or item.created %}

{% trans "Sheet" %}

{% trans "Checked" as checked_label %} @@ -268,6 +270,8 @@ {% endwith %} {% include "ishtar/blocks/sheet_creation_section.html" %}
+ {% endif %} + {% endif %}
diff --git a/archaeological_finds/templates/ishtar/sheet_findbasket.html b/archaeological_finds/templates/ishtar/sheet_findbasket.html index 4b3d9321e..c846c0494 100644 --- a/archaeological_finds/templates/ishtar/sheet_findbasket.html +++ b/archaeological_finds/templates/ishtar/sheet_findbasket.html @@ -21,9 +21,10 @@ {% field_flex_detail_multiple_full treatment_label item.treatment_files %}
+{% if item.items.exists %}

{% trans "Content" %}

{% dynamic_table_document finds 'finds' 'basket_id' item.pk 'TABLE_COLS' output %} - +{% endif %} {% endblock %} diff --git a/archaeological_finds/templates/ishtar/sheet_museum_find.html b/archaeological_finds/templates/ishtar/sheet_museum_find.html index 73e76d8bd..3c00a5d38 100644 --- a/archaeological_finds/templates/ishtar/sheet_museum_find.html +++ b/archaeological_finds/templates/ishtar/sheet_museum_find.html @@ -238,6 +238,8 @@ {% endif %} {% endwith %} + {% if not is_external %} + {% if item.history_creator or item.last_edition_date or item.created %}

{% trans "Sheet" %}

{% trans "Checked" as checked_label %} @@ -247,6 +249,8 @@ {% endwith %} {% include "ishtar/blocks/sheet_creation_section.html" %}
+ {% endif %} + {% endif %} {% if has_image %} {% endif %} diff --git a/archaeological_finds/templates/ishtar/sheet_treatment.html b/archaeological_finds/templates/ishtar/sheet_treatment.html index ea37897b6..0a23e551a 100644 --- a/archaeological_finds/templates/ishtar/sheet_treatment.html +++ b/archaeological_finds/templates/ishtar/sheet_treatment.html @@ -1,7 +1,7 @@ {% extends "ishtar/sheet.html" %} {% load i18n l10n window_field from_dict link_to_window window_tables window_ope_tables window_header humanize %} -{% block head_title %}{% trans "Treatment" %} - {{ item|default:"" }}{% endblock %} +{% block head_title %}{% trans "Treatment" %} - {{ item.cached_label|default:"" }}{% endblock %} {% block toolbar %} {% window_nav item window_id 'show-treatment' 'treatment_modify' 'show-historized-treatment' 'revert-treatment' previous next 1 %} @@ -99,11 +99,13 @@ {% 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 %} {% if has_image %}{% endif %} diff --git a/archaeological_finds/templates/ishtar/sheet_treatmentfile.html b/archaeological_finds/templates/ishtar/sheet_treatmentfile.html index 952171aa1..6cca72570 100644 --- a/archaeological_finds/templates/ishtar/sheet_treatmentfile.html +++ b/archaeological_finds/templates/ishtar/sheet_treatmentfile.html @@ -89,11 +89,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 %} {% endwith %}{% endwith %}{% endwith %} {% endblock %} diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 9d0f8142b..84bd8ab2e 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -1555,6 +1555,7 @@ class Operation( "archaeological_sites", ] SERIALIZE_STRING = ["scientist", "in_charge", "cira_rapporteur"] + SHEET_EMPTY_KEYS = ["code_patriarche", "common_name", "short_label"] # fields definition uuid = models.UUIDField(default=uuid.uuid4) @@ -3085,6 +3086,7 @@ class AdministrativeAct(DocumentItem, BaseHistorizedItem, OwnPerms, ValueGetter, (("archaeological_finds", "treatment"), "treatment_id"), ] + SHEET_EMPTY_KEYS = ["act_type", "full_ref"] # fields act_type = models.ForeignKey( diff --git a/archaeological_operations/templates/ishtar/sheet_administrativeact.html b/archaeological_operations/templates/ishtar/sheet_administrativeact.html index 1044a3dad..f344a1fb6 100644 --- a/archaeological_operations/templates/ishtar/sheet_administrativeact.html +++ b/archaeological_operations/templates/ishtar/sheet_administrativeact.html @@ -85,10 +85,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/archaeological_operations/templates/ishtar/sheet_operation.html b/archaeological_operations/templates/ishtar/sheet_operation.html index be490ba28..8613d2da6 100644 --- a/archaeological_operations/templates/ishtar/sheet_operation.html +++ b/archaeological_operations/templates/ishtar/sheet_operation.html @@ -147,6 +147,7 @@
{% if item.year %}{% trans "Year" %}{{ item.year|unlocalize }}{% endif %} + {% if next or item.cached_towns_label %} {% trans "Towns" %} {% if next %} {{ item|m2m_listing:'towns'|join:" ; "|default:'' }} @@ -154,6 +155,7 @@ {{ item.cached_towns_label }} {% endif %} + {% endif %} {% if item.common_name %}{% trans "Name" %}{{ item.common_name }}{% endif %} {% if item.address %}{% trans "Address / Locality" %}{{ item.address }}{% endif %}
@@ -174,6 +176,7 @@ {% field_flex_2 date_label dates %} {% endwith %}{% endwith %}{% endwith %} {% endif %}{% endif %} + {% if item.is_active != None %}
{% trans "State" %} @@ -187,7 +190,7 @@ {% trans "Closed operation" %} {% endif %} -
+ {% endif %} {% field_flex_2 "Code DRASSM" item.drassm_code %} {% field_flex_2 "Old code" item.old_code %} @@ -297,7 +300,7 @@ {% endif %} - {% if not item.code_patriarche %} + {% if item.code_patriarche == "" %} {% endif %} - + {% if item.geodata_list or item.towns or item.address or item.associated_file.address or item.associated_file.address_complement or item.associated_file.postal_code %}

{% trans "Geographic localisation" %}

@@ -339,7 +342,7 @@
{% if next %} {% field_flex "Towns" item|m2m_listing:'towns'|join:" ; " %} - {% else %} + {% elif item.towns %} {% field_flex_detail_multiple_full "Towns" item.towns %} {% endif %} {% field_flex "Address" item.address %} @@ -349,12 +352,15 @@ {% field_flex "Postal code" item.associated_file.postal_code %} {% endif %}
+ {% 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 %}
@@ -649,4 +655,4 @@ $(document).ready( function () { {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/archaeological_operations/templates/ishtar/sheet_site.html b/archaeological_operations/templates/ishtar/sheet_site.html index f87888655..c3154fdf5 100644 --- a/archaeological_operations/templates/ishtar/sheet_site.html +++ b/archaeological_operations/templates/ishtar/sheet_site.html @@ -118,11 +118,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 %} {% endwith %} {% endwith %} {% endwith %} {% endblock %} diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index d39e90e97..e9f012ff7 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -1583,9 +1583,9 @@ class Container( @property def associated_filename(self): filename = datetime.date.today().strftime("%Y-%m-%d") - filename += "-" + self.reference - filename += "-" + self.location.name - filename += "-" + str(self.index) + filename += "-" + (self.reference or "") + filename += "-" + (self.location.name or "") + filename += "-" + str((self.index or "")) if self.cached_division is None: self.skip_history_when_saving = True self.save() diff --git a/archaeological_warehouse/templates/ishtar/sheet_container.html b/archaeological_warehouse/templates/ishtar/sheet_container.html index a8e2ab13e..c34e5de7c 100644 --- a/archaeological_warehouse/templates/ishtar/sheet_container.html +++ b/archaeological_warehouse/templates/ishtar/sheet_container.html @@ -2,7 +2,7 @@ {% load i18n l10n ishtar_helpers window_header window_field window_tables link_to_window %} {% block head_title %}{% trans "Container" %} - -{{ item.reference|default:"" }} ({{ item.container_type|default:"" }}) - {{item.location}} +{{ item.reference|default:"" }}{% if item.container_type %} ({{ item.container_type|default:"" }}){% endif %}{% if item.location %} - {{item.location}}{% endif %} {% endblock %} {% block toolbar %} @@ -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 %}
{% trans "Sheet"%}
{% include "ishtar/blocks/sheet_creation_section.html" %}
{% endif %} + {% endif %}
{% 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