From ce47e43fa6e9136c770952007a00b856550fe84b Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Thu, 21 Sep 2023 15:26:24 +0200 Subject: [PATCH 1/4] Remove custom image infos in summary serializer. Now use plone.restapi base feature --- CHANGES.rst | 3 +- setup.py | 2 +- .../volto/restapi/serializer/summary.py | 30 ------------------- .../volto/tests/test_summary_customization.py | 24 --------------- 4 files changed, 3 insertions(+), 56 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 57365aec..27082bd5 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,7 +6,8 @@ Changelog - Max search limit became configurable by env var 'REDTURTLE_VOLTO_MAX_LIMIT_SEARCH', 500 by default. [folix-01] - +- Remove custom image infos in summary serializer. Now use plone.restapi base feature. + [cekk] 5.2.2 (2023-08-29) ------------------ diff --git a/setup.py b/setup.py index 7a57615c..d06b33dd 100644 --- a/setup.py +++ b/setup.py @@ -59,7 +59,7 @@ "collective.purgebyid", "kitconcept.seo>=2.0.0", "plone.volto>=4.0.0", - "plone.restapi>=8.36.0", + "plone.restapi>=8.43.3", "Products.PortalTransforms>=3.2.0", ], extras_require={ diff --git a/src/redturtle/volto/restapi/serializer/summary.py b/src/redturtle/volto/restapi/serializer/summary.py index f1b49bb8..f3fb9bfd 100644 --- a/src/redturtle/volto/restapi/serializer/summary.py +++ b/src/redturtle/volto/restapi/serializer/summary.py @@ -45,32 +45,6 @@ def show_all_metadata_fields(self): metadata_fields = query.get("metadata_fields", []) return "_all" in metadata_fields or self.force_all_metadata - def get_image_scales(self, data): - """ - this is a backward compatibility for old volto templates that need - a full image scales object - """ - metadata_fields = self.metadata_fields() - - if "image" not in metadata_fields and not self.show_all_metadata_fields: - return {} - if data.get("image", None): - # it's a fullobjects data, so we already have the infos - return None - if not data.get("image_field", ""): - return None - scales = {} - - for name, actual_width, actual_height in get_scale_infos(): - scales[name] = { - "width": actual_width, - "height": actual_height, - "download": "{url}/@@images/{image_field}/{name}".format( - url=data["@id"], image_field=data["image_field"], name=name - ), - } - return scales - def get_remote_url(self): """ Resolve uid and return ref absolute url @@ -105,10 +79,6 @@ def __call__(self, force_all_metadata=False): if v in EMPTY_STRINGS and k not in ["ExpirationDate", "EffectiveDate"]: # this is a Volto compatibility data[k] = None - scales = self.get_image_scales(data) - - if scales: - data["image"] = {"scales": scales} if self.context.portal_type == "Link": remote_url = self.get_remote_url() # set twice because old templates can use both diff --git a/src/redturtle/volto/tests/test_summary_customization.py b/src/redturtle/volto/tests/test_summary_customization.py index 55e0ec1a..535056a0 100644 --- a/src/redturtle/volto/tests/test_summary_customization.py +++ b/src/redturtle/volto/tests/test_summary_customization.py @@ -54,30 +54,6 @@ def setUp(self): def tearDown(self): self.api_session.close() - def test_summary_does_not_return_image_scales_if_not_requested(self): - response = self.api_session.get("/@search", params={"portal_type": "News Item"}) - self.assertEqual(response.status_code, 200) - res = response.json() - - self.assertEqual(len(res["items"]), 2) - self.assertEqual(res["items"][0]["title"], self.news_with_image.title) - self.assertEqual(res["items"][1]["title"], self.news_without_image.title) - self.assertNotIn("image", res["items"][0]) - self.assertNotIn("image", res["items"][1]) - - def test_summary_return_image_scales_if_requested(self): - response = self.api_session.get( - "/@search?metadata_fields=_all", params={"portal_type": "News Item"} - ) - self.assertEqual(response.status_code, 200) - res = response.json() - - self.assertEqual(len(res["items"]), 2) - self.assertEqual(res["items"][0]["title"], self.news_with_image.title) - self.assertEqual(res["items"][1]["title"], self.news_without_image.title) - self.assertIn("image", res["items"][0]) - self.assertNotIn("image", res["items"][1]) - def test_summary_return_empty_effective_date_if_not_set(self): page = api.content.create( container=self.portal, From d70def3950fdf60e03e838cc507ac0b719f269e3 Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Thu, 21 Sep 2023 15:26:42 +0200 Subject: [PATCH 2/4] flake8 --- src/redturtle/volto/restapi/serializer/summary.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/redturtle/volto/restapi/serializer/summary.py b/src/redturtle/volto/restapi/serializer/summary.py index f3fb9bfd..83e70c1c 100644 --- a/src/redturtle/volto/restapi/serializer/summary.py +++ b/src/redturtle/volto/restapi/serializer/summary.py @@ -3,7 +3,6 @@ from plone.app.contenttypes.interfaces import ILink from plone.app.contenttypes.utils import replace_link_variables_by_paths from plone.restapi.deserializer import json_body -from plone.restapi.imaging import get_scale_infos from plone.restapi.interfaces import ISerializeToJsonSummary from plone.restapi.serializer.summary import ( DefaultJSONSummarySerializer as BaseSerializer, From dc8219f63439594f9d29a6c4680386979c9e15d2 Mon Sep 17 00:00:00 2001 From: Mauro Amico Date: Mon, 6 Nov 2023 15:09:31 +0100 Subject: [PATCH 3/4] ci: update p.restapi 8.43.3 --- test_plone52.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_plone52.cfg b/test_plone52.cfg index 977c6d4d..6ba6acd4 100644 --- a/test_plone52.cfg +++ b/test_plone52.cfg @@ -14,7 +14,7 @@ plone.app.versioningbehavior = 1.4.6 plone.app.vocabularies = 4.3.0 plone.patternslib = 1.1.1 plone.rest = 2.0.0 -plone.restapi = 8.42.0 +plone.restapi = 8.43.3 plone.volto = 4.0.0 pycountry = 19.8.18 collective.purgebyid = 1.1.1 From 5ce5ecbdc64642ec1e823678e1011d052f3875c1 Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Mon, 6 May 2024 10:09:50 +0200 Subject: [PATCH 4/4] fix changelog --- CHANGES.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index aa12fc6a..da21913d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,8 @@ Changelog 5.4.10 (unreleased) ------------------- -- Nothing changed yet. +- Remove custom image infos in summary serializer. Now use plone.restapi base feature. + [cekk] 5.4.9 (2024-04-22) @@ -142,8 +143,6 @@ Changelog - Max search limit became configurable by env var 'REDTURTLE_VOLTO_MAX_LIMIT_SEARCH', 500 by default. [folix-01] -- Remove custom image infos in summary serializer. Now use plone.restapi base feature. - [cekk] 5.2.2 (2023-08-29) ------------------