Skip to content

Commit b507026

Browse files
committed
add extra data method to scadenziario-day
1 parent a322d4e commit b507026

2 files changed

Lines changed: 33 additions & 21 deletions

File tree

CHANGES.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ Changelog
44
6.3.17 (unreleased)
55
-------------------
66

7-
- Nothing changed yet.
7+
- Add a ``_get_extra_event_data`` hook to ``ScadenziarioDayPost`` so that
8+
downstream packages can add extra fields to ``@scadenziario-day`` event
9+
results without duplicating the whole endpoint.
10+
[fedevancin]
811

912

1013
6.3.16 (2026-04-07)

src/design/plone/contenttypes/restapi/services/scadenziario/post.py

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,17 @@ def reply(self):
203203

204204

205205
class ScadenziarioDayPost(BaseService):
206+
def _get_extra_event_data(self, event_obj):
207+
"""Hook for subclasses to contribute extra fields to an event's
208+
result item.
209+
210+
:param event_obj: the underlying Event object for the result item
211+
(already resolved from brain.context, or from its parent for an
212+
Occurrence).
213+
:returns: a dict merged into the item returned to the client.
214+
"""
215+
return {}
216+
206217
def reply(self):
207218
data = json_body(self.request)
208219
query = data.get("query", None)
@@ -283,30 +294,28 @@ def reply(self):
283294
for brain in brains_grouped[key]:
284295
if isinstance(brain, (EventAccessor, EventOccurrenceAccessor)):
285296
if brain.context.portal_type == "Occurrence":
297+
event_obj = brain.context.aq_parent
286298
url = brain.url[:-10]
287-
scales = queryMultiAdapter(
288-
(brain.context.aq_parent, self.request), IImageScalesAdapter
289-
)
290-
image_scales = scales()
291299
else:
300+
event_obj = brain.context
292301
url = brain.url
293-
scales = queryMultiAdapter(
294-
(brain.context, self.request), IImageScalesAdapter
295-
)
296-
image_scales = scales()
297-
298-
results_to_be_returned[key].append(
299-
{
300-
"@id": url,
301-
"id": brain.id,
302-
"title": brain.title,
303-
"text": brain.description,
304-
"start": brain.start.isoformat(),
305-
"type": self.context.translate("Event"),
306-
"category": brain.subjects,
307-
"image_scales": image_scales,
308-
}
302+
scales = queryMultiAdapter(
303+
(event_obj, self.request), IImageScalesAdapter
309304
)
305+
image_scales = scales()
306+
307+
item = {
308+
"@id": url,
309+
"id": brain.id,
310+
"title": brain.title,
311+
"text": brain.description,
312+
"start": brain.start.isoformat(),
313+
"type": self.context.translate("Event"),
314+
"category": brain.subjects,
315+
"image_scales": image_scales,
316+
}
317+
item.update(self._get_extra_event_data(event_obj))
318+
results_to_be_returned[key].append(item)
310319

311320
else:
312321
results_to_be_returned[key].append(

0 commit comments

Comments
 (0)