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

Add date to events in items #258

Merged
merged 2 commits into from
Apr 22, 2024
Merged
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
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/design/plone/contenttypes/restapi/serializers/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions src/design/plone/contenttypes/tests/test_summary_serializer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from datetime import datetime
from design.plone.contenttypes.testing import (
DESIGN_PLONE_CONTENTTYPES_API_FUNCTIONAL_TESTING,
)
Expand Down Expand Up @@ -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)
Loading