From c641fca2bc2bd5c6892b4105325dee99e9da35d6 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 18 May 2022 16:24:26 +0200 Subject: Syndication - serialization - display sheet find - 2 --- ishtar_common/models.py | 6 +++++- ishtar_common/models_common.py | 15 +++++++++------ .../templates/ishtar/blocks/api_document_list.html | 13 +++++++++++++ .../templates/ishtar/blocks/sheet_creation_section.html | 2 ++ ishtar_common/templates/ishtar/blocks/window_image.html | 2 +- 5 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 ishtar_common/templates/ishtar/blocks/api_document_list.html (limited to 'ishtar_common') 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( @@ -4324,6 +4324,10 @@ class Document( image="" ) + @property + def images_number(self): + return self.images.count() + @property def main_image(self): if self.images.count(): 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 @@ -2565,6 +2565,10 @@ class DocumentItem: self.documents.filter(image__isnull=False).exclude(image="").order_by("pk") ) + @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"): @@ -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 @@ + + {% for values in item.documents_list %}{% if not forloop.counter0 %} + + {% for value in values %}{% endfor %} + + {% else %} + + {% for value in values %}{% endfor %} + + {% endif %} + {% endfor %} +
{{value}}
{{value}}
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 %}
@@ -17,3 +18,4 @@ {% firstof item.history_date|date:"DATETIME_FORMAT" item.history.all.0.history_date|date:"DATETIME_FORMAT" %}
{% 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 %} -- cgit v1.2.3