summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_context_records/models.py16
-rw-r--r--archaeological_finds/models_finds.py47
-rw-r--r--archaeological_finds/templates/ishtar/sheet_basefind.html6
-rw-r--r--archaeological_finds/templates/ishtar/sheet_find.html47
-rw-r--r--archaeological_operations/templates/ishtar/sheet_operation.html14
-rw-r--r--archaeological_warehouse/models.py7
-rw-r--r--ishtar_common/models.py6
-rw-r--r--ishtar_common/models_common.py15
-rw-r--r--ishtar_common/templates/ishtar/blocks/api_document_list.html13
-rw-r--r--ishtar_common/templates/ishtar/blocks/sheet_creation_section.html2
-rw-r--r--ishtar_common/templates/ishtar/blocks/window_image.html2
11 files changed, 134 insertions, 41 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index ef9e2788e..29e8793dc 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -66,7 +66,7 @@ from ishtar_common.models import (
QuickAction,
RelationsViews,
)
-from ishtar_common.models_common import HistoricalRecords
+from ishtar_common.models_common import HistoricalRecords, SerializeItem
from archaeological_operations.models import (
Operation,
Period,
@@ -98,7 +98,9 @@ post_save.connect(post_save_cache, sender=DatingQuality)
post_delete.connect(post_save_cache, sender=DatingQuality)
-class Dating(models.Model):
+class Dating(models.Model, SerializeItem):
+ SLUG = "dating"
+ SERIALIZE_EXCLUDE = ["find", "context_record"]
uuid = models.UUIDField(default=uuid.uuid4)
period = models.ForeignKey(
Period, verbose_name=_("Period"), on_delete=models.PROTECT
@@ -614,6 +616,10 @@ class ContextRecord(
),
]
SERIALIZE_EXCLUDE = MainItem.SERIALIZE_EXCLUDE + ["contextrecord"]
+ SERIALIZE_PROPERTIES = MainItem.SERIALIZE_PROPERTIES + [
+ "short_label",
+ "town_label_with_areas",
+ ]
history = HistoricalRecords(bases=[HistoryModel])
objects = UUIDModelManager()
@@ -975,6 +981,12 @@ class ContextRecord(
)
@property
+ def town_label_with_areas(self):
+ if not self.town:
+ return ""
+ return self.town.label_with_areas
+
+ @property
def relation_label(self):
return self.label
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index 6ccf6c990..583ee405a 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -395,6 +395,9 @@ class BaseFind(
EXTERNAL_ID_KEY = "base_find_external_id"
EXTERNAL_ID_DEPENDENCIES = ["find"]
SLUG = "basefind"
+ SERIALIZE_EXCLUDE = ["find"]
+ SERIALIZE_CALL = {"complete_id": "complete_id", "short_id": "short_id"}
+
uuid = models.UUIDField(default=uuid.uuid4)
label = models.TextField(_("Free ID"))
external_id = models.TextField(_("External ID"), blank=True, default="")
@@ -1759,9 +1762,20 @@ class Find(
"cached_object_types",
"cached_materials",
]
- SERIALIZE_PROPERTIES = ["external_id"]
- SERIALIZE_CALL = {"base_finds_list": "base_finds_list",
- "documents_list": "documents_list"}
+ SERIALIZE_CALL = {
+ "base_finds_list": "base_finds_list",
+ "documents_list": "documents_list",
+ "m2m_listing_datings": "m2m_listing_datings",
+ }
+ SERIALIZE_PROPERTIES = MainItem.SERIALIZE_PROPERTIES + [
+ "administrative_index",
+ "integrities_count",
+ "remarkabilities_count",
+ "cultural_attributions_count",
+ "documents_count",
+ "excavation_ids",
+ "weight_string",
+ ]
objects = UUIDModelManager()
# fields
@@ -2161,6 +2175,9 @@ class Find(
lst.append(bf.full_serialize())
return lst
+ def m2m_listing_datings(self) -> list:
+ return [dating.full_serialize() for dating in self.datings.all()]
+
DOC_VALUES = [
("base_finds", _("List of associated base finds")),
("material_types_label", _("Material types string")),
@@ -2209,7 +2226,8 @@ class Find(
q = q.exclude(**{k: v})
for recommendation in q.values_list(
- "parent__" * level + "recommendation", flat=True):
+ "parent__" * level + "recommendation", flat=True
+ ):
recommendations.add(recommendation)
return ", ".join(sorted(recommendations))
@@ -2225,8 +2243,9 @@ class Find(
if not filtr or prefix + "material_types_code" in filtr:
values[prefix + "material_types_code"] = self.get_material_types_code()
if not filtr or prefix + "material_types_recommendations" in filtr:
- values[prefix + "material_types_recommendations"] = \
- self.get_material_types_recommendations()
+ values[
+ prefix + "material_types_recommendations"
+ ] = self.get_material_types_recommendations()
if no_base_finds:
return values
# by default attach first basefind data
@@ -2337,6 +2356,22 @@ class Find(
return "{}-{}".format(bf.context_record.operation.get_reference(), self.index)
@property
+ def integrities_count(self):
+ return self.integrities.count()
+
+ @property
+ def remarkabilities_count(self):
+ return self.remarkabilities.count()
+
+ @property
+ def cultural_attributions_count(self):
+ return self.cultural_attributions.count()
+
+ @property
+ def documents_count(self):
+ return self.documents.count()
+
+ @property
def operation(self):
bf = self.get_first_base_find()
if not bf or not bf.context_record or not bf.context_record.operation:
diff --git a/archaeological_finds/templates/ishtar/sheet_basefind.html b/archaeological_finds/templates/ishtar/sheet_basefind.html
index c57e0d681..0b56727ca 100644
--- a/archaeological_finds/templates/ishtar/sheet_basefind.html
+++ b/archaeological_finds/templates/ishtar/sheet_basefind.html
@@ -16,8 +16,8 @@
<div class='row'>
{% field_flex_detail "Operation" base_find.context_record.operation first %}
{% field_flex_detail "Archaeological site" base_find.context_record.archaeological_site first %}
- {% field_flex_detail "Context record" base_find.context_record first %}
- {% field_flex "Town" base_find.context_record.town.label_with_areas '' '' first %}
+ {% field_flex_detail "Context record" base_find.context_record.short_label first %}
+ {% field_flex "Town" base_find.context_record.town_label_with_areas '' '' first %}
{% field_flex "Parcel" base_find.context_record.parcel '' '' first %}
{# START discovery dates #}
@@ -48,6 +48,7 @@
{% with item=base_find %}
{% include "ishtar/blocks/sheet_json.html" %}
{% endwith %}
+ {% if not is_external %}
<h3>{% trans "Sheet"%}</h3>
<div class='row'>
{% with item.history_creation_date|date:"SHORT_DATETIME_FORMAT" as creation_date %}
@@ -62,6 +63,7 @@
{% endwith %}{% endwith %}
{% endif %}
</div>
+ {% endif %}
{% if base_find.point_2d or base_find.x or base_find.y or base_find.topographic_localisation %}
{% if base_find.point_2d %}
diff --git a/archaeological_finds/templates/ishtar/sheet_find.html b/archaeological_finds/templates/ishtar/sheet_find.html
index dd9c2e059..5b6c38112 100644
--- a/archaeological_finds/templates/ishtar/sheet_find.html
+++ b/archaeological_finds/templates/ishtar/sheet_find.html
@@ -11,7 +11,7 @@
{% if item.downstream_treatment %}
<div class="alert alert-warning" role="alert">
- {% trans "This sheet has a downstream treatment: it is related to an old version of the find." %}</p>
+ {% trans "This sheet has a downstream treatment: it is related to an old version of the find." %}
</div>
{% endif %}
@@ -19,14 +19,13 @@
{% with permission_view_document=permission_view_document %}
{% with permission_view_own_document=permission_view_own_document %}
-{% with m2m_listing_datings=item|m2m_listing:'datings' %}
{% with non_modif_treatments_count=item.non_modif_treatments_count %}
{% with associated_treatment_files_count=item.associated_treatment_files_count %}
-{% with display_datings=item.integrities.count|or_:item.remarkabilities.count|or_:item.conservatory_state|or_:item.conservatory_comment|or_:item.alterations.count|or_:item.alteration_causes.count|or_:item.preservation_to_considers.count|or_:item.appraisal_date|or_:item.treatment_emergency|or_:item.insurance_value|or_:item.estimated_value|or_:m2m_listing_datings|or_:item.dating_comment|or_:item.cultural_attributions.count %}
+{% with display_datings=item.integrities.count|or_:item.remarkabilities.count|or_:item.conservatory_state|or_:item.conservatory_comment|or_:item.alterations.count|or_:item.alteration_causes.count|or_:item.preservation_to_considers.count|or_:item.appraisal_date|or_:item.treatment_emergency|or_:item.insurance_value|or_:item.estimated_value|or_:item.m2m_listing_datings|or_:item.dating_comment|or_:item.cultural_attributions.count %}
{% 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 display_documents=can_view_documents|and_:item.documents_count %}
{% if output != "ODT" and output != "PDF"%}
<ul class="nav nav-tabs" id="{{window_id}}-tabs" role="tablist">
@@ -87,7 +86,7 @@
<div class="tab-pane fade show active" id="{{window_id}}-basefind"
role="tabpanel" aria-labelledby="{{window_id}}-basefind-tab">
- {% with has_image=item.images.count %}
+ {% with has_image=item.images_number %}
{% if has_image %}
<div class="clearfix">
<div class="card float-left col-12 col-md-6 col-lg-4">
@@ -120,11 +119,19 @@
</ul>
<div class="tab-content">
+ {% if is_external %}
+ {% for base_find in item.base_finds_list %}
+ {% with first=forloop.first|add:has_image %}
+ {% include "ishtar/sheet_basefind.html" %}
+ {% endwith %}
+ {% endfor %}
+ {% else %}
{% for base_find in item.base_finds.all %}
{% with first=forloop.first|add:has_image %}
{% include "ishtar/sheet_basefind.html" %}
{% endwith %}
{% endfor %}
+ {% endif %}
</div>
{% if has_image %}
</div>
@@ -206,7 +213,7 @@
{% if display_datings %}
<div class="tab-pane fade" id="{{window_id}}-preservation"
role="tabpanel" aria-labelledby="{{window_id}}-preservation-tab">
- {% if item.integrities.count or item.remarkabilities.count or item.conservatory_state or item.conservatory_comment or item.alterations.count or item.alteration_causes.count or item.preservation_to_considers.count or item.appraisal_date or item.treatment_emergency or item.insurance_value or item.estimated_value %}
+ {% if item.integrities_count or item.remarkabilities_count or item.conservatory_state or item.conservatory_comment or item.alterations.count or item.alteration_causes.count or item.preservation_to_considers.count or item.appraisal_date or item.treatment_emergency or item.insurance_value or item.estimated_value %}
<h3>{% trans "Preservation" %}</h3>
<div class='row'>
{% field_flex_multiple_obj "Integrity / interest" item 'integrities' %}
@@ -223,9 +230,9 @@
</div>
{% endif %}
- {% if m2m_listing_datings or item.dating_comment or item.cultural_attributions.count %}
+ {% if item.m2m_listing_datings or item.dating_comment or item.cultural_attributions_count %}
<h3>{% trans "Dating" %}</h3>
- {% if item.cultural_attributions.count %}
+ {% if item.cultural_attributions_count %}
<div class='row'>
{% field_flex_multiple_obj "Cultural attributions" item 'cultural_attributions' %}
</div>
@@ -239,7 +246,7 @@
<th>{% trans "Quality" %}</th>
<th>{% trans "Precise dating" %}</th>
</tr>
- {% for dating in m2m_listing_datings %}
+ {% for dating in item.m2m_listing_datings %}
<tr>
<td>
{{dating.period}}
@@ -285,6 +292,7 @@
<dd>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
+ {% if not is_external %}
{% for loca in item.container_ref.get_localisations %}
<li class="breadcrumb-item">
{{loca.short_label}}&nbsp;{{loca|simple_link_to_window}}
@@ -293,6 +301,9 @@
<li class="breadcrumb-item">
{{item.container_ref.short_label}}&nbsp;{{item.container_ref|simple_link_to_window}}
</li>
+ {% else %}
+ {{item.container_ref}}
+ {% endif %}
</ol>
</nav>
</dd>
@@ -309,6 +320,7 @@
<dd>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
+ {% if not is_external %}
{% for loca in item.container.get_localisations %}
<li class="breadcrumb-item">
{{loca.short_label}}&nbsp;{{loca|simple_link_to_window}}
@@ -317,6 +329,16 @@
<li class="breadcrumb-item">
{{item.container.short_label}}&nbsp;{{item.container|simple_link_to_window}}
</li>
+ {% else %}
+ {% for loca in item.container.localisation_list %}
+ <li class="breadcrumb-item">
+ {{loca}}
+ </li>
+ {% endfor %}
+ <li class="breadcrumb-item">
+ {{item.container.short_label}}
+ </li>
+ {% endif %}
</ol>
</nav>
</dd>
@@ -490,7 +512,12 @@
<div class="tab-pane fade" id="{{window_id}}-documents"
role="tabpanel" aria-labelledby="{{window_id}}-documents-tab">
{% trans "Associated documents" as finds_docs %}
+ {% if item.documents.count %}
{% dynamic_table_document finds_docs 'documents' 'finds' item.pk '' output %}
+ {% elif item.documents_list %}
+ <h3>{{finds_docs}}</h3>
+ {% include "ishtar/blocks/api_document_list.html" %}
+ {% endif %}
</div>
{% endif %}
{% if item.data and item.data|length > 0 %}
@@ -501,7 +528,7 @@
{% endif %}
</div>
-{% 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 811997515..d24bb20fe 100644
--- a/archaeological_operations/templates/ishtar/sheet_operation.html
+++ b/archaeological_operations/templates/ishtar/sheet_operation.html
@@ -352,19 +352,7 @@
{% 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>
+ {% include "ishtar/blocks/api_document_list.html" %}
{% endif %}
</div>
{% endif %}
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py
index 2ea825406..8494b5bdc 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -1016,6 +1016,10 @@ class Container(
QUICK_ACTIONS = [QA_EDIT, QA_LOCK]
BASE_QUERY_LOCATION = "container_tree_child__container_parent"
+ SERIALIZE_CALL = {
+ "localisation_list": "localisation_list",
+ }
+ SERIALIZE_PROPERTIES = MainItem.SERIALIZE_PROPERTIES + ["short_label"]
objects = UUIDModelManager()
@@ -1430,6 +1434,9 @@ class Container(
localisations.append(self.location)
return reversed(localisations)
+ def localisation_list(self):
+ return [l.short_label for l in self.get_localisations()]
+
def get_localisation(self, place):
locas = list(self.get_localisations())
if len(locas) < (place + 1):
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index e72fd2a22..c1a53213f 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -3923,7 +3923,7 @@ class Document(
),
]
SERIALIZATION_FILES = ["image", "thumbnail", "associated_file"]
- SERIALIZE_PROPERTIES = ["external_id"]
+ SERIALIZE_PROPERTIES = ["external_id", "images_number"]
title = models.TextField(_("Title"), blank=True, default="")
associated_file = models.FileField(
@@ -4325,6 +4325,10 @@ class Document(
)
@property
+ def images_number(self):
+ return self.images.count()
+
+ @property
def main_image(self):
if self.images.count():
return self.images.all()[0]
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py
index bf1d10b5a..0d8eeac54 100644
--- a/ishtar_common/models_common.py
+++ b/ishtar_common/models_common.py
@@ -2566,6 +2566,10 @@ class DocumentItem:
)
@property
+ def images_number(self):
+ return self.images.count()
+
+ @property
def images_without_main_image(self):
if not hasattr(self, "main_image") or not hasattr(self, "documents"):
return self.images
@@ -3251,7 +3255,8 @@ class ShortMenuItem:
class SerializeItem:
SERIALIZE_EXCLUDE = ["search_vector"]
- SERIALIZE_PROPERTIES = ["external_id", "multi_polygon_geojson", "point_2d_geojson"]
+ SERIALIZE_PROPERTIES = ["external_id", "multi_polygon_geojson", "point_2d_geojson",
+ "images_number", "json_sections"]
SERIALIZE_CALL = {}
SERIALIZE_DATES = []
SERIALIZATION_FILES = []
@@ -3279,7 +3284,7 @@ class SerializeItem:
and hasattr(value, "full_serialize")
and not recursion
):
- # print(field.name)
+ #print(field.name, self.__class__, self)
value = value.full_serialize(recursion=True)
elif field_name in self.SERIALIZATION_FILES:
try:
@@ -3300,7 +3305,7 @@ class SerializeItem:
and hasattr(first_value, "full_serialize")
and not recursion
):
- # print(field.name)
+ #print(field.name, self.__class__, self)
values = [
v.full_serialize(recursion=True) for v in values.all()
]
@@ -3309,7 +3314,7 @@ class SerializeItem:
values = []
for v in values:
try:
- values.append({"url": value.url})
+ values.append({"url": v.url})
except ValueError:
pass
else:
@@ -3330,8 +3335,6 @@ class SerializeItem:
result = json.loads(serialize("json", [self], fields=serialize_fields))
full_result.update(result[0]["fields"])
- if "main_image" in full_result:
- print(full_result["main_image"])
for prop in self.SERIALIZE_PROPERTIES:
if hasattr(self, prop) and prop not in full_result:
full_result[prop] = getattr(self, prop)
diff --git a/ishtar_common/templates/ishtar/blocks/api_document_list.html b/ishtar_common/templates/ishtar/blocks/api_document_list.html
new file mode 100644
index 000000000..251885a19
--- /dev/null
+++ b/ishtar_common/templates/ishtar/blocks/api_document_list.html
@@ -0,0 +1,13 @@
+<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>
diff --git a/ishtar_common/templates/ishtar/blocks/sheet_creation_section.html b/ishtar_common/templates/ishtar/blocks/sheet_creation_section.html
index a848dad5d..46856cad0 100644
--- a/ishtar_common/templates/ishtar/blocks/sheet_creation_section.html
+++ b/ishtar_common/templates/ishtar/blocks/sheet_creation_section.html
@@ -1,4 +1,5 @@
{% load i18n link_to_window %}
+{% if not is_external %}
{% if item.history_creator.ishtaruser.person %}
<div class="col-12 col-md-6 col-lg-3 flex-wrap text-muted"
title="{% trans 'Creation' context 'Sheet' %}">
@@ -17,3 +18,4 @@
<small>{% firstof item.history_date|date:"DATETIME_FORMAT" item.history.all.0.history_date|date:"DATETIME_FORMAT" %}</small>
</div>
{% endif %}
+{% endif %}
diff --git a/ishtar_common/templates/ishtar/blocks/window_image.html b/ishtar_common/templates/ishtar/blocks/window_image.html
index 8f0c0dbed..409ad25fa 100644
--- a/ishtar_common/templates/ishtar/blocks/window_image.html
+++ b/ishtar_common/templates/ishtar/blocks/window_image.html
@@ -1,4 +1,4 @@
-{% load i18n link_to_window %}{% if item.images.count %}
+{% load i18n link_to_window %}{% if item.images_number %}
{% if output == "ODT" or output == "PDF"%}
{% include "ishtar/blocks/window_image_odt.html" %}
{% else %}