diff --git a/CHANGES.rst b/CHANGES.rst index 1985f38..3d4ae07 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,7 @@ Changelog ------------------ - Compatibilize with the 2.0.1 redturtle.prenotazioni version. +- Add the UO.contact_info field to @bookable-uo-list response. [folix-01] diff --git a/src/design/plone/ioprenoto/restapi/services/bookable_list/get.py b/src/design/plone/ioprenoto/restapi/services/bookable_list/get.py index 81f611e..2ef54da 100644 --- a/src/design/plone/ioprenoto/restapi/services/bookable_list/get.py +++ b/src/design/plone/ioprenoto/restapi/services/bookable_list/get.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from urllib.parse import urlencode +from logging import getLogger from plone import api from plone.restapi.interfaces import ISerializeToJsonSummary @@ -9,6 +10,8 @@ from zope.intid.interfaces import IIntIds from plone.restapi.serializer.converters import json_compatible +logger = getLogger(__name__) + class BookableList(Service): def reply(self): @@ -152,7 +155,26 @@ def reply(self): "title": uo.Title(), "id": uo.getId(), "uid": uo.UID(), + "contact_info": self.get_uo_contact_info(uo), "prenotazioni_folder": folders, } ) return response + + def get_uo_contact_info(self, uo): + result = [] + + for contact in getattr(uo, "contact_info", None) or []: + if contact.isBroken(): + logger.warning( + "Broken relation found in <{UID}>.contact_info".format(UID=uo.UID()) + ) + continue + + result.append( + getMultiAdapter( + (contact.to_object, self.request), ISerializeToJsonSummary + )() + ) + + return result