manager: support full day opening in partial bookings agenda (#79171)
gitea/chrono/pipeline/head This commit looks good Details

This commit is contained in:
Valentin Deniaud 2023-06-28 11:43:02 +02:00
parent 9125b7af10
commit cdcb663f85
2 changed files with 20 additions and 3 deletions

View File

@ -1505,9 +1505,9 @@ class AgendaDayView(AgendaDateView, DayArchiveView):
min_time = localtime(event_times['start_datetime__min']).time()
max_time = event_times['end_time__max']
start_time = datetime.time(min_time.hour - 1, 0)
end_time = datetime.time(max_time.hour + 2, 0)
context['hours'] = [datetime.time(hour=i) for i in range(start_time.hour, end_time.hour)]
start_time = datetime.time(max(min_time.hour - 1, 0), 0)
end_time = datetime.time(min(max_time.hour + 1, 23), 0)
context['hours'] = [datetime.time(hour=i) for i in range(start_time.hour, end_time.hour + 1)]
def get_time_ratio(t1, t2):
return 100 * ((t1.hour - t2.hour) * 60 + t1.minute - t2.minute) // 60

View File

@ -109,3 +109,20 @@ def test_manager_partial_bookings_day_view(app, admin_user, freezer):
resp = resp.click('Next day')
assert 'No opening hours this day.' in resp.text
def test_manager_partial_bookings_day_view_24_hours(app, admin_user, freezer):
agenda = Agenda.objects.create(label='Foo bar', kind='events', partial_bookings=True)
start_datetime = make_aware(datetime.datetime(2023, 5, 2, 0, 0))
Event.objects.create(
label='Event', start_datetime=start_datetime, end_time=datetime.time(23, 59), places=10, agenda=agenda
)
app = login(app)
today = start_datetime.date()
resp = app.get('/manage/agendas/%s/day/%d/%d/%d/' % (agenda.pk, today.year, today.month, today.day))
assert resp.pyquery('thead th').text() == (
'midnight 1 a.m. 2 a.m. 3 a.m. 4 a.m. 5 a.m. 6 a.m. 7 a.m. 8 a.m. 9 a.m. 10 a.m. 11 a.m. noon '
'1 p.m. 2 p.m. 3 p.m. 4 p.m. 5 p.m. 6 p.m. 7 p.m. 8 p.m. 9 p.m. 10 p.m. 11 p.m.'
)