diff --git a/CHANGES.rst b/CHANGES.rst index fcd7a6a..9d859ad 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,7 +5,9 @@ Changelog 1.1.11 (unreleased) ------------------- -- Nothing changed yet. +- WEB-4007 : Update contact serializer and use ContactProperties to get well formated schedule + and help displaying schedule in REACT directory view + [boulch] 1.1.10 (2023-10-09) diff --git a/src/imio/directory/core/contents/contact/serializer.py b/src/imio/directory/core/contents/contact/serializer.py index cbc26fb..0fcc43c 100644 --- a/src/imio/directory/core/contents/contact/serializer.py +++ b/src/imio/directory/core/contents/contact/serializer.py @@ -2,6 +2,7 @@ from imio.directory.core.contents import IContact from imio.directory.core.interfaces import IImioDirectoryCoreLayer +from imio.smartweb.common.contact_utils import ContactProperties from imio.smartweb.common.rest.utils import get_restapi_query_lang from plone.app.contentlisting.interfaces import IContentListingObject from plone.restapi.interfaces import ISerializeToJson @@ -27,6 +28,33 @@ def __call__(self, version=None, include_items=True): query = self.request.form lang = get_restapi_query_lang(query) + contact_prop = ContactProperties(result) + opening_informations = contact_prop.get_opening_informations() + result["opening_informations"] = opening_informations + result["schedule_for_today"] = contact_prop.get_schedule_for_today( + opening_informations + ) + result["table_date"] = [] + week_days = contact_prop.get_week_days() + table_date = [] + day_mapping = { + "weekday_mon_short": "Monday", + "weekday_tue_short": "Tuesday", + "weekday_wed_short": "Wednesday", + "weekday_thu_short": "Thursday", + "weekday_fri_short": "Friday", + "weekday_sat_short": "Saturday", + "weekday_sun_short": "Sunday", + } + for a_date in week_days: + formatted_schedule = contact_prop.formatted_schedule( + list(a_date.values())[0] + ) + day = day_mapping.get([k for k, v in a_date.items()][0]) + dict = {day: formatted_schedule} + table_date.append(dict) + result["table_date"] = table_date + if lang and lang != "fr": result["title"] = getattr(obj, f"title_{lang}") result["subtitle"] = getattr(obj, f"subtitle_{lang}") diff --git a/src/imio/directory/core/tests/test_contact.py b/src/imio/directory/core/tests/test_contact.py index 8718c78..1b248fc 100644 --- a/src/imio/directory/core/tests/test_contact.py +++ b/src/imio/directory/core/tests/test_contact.py @@ -218,6 +218,59 @@ def test_overall_response_format(self): type="imio.directory.Contact", title="contact", ) + + contact.schedule = { + "friday": { + "afternoonend": "17:30", + "afternoonstart": "13:00", + "comment": "uniquement sur rdv", + "morningend": "12:30", + "morningstart": "09:00", + }, + "monday": { + "afternoonend": "15:15", + "afternoonstart": "13:00", + "comment": "uniquement sur rdv", + "morningend": "12:30", + "morningstart": "09:00", + }, + "saturday": { + "afternoonend": "", + "afternoonstart": "", + "comment": "", + "morningend": "", + "morningstart": "", + }, + "sunday": { + "afternoonend": "", + "afternoonstart": "", + "comment": "", + "morningend": "", + "morningstart": "", + }, + "thursday": { + "afternoonend": "18:30", + "afternoonstart": "13:00", + "comment": "uniquement sur rdv", + "morningend": "12:30", + "morningstart": "09:00", + }, + "tuesday": { + "afternoonend": "15:15", + "afternoonstart": "13:00", + "comment": "uniquement sur rdv", + "morningend": "12:30", + "morningstart": "09:00", + }, + "wednesday": { + "afternoonend": "18:30", + "afternoonstart": "13:00", + "comment": "uniquement sur rdv", + "morningend": "12:30", + "morningstart": "09:00", + }, + } + transaction.commit() response = self.api_session.get(contact.absolute_url()) self.assertEqual(response.status_code, 200) diff --git a/src/imio/directory/core/tests/test_multilingual.py b/src/imio/directory/core/tests/test_multilingual.py index c2cefb7..d2b9232 100644 --- a/src/imio/directory/core/tests/test_multilingual.py +++ b/src/imio/directory/core/tests/test_multilingual.py @@ -149,6 +149,58 @@ def test_contact_serializer(self): contact.subtitle_de = "Meine Funktion" contact.taxonomy_contact_category = ["cho96vl9ox"] + contact.schedule = { + "friday": { + "afternoonend": "17:30", + "afternoonstart": "13:00", + "comment": "uniquement sur rdv", + "morningend": "12:30", + "morningstart": "09:00", + }, + "monday": { + "afternoonend": "15:15", + "afternoonstart": "13:00", + "comment": "uniquement sur rdv", + "morningend": "12:30", + "morningstart": "09:00", + }, + "saturday": { + "afternoonend": "", + "afternoonstart": "", + "comment": "", + "morningend": "", + "morningstart": "", + }, + "sunday": { + "afternoonend": "", + "afternoonstart": "", + "comment": "", + "morningend": "", + "morningstart": "", + }, + "thursday": { + "afternoonend": "18:30", + "afternoonstart": "13:00", + "comment": "uniquement sur rdv", + "morningend": "12:30", + "morningstart": "09:00", + }, + "tuesday": { + "afternoonend": "15:15", + "afternoonstart": "13:00", + "comment": "uniquement sur rdv", + "morningend": "12:30", + "morningstart": "09:00", + }, + "wednesday": { + "afternoonend": "18:30", + "afternoonstart": "13:00", + "comment": "uniquement sur rdv", + "morningend": "12:30", + "morningstart": "09:00", + }, + } + serializer = getMultiAdapter((contact, self.request), ISerializeToJson) json = serializer() self.assertEqual(json["title"], "Mon contact")