From 158c27282cd504788ebc3d8cc4b2f9b0de2027f0 Mon Sep 17 00:00:00 2001 From: Roman <72063601+folix-01@users.noreply.github.com> Date: Fri, 13 Oct 2023 14:29:48 +0200 Subject: [PATCH] Add the contact info to @bookable-uo-list response (#27) * Add the contact info to @bookable-uo-list response * Update src/design/plone/ioprenoto/restapi/services/bookable_list/get.py Co-authored-by: Mauro Amico * Use python syntax * Update src/design/plone/ioprenoto/restapi/services/bookable_list/get.py Co-authored-by: Mauro Amico --------- Co-authored-by: Mauro Amico --- CHANGES.rst | 3 ++- .../restapi/services/bookable_list/get.py | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index d07fd1b..70cb09e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,8 @@ Changelog 1.1.8 (unreleased) ------------------ -- Nothing changed yet. +- Add the UO.contact_info field to @bookable-uo-list response. + [folix-01] 1.1.7 (2023-09-25) 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