Skip to content

Commit

Permalink
WEB-4052 : If all values in schedule are "" then we set "table_date" …
Browse files Browse the repository at this point in the history
…to None
  • Loading branch information
boulch committed Jan 17, 2024
1 parent 90f9b0b commit eaffb0b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Changelog
1.2.4 (unreleased)
------------------

- Nothing changed yet.
- WEB-4052 : If all values in schedule are "" then we set "table_date" to None
[boulch]


1.2.3 (2024-01-09)
Expand Down
51 changes: 31 additions & 20 deletions src/imio/directory/core/contents/contact/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,37 @@ def __call__(self, version=None, include_items=True):
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

schedule = result["schedule"]
all_values_empty = all(
value == ""
for day_values in schedule.values()
for value in day_values.values()
)

if all_values_empty is False:
result["table_date"] = None
table_date = []
week_days = contact_prop.get_week_days()
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
else:
result["table_date"] = None

if lang and lang != "fr":
result["title"] = getattr(obj, f"title_{lang}")
Expand Down

0 comments on commit eaffb0b

Please sign in to comment.