summaryrefslogtreecommitdiff
path: root/archaeological_operations
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2021-11-15 16:37:42 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-12-12 12:20:59 +0100
commite3ce9c77d36db4510076b677ec7ce1e0021a51f8 (patch)
treeedb1258d180c35e73a10ab7120c69d81b3925d44 /archaeological_operations
parent905dfbb0ebb91af7b7acaae256306f178863c57f (diff)
downloadIshtar-e3ce9c77d36db4510076b677ec7ce1e0021a51f8.tar.bz2
Ishtar-e3ce9c77d36db4510076b677ec7ce1e0021a51f8.zip
Syndication - serialization - display sheet operation
Diffstat (limited to 'archaeological_operations')
-rw-r--r--archaeological_operations/models.py20
-rw-r--r--archaeological_operations/templates/ishtar/sheet_operation.html83
2 files changed, 92 insertions, 11 deletions
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" %}
<ul class="nav nav-tabs" id="{{window_id}}-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="{{window_id}}-general-tab"
@@ -94,6 +95,7 @@
</a>
</li>
{% endif %}
+ {% if not is_external %}
<li class="nav-item">
<a class="nav-link" id="{{window_id}}-statistics-tab"
data-toggle="tab" href="#{{window_id}}-statistics" role="tab"
@@ -101,6 +103,7 @@
{% trans "Statistics" %}
</a>
</li>
+ {% endif %}
</ul>
{% endif %}
@@ -131,7 +134,7 @@
{% if next %}
{{ item|m2m_listing:'towns'|join:" ; "|default:'' }}
{% else %}
- {{ item.towns_codes|join:" ; "|default:'' }}
+ {{ item.cached_towns_label }}
{% endif %}
</p>
<p class='window-refs' title="{% trans 'Name' %}">{{item.common_name|default:''}}</p>
@@ -141,13 +144,19 @@
<div class="row">
{% 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 %}
<dl class="col-12 col-md-6 col-lg-3 flex-wrap">
<dt>
{% trans "State" %}
@@ -243,10 +252,12 @@
{% field_flex_full "Comment about scientific documentation" item.scientific_documentation_comment "<pre>" "</pre>" %}
</div>
+ {% if not is_external %}
<h3>{% trans "Sheet"%}</h3>
<div class="row">
{% include "ishtar/blocks/sheet_creation_section.html" %}
</div>
+ {% endif %}
{% if item.virtual_operation %}
<div class="alert alert-warning" role="alert">
@@ -282,7 +293,7 @@
{% if next %}
{% field_flex_full "Towns" item|m2m_listing:'towns'|join:" ; " %}
{% else %}
- {% field_flex_full "Towns" item.towns_codes|join:" ; " %}
+ {{ item.cached_towns_label }}
{% endif %}
{% field_flex "Address" item.address %}
{% if not item.address %}
@@ -301,9 +312,24 @@
{% if display_sites %}
<div class="tab-pane fade" id="{{window_id}}-sites"
role="tabpanel" aria-labelledby="{{window_id}}-sites-tab">
- {% if item.archaeological_sites.count %}
{% trans "Archaeological sites" as archaeologicalsites_label %}
+ {% if item.archaeological_sites.count %}
{% dynamic_table_document archaeologicalsites_label 'sites' 'operations' item.pk '' output %}
+ {% elif item.archaeological_sites_list %}
+ <h3>{{archaeologicalsites_label}}</h3>
+ <table class='table table-striped datatables'
+ id="{{window_id}}-sites-table">
+ {% for values in item.archaeological_sites_list %}{% if not forloop.counter0 %}
+ <thead>
+ {% for value in values %}<th class="text-center">{{value}}</th>{% endfor %}
+ </thead>
+ {% else %}
+ <tr>
+ {% for value in values %}<td>{{value}}</td>{% endfor %}
+ </tr>
+ {% endif %}
+ {% endfor %}
+ </table>
{% endif %}
{% if item.parcels.count %}
@@ -322,7 +348,24 @@
<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 %}
{% dynamic_table_document operation_docs 'documents' 'operations' item.pk '' output %}
+ {% elif item.documents_list %}
+ <h3>{{operation_docs}}</h3>
+ <table class='table table-striped datatables'
+ id="{{window_id}}-docs-table">
+ {% for values in item.documents_list %}{% if not forloop.counter0 %}
+ <thead>
+ {% for value in values %}<th class="text-center">{{value}}</th>{% endfor %}
+ </thead>
+ {% else %}
+ <tr>
+ {% for value in values %}<td>{{value}}</td>{% endfor %}
+ </tr>
+ {% endif %}
+ {% endfor %}
+ </table>
+ {% endif %}
</div>
{% endif %}
@@ -414,6 +457,7 @@
{% include "ishtar/blocks/sheet_json.html" %}
</div>
{% endif %}
+ {% if not is_external %}
<div class="tab-pane fade" id="{{window_id}}-statistics"
role="tabpanel" aria-labelledby="{{window_id}}-statistics-tab">
<h3>{% trans "Statistics" %}</h3>
@@ -538,8 +582,27 @@
</div>
{% endif %}
</div>
+ {% endif %}
</div>
-{% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %}
+
+<script type="text/javascript">
+$(document).ready( function () {
+ datatable_options = {
+ "dom": 'ltip',
+ };
+ $.extend(datatable_options, datatables_static_default);
+ if (datatables_i18n) datatable_options['language'] = datatables_i18n;
+ $('.datatables').each(
+ function(){
+ var dt_id = "#" + $(this).attr('id');
+ if (! $.fn.DataTable.isDataTable(dt_id) ) {
+ $(dt_id).DataTable(datatable_options);
+ }
+ });
+} );
+</script>
+
+{% 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