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 <[email protected]>

* Use python syntax

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

Co-authored-by: Mauro Amico <[email protected]>

---------

Co-authored-by: Mauro Amico <[email protected]>
  • Loading branch information
folix-01 and mamico committed Oct 13, 2023
1 parent e2ceb8c commit ea11622
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]


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 ea11622

Please sign in to comment.