From 2533df2da2e803dce9e057ffaf61c0247443b018 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 11 Oct 2023 12:12:43 +0200 Subject: [PATCH] Add the contact info to @bookable-uo-list response --- 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..285bf89 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", []): + if contact.isBroken(): + logger.error( + "Broken relation found in <{UID}>.contact_info".format(UID=uo.UID()) + ) + continue + + result.append( + getMultiAdapter( + (contact.to_object, self.request), ISerializeToJsonSummary + )() + ) + + return result