Skip to content

Commit

Permalink
WEB-4007 : Update contact serializer and use ContactProperties to get…
Browse files Browse the repository at this point in the history
… well formated schedule and help displaying schedule in REACT directory view
  • Loading branch information
boulch committed Jan 3, 2024
1 parent 4f5b9cf commit 4987340
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 28 additions & 0 deletions src/imio/directory/core/contents/contact/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}")
Expand Down
52 changes: 52 additions & 0 deletions src/imio/directory/core/tests/test_multilingual.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 4987340

Please sign in to comment.