diff --git a/CHANGES.rst b/CHANGES.rst index 137bdca..da21913 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) @@ -143,7 +144,6 @@ Changelog - Max search limit became configurable by env var 'REDTURTLE_VOLTO_MAX_LIMIT_SEARCH', 500 by default. [folix-01] - 5.2.2 (2023-08-29) ------------------ diff --git a/src/redturtle/volto/restapi/serializer/summary.py b/src/redturtle/volto/restapi/serializer/summary.py index f1b49bb..83e70c1 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, @@ -45,32 +44,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 +78,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 55e0ec1..535056a 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, diff --git a/test_plone52.cfg b/test_plone52.cfg index 146d479..f694655 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 = >=9.6.0 +plone.restapi = 9.6.0 plone.volto = 4.0.0 pycountry = 19.8.18 collective.purgebyid = 1.1.1