Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove image customization in restapi #74

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
------------------

Expand Down
31 changes: 0 additions & 31 deletions src/redturtle/volto/restapi/serializer/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
24 changes: 0 additions & 24 deletions src/redturtle/volto/tests/test_summary_customization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test_plone52.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading