templatetags: fix mdr support for timezone aware elements (#22050)
This commit is contained in:
parent
0e62a5de05
commit
97aca8279b
|
@ -97,8 +97,8 @@ def get_slots_from_mdr_format(data, today):
|
||||||
continue
|
continue
|
||||||
# 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(
|
||||||
datetime.datetime(today.year, today.month, today.day, int(parts[0]), int(parts[1])),
|
datetime.datetime(today.year, today.month, today.day, int(parts[0]), int(parts[1]), tzinfo=today.tzinfo),
|
||||||
datetime.datetime(today.year, today.month, today.day, int(parts[2]), int(parts[3]))
|
datetime.datetime(today.year, today.month, today.day, int(parts[2]), int(parts[3]), tzinfo=today.tzinfo)
|
||||||
))
|
))
|
||||||
|
|
||||||
today = today + datetime.timedelta(days=1)
|
today = today + datetime.timedelta(days=1)
|
||||||
|
@ -180,7 +180,7 @@ def as_opening_hours_badge(data, base_datetime=None):
|
||||||
exclusion_slots = []
|
exclusion_slots = []
|
||||||
today = base_datetime.date()
|
today = base_datetime.date()
|
||||||
|
|
||||||
(slots, known_format) = get_slots_from_mdr_format(data, today)
|
(slots, known_format) = get_slots_from_mdr_format(data, base_datetime)
|
||||||
if not known_format:
|
if not known_format:
|
||||||
(slots, exclusion_slots, known_format) = get_slots_from_mairie_format(data, base_datetime)
|
(slots, exclusion_slots, known_format) = get_slots_from_mairie_format(data, base_datetime)
|
||||||
|
|
||||||
|
|
|
@ -77,3 +77,19 @@ def test_all_mdr_data_parsed_correct():
|
||||||
"""everything got parsed correctly"""
|
"""everything got parsed correctly"""
|
||||||
opening_hours = [as_opening_hours_badge(x) for x in MDR_GEOJSON]
|
opening_hours = [as_opening_hours_badge(x) for x in MDR_GEOJSON]
|
||||||
assert opening_hours.count('') == 0
|
assert opening_hours.count('') == 0
|
||||||
|
|
||||||
|
def test_mdr_closing_time():
|
||||||
|
test_datetime = parse("2018-03-05T14:59:00+01:00")
|
||||||
|
test_html = [as_opening_hours_badge(x, base_datetime=test_datetime) for x in MDR_GEOJSON if x['properties']['nom'] == u'Maison de la Métropole Bramet'][0]
|
||||||
|
klass, label = 'open', u"Ouvert jusqu'à 16h45"
|
||||||
|
assert test_html == mark_safe(u'<div class="badge %s"><span>%s</span></div>'% (klass, label))
|
||||||
|
|
||||||
|
test_datetime = parse("2018-03-05T15:50:00+01:00")
|
||||||
|
test_html = [as_opening_hours_badge(x, base_datetime=test_datetime) for x in MDR_GEOJSON if x['properties']['nom'] == u'Maison de la Métropole Bramet'][0]
|
||||||
|
klass, label = 'soon-to-be-closed', u"Ouvert jusqu'à 16h45"
|
||||||
|
assert test_html == mark_safe(u'<div class="badge %s"><span>%s</span></div>'% (klass, label))
|
||||||
|
|
||||||
|
test_datetime = parse("2018-03-10T17:30:00+01:00")
|
||||||
|
test_html = [as_opening_hours_badge(x, base_datetime=test_datetime) for x in MDR_GEOJSON if x['properties']['nom'] == u'Maison de la Métropole Bramet'][0]
|
||||||
|
klass, label = 'closed', u"Réouvre lundi à 8h30"
|
||||||
|
assert test_html == mark_safe(u'<div class="badge %s"><span>%s</span></div>'% (klass, label))
|
||||||
|
|
Loading…
Reference in New Issue