Skip to content

Commit

Permalink
Add the contact info to @bookable-uo-list response
Browse files Browse the repository at this point in the history
  • Loading branch information
folix-01 committed Oct 11, 2023
1 parent d08aaf6 commit 2533df2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions src/design/plone/ioprenoto/restapi/services/bookable_list/get.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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

0 comments on commit 2533df2

Please sign in to comment.