diff --git a/CHANGES.rst b/CHANGES.rst index 58502195..961ec4d1 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,10 @@ Changelog 6.2.8 (unreleased) ------------------ -- Nothing changed yet. +- Add start metadata to event summary serialization; + useful when create event with children event: in items list we + have subevents with missing start date + [lucabel] 6.2.7 (2024-04-22) diff --git a/src/design/plone/contenttypes/restapi/serializers/summary.py b/src/design/plone/contenttypes/restapi/serializers/summary.py index 92c31bb3..5e5d98d0 100644 --- a/src/design/plone/contenttypes/restapi/serializers/summary.py +++ b/src/design/plone/contenttypes/restapi/serializers/summary.py @@ -158,6 +158,8 @@ def __call__(self, force_all_metadata=False, force_images=False): res["tipologia_bando"] = getattr(self.context, "tipologia_bando", "") if "bando_state" in metadata_fields or self.show_all_metadata_fields: res["bando_state"] = self.get_bando_state() + if self.context.portal_type == "Event": + res["start"] = json_compatible(self.context.start) if "geolocation" in metadata_fields or self.show_all_metadata_fields: # backward compatibility for some block templates diff --git a/src/design/plone/contenttypes/tests/test_summary_serializer.py b/src/design/plone/contenttypes/tests/test_summary_serializer.py index 00836c73..66696a83 100644 --- a/src/design/plone/contenttypes/tests/test_summary_serializer.py +++ b/src/design/plone/contenttypes/tests/test_summary_serializer.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from datetime import datetime from design.plone.contenttypes.testing import ( DESIGN_PLONE_CONTENTTYPES_API_FUNCTIONAL_TESTING, ) @@ -329,3 +330,23 @@ def test_bando_summary_return_tipologia_bando(self): self.assertEqual(len(items), 1) self.assertNotIn("tipologia_bando", bando.tipologia_bando) + + def test_event_summary(self): + event1 = api.content.create( + container=self.portal, + type="Event", + title="Evento1", + start=datetime(2024, 4, 22, 12, 0), + end=datetime(2024, 5, 22, 13, 0), + ) + api.content.create( + container=event1, + type="Event", + title="Evento2", + start=datetime(2024, 4, 23, 12, 0), + end=datetime(2024, 4, 23, 13, 0), + ) + commit() + resp = self.api_session.get(event1.absolute_url()).json() + subevent = [x for x in resp["items"] if x["@type"] == "Event"][0] + self.assertIn("start", subevent)