Skip to content

Commit

Permalink
add contatti to pdc summary serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed Aug 27, 2024
1 parent 87aa40d commit d6d3938
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/iosanita/contenttypes/restapi/serializers/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<adapter factory=".news.NewsItemSerializeToJson" />
<adapter factory=".summary.IOSanitaJSONSummarySerializer" />
<adapter factory=".summary.PuntoDiContattoJSONSummarySerializer" />


<!-- Summary Serializer Metadata -->
<utility
Expand Down
12 changes: 12 additions & 0 deletions src/iosanita/contenttypes/restapi/serializers/summary.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collective.taxonomy import PATH_SEPARATOR
from iosanita.contenttypes.indexers.taxonomies import get_taxonomy_vocab
from iosanita.contenttypes.interfaces import IIosanitaContenttypesLayer
from iosanita.contenttypes.interfaces.punto_di_contatto import IPuntoDiContatto
from plone.restapi.interfaces import IJSONSummarySerializerMetadata
from plone.restapi.interfaces import ISerializeToJsonSummary
from redturtle.volto.restapi.serializer.summary import DefaultJSONSummarySerializer
Expand Down Expand Up @@ -81,3 +82,14 @@ def has_children(self):
except AttributeError:
return False
return False


@implementer(ISerializeToJsonSummary)
@adapter(IPuntoDiContatto, IIosanitaContenttypesLayer)
class PuntoDiContattoJSONSummarySerializer(IOSanitaJSONSummarySerializer):
def __call__(self):
data = super().__call__()

data["contatti"] = getattr(self.context, "contatti", [])

return data
17 changes: 17 additions & 0 deletions src/iosanita/contenttypes/tests/test_serializer_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
from plone.app.testing import SITE_OWNER_NAME
from plone.app.testing import SITE_OWNER_PASSWORD
from plone.app.testing import TEST_USER_ID
from plone.restapi.interfaces import ISerializeToJsonSummary
from plone.restapi.testing import RelativeSession
from transaction import commit
from zope.component import getMultiAdapter

import unittest

Expand Down Expand Up @@ -205,3 +207,18 @@ def test_summary_serializer_does_not_return_has_children_info_in_POST_calls(self

self.assertEqual(len(resp["items"]), 1)
self.assertNotIn("has_children", resp["items"][0])

def test_pdc_summary_returns_also_contatti_data(self):
contatti = [{"descrizione": "xxx", "tipo": "email", "valore": "[email protected]"}]

pdc = api.content.create(
container=self.portal,
type="PuntoDiContatto",
title="pdc",
contatti=contatti,
)

serializer = getMultiAdapter((pdc, self.request), ISerializeToJsonSummary)()

self.assertIn("contatti", serializer)
self.assertEqual(serializer["contatti"], contatti)

0 comments on commit d6d3938

Please sign in to comment.