Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the contact info to @bookable-uo-list response #27

Merged
merged 4 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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", []):
folix-01 marked this conversation as resolved.
Show resolved Hide resolved
if contact.isBroken():
logger.error(
folix-01 marked this conversation as resolved.
Show resolved Hide resolved
"Broken relation found in <{UID}>.contact_info".format(UID=uo.UID())
)
continue

result.append(
getMultiAdapter(
(contact.to_object, self.request), ISerializeToJsonSummary
)()
)

return result
Loading