templatetags: manage 24h/24 slots (#48929)
This commit is contained in:
parent
3721cc8faa
commit
d9f2edd994
|
@ -107,7 +107,8 @@ def get_slot(day_number, time_table, base_datetime):
|
||||||
|
|
||||||
# hours may belongs on next day
|
# hours may belongs on next day
|
||||||
end_day_number = day_number
|
end_day_number = day_number
|
||||||
if end_hour < start_hour or end_hour == start_hour and end_minute < start_minute:
|
if (end_hour < start_hour or end_hour == start_hour and end_minute < start_minute
|
||||||
|
or end_hour == start_hour == 0 and end_minute == start_minute == 0): # 24h/24
|
||||||
end_day_number += 1
|
end_day_number += 1
|
||||||
end = openinghours_to_datetime(end_day_number, end_hour, end_minute, base_datetime)
|
end = openinghours_to_datetime(end_day_number, end_hour, end_minute, base_datetime)
|
||||||
|
|
||||||
|
@ -269,7 +270,6 @@ def get_slots_from_mairie_format(data, base_datetime):
|
||||||
for weekday in days_list:
|
for weekday in days_list:
|
||||||
day_number = EN_ABBREV_WEEKDAYS_LIST.index(weekday)
|
day_number = EN_ABBREV_WEEKDAYS_LIST.index(weekday)
|
||||||
timeslot = get_slot(day_number, time_table, base_datetime)
|
timeslot = get_slot(day_number, time_table, base_datetime)
|
||||||
|
|
||||||
# add to slots the opening hours in chronological order beginning from today
|
# add to slots the opening hours in chronological order beginning from today
|
||||||
slots.append(timeslot)
|
slots.append(timeslot)
|
||||||
|
|
||||||
|
@ -409,15 +409,21 @@ def as_opening_hours_badge(data):
|
||||||
day_label = u'demain'
|
day_label = u'demain'
|
||||||
else:
|
else:
|
||||||
day_label = FR_WEEKDAYS[slots[0].start.weekday()]
|
day_label = FR_WEEKDAYS[slots[0].start.weekday()]
|
||||||
time = format_time(slots[0].start.hour, slots[0].start.minute)
|
if slots[0].start.strftime("%H:%M") == slots[0].end.strftime("%H:%M") == '00:00':
|
||||||
label = u'%s %s à %s' % (verb, day_label, time)
|
label = u'%s %s 24h/24' % (verb, day_label)
|
||||||
|
else:
|
||||||
|
time = format_time(slots[0].start.hour, slots[0].start.minute)
|
||||||
|
label = u'%s %s à %s' % (verb, day_label, time)
|
||||||
elif base_datetime < slots[0].end:
|
elif base_datetime < slots[0].end:
|
||||||
if (slots[0].end - base_datetime).seconds < 3600:
|
if (slots[0].end - base_datetime).seconds < 3600:
|
||||||
klass = 'soon-to-be-closed'
|
klass = 'soon-to-be-closed'
|
||||||
else:
|
else:
|
||||||
klass = 'open'
|
klass = 'open'
|
||||||
time = format_time(slots[0].end.hour, slots[0].end.minute)
|
if slots[0].start.strftime("%H:%M") == slots[0].end.strftime("%H:%M") == '00:00':
|
||||||
label = u"Ouvert jusqu'à %s" % time
|
label = u"Ouvert 24h/24"
|
||||||
|
else:
|
||||||
|
time = format_time(slots[0].end.hour, slots[0].end.minute)
|
||||||
|
label = u"Ouvert jusqu'à %s" % time
|
||||||
|
|
||||||
return mark_safe(u'<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
return mark_safe(u'<div class="badge %s"><span>%s</span></div>' % (klass, label))
|
||||||
|
|
||||||
|
|
|
@ -170,6 +170,7 @@ def test_mairie_holiday():
|
||||||
@pytest.mark.freeze_time("2018-03-05 00:30:00")
|
@pytest.mark.freeze_time("2018-03-05 00:30:00")
|
||||||
@pytest.mark.parametrize('day, hours, badge, text', [
|
@pytest.mark.parametrize('day, hours, badge, text', [
|
||||||
('mercredi_pm', '14h30-17h45', 'closed', 'Réouvre mercredi à 14h30'),
|
('mercredi_pm', '14h30-17h45', 'closed', 'Réouvre mercredi à 14h30'),
|
||||||
|
('mercredi_pm', '00h00-24h00', 'closed', 'Réouvre mercredi 24h/24'),
|
||||||
('mardi_pm', '14h30-17h45', 'closed', 'Réouvre demain à 14h30'),
|
('mardi_pm', '14h30-17h45', 'closed', 'Réouvre demain à 14h30'),
|
||||||
('mardi_pm', '14h30-00h15', 'closed', 'Réouvre demain à 14h30'),
|
('mardi_pm', '14h30-00h15', 'closed', 'Réouvre demain à 14h30'),
|
||||||
('lundi_pm', '14h30-17h45', 'closed', 'Réouvre à 14h30'),
|
('lundi_pm', '14h30-17h45', 'closed', 'Réouvre à 14h30'),
|
||||||
|
@ -177,6 +178,7 @@ def test_mairie_holiday():
|
||||||
('lundi_am', '00h00-00h45', 'soon-to-be-closed', "Ouvert jusqu'à 0h45"),
|
('lundi_am', '00h00-00h45', 'soon-to-be-closed', "Ouvert jusqu'à 0h45"),
|
||||||
('dimanche_pm', '20h30-00h45', 'soon-to-be-closed', "Ouvert jusqu'à 0h45"),
|
('dimanche_pm', '20h30-00h45', 'soon-to-be-closed', "Ouvert jusqu'à 0h45"),
|
||||||
('lundi_am', '00h15-24h00', 'open', "Ouvert jusqu'à minuit"),
|
('lundi_am', '00h15-24h00', 'open', "Ouvert jusqu'à minuit"),
|
||||||
|
('lundi_am', '00h00-24h00', 'open', "Ouvert 24h/24"),
|
||||||
])
|
])
|
||||||
def test_mdr_format(day, hours, badge, text):
|
def test_mdr_format(day, hours, badge, text):
|
||||||
geojson = """
|
geojson = """
|
||||||
|
@ -193,6 +195,7 @@ def test_mdr_format(day, hours, badge, text):
|
||||||
@pytest.mark.freeze_time("2018-03-05 00:30:00")
|
@pytest.mark.freeze_time("2018-03-05 00:30:00")
|
||||||
@pytest.mark.parametrize('openinghour, badge, text', [
|
@pytest.mark.parametrize('openinghour, badge, text', [
|
||||||
('We 14:30-17:45', 'closed', 'Réouvre mercredi à 14h30'),
|
('We 14:30-17:45', 'closed', 'Réouvre mercredi à 14h30'),
|
||||||
|
('We 00:00-24:00', 'closed', 'Réouvre mercredi 24h/24'),
|
||||||
('Tu 14:30-17:45', 'closed', 'Réouvre demain à 14h30'),
|
('Tu 14:30-17:45', 'closed', 'Réouvre demain à 14h30'),
|
||||||
('Tu 14:30-00:15', 'closed', 'Réouvre demain à 14h30'),
|
('Tu 14:30-00:15', 'closed', 'Réouvre demain à 14h30'),
|
||||||
('Mo 14:30-17:45', 'closed', 'Réouvre à 14h30'),
|
('Mo 14:30-17:45', 'closed', 'Réouvre à 14h30'),
|
||||||
|
@ -200,6 +203,7 @@ def test_mdr_format(day, hours, badge, text):
|
||||||
('Mo 00:00-00:45', 'soon-to-be-closed', "Ouvert jusqu'à 0h45"),
|
('Mo 00:00-00:45', 'soon-to-be-closed', "Ouvert jusqu'à 0h45"),
|
||||||
('Su 20:30-00:45', 'soon-to-be-closed', "Ouvert jusqu'à 0h45"),
|
('Su 20:30-00:45', 'soon-to-be-closed', "Ouvert jusqu'à 0h45"),
|
||||||
('Mo 00:15-24:00', 'open', "Ouvert jusqu'à minuit"),
|
('Mo 00:15-24:00', 'open', "Ouvert jusqu'à minuit"),
|
||||||
|
('Mo 00:00-24:00', 'open', "Ouvert 24h/24"),
|
||||||
])
|
])
|
||||||
def test_mairie_format_openinghours(openinghour, badge, text):
|
def test_mairie_format_openinghours(openinghour, badge, text):
|
||||||
geojson = """
|
geojson = """
|
||||||
|
@ -216,6 +220,7 @@ def test_mairie_format_openinghours(openinghour, badge, text):
|
||||||
@pytest.mark.freeze_time("2018-03-05 00:30:00")
|
@pytest.mark.freeze_time("2018-03-05 00:30:00")
|
||||||
@pytest.mark.parametrize('day, opens, closes, badge, text', [
|
@pytest.mark.parametrize('day, opens, closes, badge, text', [
|
||||||
('Wednesday', '14:30', '17:45', 'closed', 'Réouvre mercredi à 14h30'),
|
('Wednesday', '14:30', '17:45', 'closed', 'Réouvre mercredi à 14h30'),
|
||||||
|
('Wednesday', '00:00', '24:00', 'closed', 'Réouvre mercredi 24h/24'),
|
||||||
('Tuesday', '14:30', '17:45', 'closed', 'Réouvre demain à 14h30'),
|
('Tuesday', '14:30', '17:45', 'closed', 'Réouvre demain à 14h30'),
|
||||||
('Tuesday', '14:30', '00:15', 'closed', 'Réouvre demain à 14h30'),
|
('Tuesday', '14:30', '00:15', 'closed', 'Réouvre demain à 14h30'),
|
||||||
('Monday', '14:30', '17:45', 'closed', 'Réouvre à 14h30'),
|
('Monday', '14:30', '17:45', 'closed', 'Réouvre à 14h30'),
|
||||||
|
@ -223,6 +228,7 @@ def test_mairie_format_openinghours(openinghour, badge, text):
|
||||||
('Monday', '00:00', '00:45', 'soon-to-be-closed', "Ouvert jusqu'à 0h45"),
|
('Monday', '00:00', '00:45', 'soon-to-be-closed', "Ouvert jusqu'à 0h45"),
|
||||||
('Sunday', '20:30', '00:45', 'soon-to-be-closed', "Ouvert jusqu'à 0h45"),
|
('Sunday', '20:30', '00:45', 'soon-to-be-closed', "Ouvert jusqu'à 0h45"),
|
||||||
('Monday', '00:15', '24:00', 'open', "Ouvert jusqu'à minuit"),
|
('Monday', '00:15', '24:00', 'open', "Ouvert jusqu'à minuit"),
|
||||||
|
('Monday', '00:00', '24:00', 'open', "Ouvert 24h/24"),
|
||||||
])
|
])
|
||||||
def test_mairie_format_openinghoursspecification(day, opens, closes, badge, text):
|
def test_mairie_format_openinghoursspecification(day, opens, closes, badge, text):
|
||||||
geojson = """
|
geojson = """
|
||||||
|
|
|
@ -81,7 +81,8 @@ def test_mairie_format_openinghours():
|
||||||
"We 10:30-18:30",
|
"We 10:30-18:30",
|
||||||
"Th 22:30-00:30",
|
"Th 22:30-00:30",
|
||||||
"Fr 07:30-07:00",
|
"Fr 07:30-07:00",
|
||||||
"Sa 21:00-24:00"
|
"Sa 21:00-24:00",
|
||||||
|
"Su 00:00-24:00"
|
||||||
]}}
|
]}}
|
||||||
"""
|
"""
|
||||||
hours = get_mairie_opening_hours(json.loads(geojson))
|
hours = get_mairie_opening_hours(json.loads(geojson))
|
||||||
|
@ -92,6 +93,7 @@ def test_mairie_format_openinghours():
|
||||||
('jeudi', {'am': None, 'pm': '22h30-00h30'}),
|
('jeudi', {'am': None, 'pm': '22h30-00h30'}),
|
||||||
('vendredi', {'am': '07h30-07h00', 'pm': ''}),
|
('vendredi', {'am': '07h30-07h00', 'pm': ''}),
|
||||||
('samedi', {'am': None, 'pm': '21h00-24h00'}),
|
('samedi', {'am': None, 'pm': '21h00-24h00'}),
|
||||||
|
('dimanche', {'am': '00h00-24h00', 'pm': ''}),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -137,6 +139,12 @@ def test_mairie_format_openinghoursspecification():
|
||||||
"dayOfWeek": "http:\/\/schema.org\/Saturday",
|
"dayOfWeek": "http:\/\/schema.org\/Saturday",
|
||||||
"validFrom": "2018-01-01T00:00:00+01:00",
|
"validFrom": "2018-01-01T00:00:00+01:00",
|
||||||
"validThrough": "2018-06-30T23:59:59+02:00"
|
"validThrough": "2018-06-30T23:59:59+02:00"
|
||||||
|
}, {
|
||||||
|
"opens": "00:00",
|
||||||
|
"closes": "24:00",
|
||||||
|
"dayOfWeek": "http:\/\/schema.org\/Sunday",
|
||||||
|
"validFrom": "2018-01-01T00:00:00+01:00",
|
||||||
|
"validThrough": "2018-06-30T23:59:59+02:00"
|
||||||
}]}}
|
}]}}
|
||||||
"""
|
"""
|
||||||
hours = get_mairie_opening_hours(json.loads(geojson))
|
hours = get_mairie_opening_hours(json.loads(geojson))
|
||||||
|
@ -147,4 +155,5 @@ def test_mairie_format_openinghoursspecification():
|
||||||
('jeudi', {'am': None, 'pm': '22h30-00h30'}),
|
('jeudi', {'am': None, 'pm': '22h30-00h30'}),
|
||||||
('vendredi', {'am': '07h30-07h00', 'pm': ''}),
|
('vendredi', {'am': '07h30-07h00', 'pm': ''}),
|
||||||
('samedi', {'am': None, 'pm': '21h00-24h00'}),
|
('samedi', {'am': None, 'pm': '21h00-24h00'}),
|
||||||
|
('dimanche', {'am': '00h00-24h00', 'pm': ''}),
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue