From c58f3cd20aac4f89fcdb2ef28a5b1c9bc719c51f Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Thu, 25 Jan 2024 21:15:47 +0100 Subject: [PATCH 1/2] Add getObjSize info in File field serializer (#236) --- CHANGES.rst | 3 ++- .../contenttypes/restapi/serializers/dxfields.py | 11 +++++++++-- .../tests/test_filefield_view_mode_serializer.py | 5 ++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 27756c9d..4306f573 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,8 @@ Changelog 6.1.11 (unreleased) ------------------- -- Nothing changed yet. +- Add getObjSize info in File field serializer. + [cekk] 6.1.10 (2024-01-16) diff --git a/src/design/plone/contenttypes/restapi/serializers/dxfields.py b/src/design/plone/contenttypes/restapi/serializers/dxfields.py index 1cf1ab10..133351c6 100644 --- a/src/design/plone/contenttypes/restapi/serializers/dxfields.py +++ b/src/design/plone/contenttypes/restapi/serializers/dxfields.py @@ -5,6 +5,7 @@ from design.plone.contenttypes.interfaces.servizio import IServizio from plone import api from plone.app.contenttypes.utils import replace_link_variables_by_paths +from plone.base.utils import human_readable_size from plone.dexterity.interfaces import IDexterityContent from plone.namedfile.interfaces import INamedFileField from plone.outputfilters.browser.resolveuid import uuidToURL @@ -56,7 +57,11 @@ def __call__(self): @adapter(INamedFileField, IDexterityContent, IDesignPloneContenttypesLayer) class FileFieldViewModeSerializer(DefaultFieldSerializer): - """Ovveride the basic DX serializer to handle the visualize file functionality""" + """ + Ovveride the basic DX serializer to: + - handle the visualize file functionality + - add getObjSize info + """ def __call__(self): namedfile = self.field.get(self.context) @@ -70,10 +75,12 @@ def __call__(self): self.field.__name__, ) ) + size = namedfile.getSize() result = { "filename": namedfile.filename, "content-type": namedfile.contentType, - "size": namedfile.getSize(), + "size": size, + "getObjSize": human_readable_size(size), "download": url, } diff --git a/src/design/plone/contenttypes/tests/test_filefield_view_mode_serializer.py b/src/design/plone/contenttypes/tests/test_filefield_view_mode_serializer.py index c0fb9737..b1532b2d 100644 --- a/src/design/plone/contenttypes/tests/test_filefield_view_mode_serializer.py +++ b/src/design/plone/contenttypes/tests/test_filefield_view_mode_serializer.py @@ -59,5 +59,8 @@ def test_if_visualize_files_true_so_dsiplay(self): commit() response = self.api_session.get(self.modulo.absolute_url()).json() - self.assertIn("@@display-file", response["file_principale"]["download"]) + + def test_human_readable_obj_size_in_data(self): + response = self.api_session.get(self.modulo.absolute_url()).json() + self.assertEqual("1 KB", response["file_principale"]["getObjSize"]) From 60a899bb4dde370fee47b602e62d45d420b618d3 Mon Sep 17 00:00:00 2001 From: Filippo Campi Date: Fri, 26 Jan 2024 12:09:58 +0100 Subject: [PATCH 2/2] Us51048 modifie old pdc (#235) * fixed upgrade step for add desc to pdc * updated CHANGES --- CHANGES.rst | 2 ++ .../plone/contenttypes/profiles/default/metadata.xml | 2 +- src/design/plone/contenttypes/upgrades/configure.zcml | 7 ++++--- src/design/plone/contenttypes/upgrades/upgrades.py | 4 ++++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 4306f573..e0b2077f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,8 @@ Changelog 6.1.11 (unreleased) ------------------- +- Fixed script to update pdc with description + [eikichi18] - Add getObjSize info in File field serializer. [cekk] diff --git a/src/design/plone/contenttypes/profiles/default/metadata.xml b/src/design/plone/contenttypes/profiles/default/metadata.xml index bd728141..24726ddb 100644 --- a/src/design/plone/contenttypes/profiles/default/metadata.xml +++ b/src/design/plone/contenttypes/profiles/default/metadata.xml @@ -1,6 +1,6 @@ - 7021 + 7023 profile-redturtle.bandi:default profile-collective.venue:default diff --git a/src/design/plone/contenttypes/upgrades/configure.zcml b/src/design/plone/contenttypes/upgrades/configure.zcml index e8fc5e60..8e88bee8 100644 --- a/src/design/plone/contenttypes/upgrades/configure.zcml +++ b/src/design/plone/contenttypes/upgrades/configure.zcml @@ -796,12 +796,13 @@ + diff --git a/src/design/plone/contenttypes/upgrades/upgrades.py b/src/design/plone/contenttypes/upgrades/upgrades.py index 6019d520..e3837fd7 100644 --- a/src/design/plone/contenttypes/upgrades/upgrades.py +++ b/src/design/plone/contenttypes/upgrades/upgrades.py @@ -1572,4 +1572,8 @@ def update_pdc_with_pdc_desc(context): if not v.get("pdc_desc", None): v["pdc_desc"] = None logger.info(f"Set pdc_desc for {pdc.absolute_url()}") + + pdc.value_punto_contatto = value_punto_contatto + + commit() logger.info("Ends of update")