Skip to content

Commit

Permalink
Add the contact info to @bookable-uo-list response (#27)
Browse files Browse the repository at this point in the history
* 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 <mauro.amico@gmail.com>

* Use python syntax

* Update src/design/plone/ioprenoto/restapi/services/bookable_list/get.py

Co-authored-by: Mauro Amico <mauro.amico@gmail.com>

---------

Co-authored-by: Mauro Amico <mauro.amico@gmail.com>
  • Loading branch information
folix-01 and mamico authored Oct 13, 2023
1 parent d08aaf6 commit 158c272
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", 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

0 comments on commit 158c272

Please sign in to comment.