Skip to content

Commit

Permalink
image_scales in serializer are returned as json_compatible format (#1772
Browse files Browse the repository at this point in the history
)

* fix: image_scales in serializer are returned as json_compatible format

* add changelog
  • Loading branch information
cekk authored Apr 4, 2024
1 parent 5cf1418 commit 848dff0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/1772.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
image_scales in serializer are returned as json_compatible format. @cekk
4 changes: 3 additions & 1 deletion src/plone/restapi/serializer/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def _process_data(self, data, field=None):
continue
newdata[field], brain = resolve_uid(data[field])
if brain is not None and "image_scales" not in newdata:
newdata["image_scales"] = getattr(brain, "image_scales", None)
newdata["image_scales"] = json_compatible(
getattr(brain, "image_scales", None)
)
result = {
field: (
newdata[field]
Expand Down
12 changes: 12 additions & 0 deletions src/plone/restapi/tests/test_blocks_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,3 +505,15 @@ def test_image_scales_serializer(self):
)
self.assertEqual(res["123"]["url"], self.image.absolute_url())
self.assertIn("image_scales", res["123"])

@unittest.skipUnless(
HAS_PLONE_6,
"image_scales were added to the catalog in Plone 6",
)
def test_image_scales_serializer_is_json_compatible(self):
image_uid = self.image.UID()
res = self.serialize(
context=self.portal["doc1"],
blocks={"123": {"@type": "image", "url": f"../resolveuid/{image_uid}"}},
)
self.assertIs(type(res["123"]["image_scales"]), dict)

0 comments on commit 848dff0

Please sign in to comment.