From e3ce9c77d36db4510076b677ec7ce1e0021a51f8 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 15 Nov 2021 16:37:42 +0100 Subject: Syndication - serialization - display sheet operation --- archaeological_operations/models.py | 20 +++++- .../templates/ishtar/sheet_operation.html | 83 +++++++++++++++++++--- 2 files changed, 92 insertions(+), 11 deletions(-) (limited to 'archaeological_operations') diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 050e50240..4747fbf9e 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -75,6 +75,7 @@ from ishtar_common.model_managers import UUIDModelManager from ishtar_common.utils import ( cached_label_changed, force_cached_label_changed, + human_date, mode, m2m_historization_changed, post_save_geo, @@ -732,6 +733,14 @@ def get_values_town_related(item, prefix, values, filtr=None): class ClosedItem(object): + def serialize_closing(self): + value = self.closing() + if not value: + return "" + value["date"] = human_date(value["date"]) + value["user"] = str(value["user"]) + return value + def closing(self): if self.is_active(): return @@ -1120,6 +1129,11 @@ class Operation( "towns", "periods", ] + SERIALIZE_PROPERTIES = MainItem.SERIALIZE_PROPERTIES + ["short_label"] + SERIALIZE_DATES = ["start_date", "excavation_end_date"] + SERIALIZE_CALL = {"closing": "serialize_closing", + "archaeological_sites_list": "archaeological_sites_list", + "documents_list": "documents_list"} # fields definition uuid = models.UUIDField(default=uuid.uuid4) @@ -1460,6 +1474,10 @@ class Operation( ) return dct + def archaeological_sites_list(self) -> list: + return self.get_associated_main_item_list("archaeological_sites", + ArchaeologicalSite) + @classmethod def _get_department_code(cls, value): if not settings.ISHTAR_DPTS: @@ -1499,7 +1517,7 @@ class Operation( return [town.label_with_areas for town in self.towns.all()] def towns_label(self): - return " - ".join(self.towns_codes()) + return " ; ".join(self.towns_codes()) def has_finds(self): from archaeological_finds.models import BaseFind diff --git a/archaeological_operations/templates/ishtar/sheet_operation.html b/archaeological_operations/templates/ishtar/sheet_operation.html index babcc9ce0..811997515 100644 --- a/archaeological_operations/templates/ishtar/sheet_operation.html +++ b/archaeological_operations/templates/ishtar/sheet_operation.html @@ -21,9 +21,10 @@ {% with display_data=item.data %} {% with display_relations=item|safe_or:"right_relations.count|left_relations.count" %} -{% with display_sites=item|safe_or:"archaeological_sites.count|grouped_parcels|administrative_act.count" %} +{% 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 display_documents=perm_documents|and_:item.documents.count %} +{% with has_documents=item|safe_or:"documents.count|documents_list" %} +{% 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 display_context_records=perm_context_records|and_:has_context_records %} @@ -31,7 +32,7 @@ {% with has_finds=item|safe_or:"has_finds" %} {% with display_finds=perm_find|and_:has_finds %} -{% if output != "ODT" and output != "PDF"%} +{% if output != "ODT" and output != "PDF" %} {% endif %} @@ -131,7 +134,7 @@ {% if next %} {{ item|m2m_listing:'towns'|join:" ; "|default:'' }} {% else %} - {{ item.towns_codes|join:" ; "|default:'' }} + {{ item.cached_towns_label }} {% endif %}

{{item.common_name|default:''}}

@@ -141,13 +144,19 @@
{% trans "Excavation dates (start/end)" as date_label %} + {% if not is_external %} {% with start_date=item.start_date|date:"DATE_FORMAT"|default:"-" %} {% with end_date=item.excavation_end_date|date:"DATE_FORMAT"|default:"-" %} {% with dates=start_date|add:" / "|add:end_date %} {% field_flex_2 date_label dates %} - {% endwith %} - {% endwith %} - {% endwith %} + {% endwith %}{% endwith %}{% endwith %} + {% else %} + {% with start_date=item.start_date|default:"-" %} + {% with end_date=item.excavation_end_date|default:"-" %} + {% with dates=start_date|add:" / "|add:end_date %} + {% field_flex_2 date_label dates %} + {% endwith %}{% endwith %}{% endwith %} + {% endif %}
{% trans "State" %} @@ -243,10 +252,12 @@ {% field_flex_full "Comment about scientific documentation" item.scientific_documentation_comment "
" "
" %}
+ {% if not is_external %}

{% trans "Sheet"%}

{% include "ishtar/blocks/sheet_creation_section.html" %}
+ {% endif %} {% if item.virtual_operation %} + {% endif %} -{% 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 %} \ No newline at end of file -- cgit v1.2.3