templatetags: simplify get_period_from_data (#48919)
This commit is contained in:
parent
2e0328ed29
commit
d75a455f4d
|
@ -138,15 +138,16 @@ def openinghours_to_datetime(codename, hour, minute):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_period_from_data(weekday, open_close_time_string=None, opening_time=None, closing_time=None):
|
def get_period_from_data(weekday, time_table):
|
||||||
"""Return am or pm and all_day_hours from opening_time and closing_time
|
"""Return am or pm and all_day_hours from opening_time and closing_time
|
||||||
"""
|
"""
|
||||||
if open_close_time_string is not None:
|
start_hour = int(time_table['start_hour'])
|
||||||
(start_hour, start_minute, end_hour, end_minute) = open_close_time_string
|
start_minute = int(time_table['start_minute'])
|
||||||
if closing_time is None:
|
end_hour = int(time_table['end_hour'])
|
||||||
closing_time = openinghours_to_datetime(weekday, int(end_hour), int(end_minute))
|
end_minute = int(time_table['end_minute'])
|
||||||
if opening_time is None:
|
|
||||||
opening_time = openinghours_to_datetime(weekday, int(start_hour), int(start_minute))
|
closing_time = openinghours_to_datetime(weekday, end_hour, end_minute)
|
||||||
|
opening_time = openinghours_to_datetime(weekday, start_hour, start_minute)
|
||||||
|
|
||||||
all_day_hours = False
|
all_day_hours = False
|
||||||
if (opening_time < closing_time # closing_time may last on the night
|
if (opening_time < closing_time # closing_time may last on the night
|
||||||
|
@ -329,10 +330,7 @@ def get_mairie_opening_hours(mairie_data):
|
||||||
} for i in range(7)]))
|
} for i in range(7)]))
|
||||||
|
|
||||||
def update_opening_hours(weekday, time_table):
|
def update_opening_hours(weekday, time_table):
|
||||||
period, all_day_hours = get_period_from_data(
|
period, all_day_hours = get_period_from_data(weekday, time_table)
|
||||||
weekday, open_close_time_string=(
|
|
||||||
time_table['start_hour'], time_table['start_minute'],
|
|
||||||
time_table['end_hour'], time_table['end_minute']))
|
|
||||||
if all_day_hours and period == 'am':
|
if all_day_hours and period == 'am':
|
||||||
opening_hours_dict[weekday]['pm'] = '' # empty string to avoid displaying fermé
|
opening_hours_dict[weekday]['pm'] = '' # empty string to avoid displaying fermé
|
||||||
opening_hours_dict[weekday][period] = "%sh%s-%sh%s" % (
|
opening_hours_dict[weekday][period] = "%sh%s-%sh%s" % (
|
||||||
|
|
Loading…
Reference in New Issue