From d7480c98c57f5435637901e4a9be7965cf3b305c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Thu, 24 Sep 2020 19:56:00 +0200 Subject: [PATCH] don't crash when there are no nonstop zones --- emissions/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/emissions/utils.py b/emissions/utils.py index 366d567..def59d6 100644 --- a/emissions/utils.py +++ b/emissions/utils.py @@ -221,8 +221,11 @@ def period_program(date_start, date_end, prefetch_sounds=True, nonstops = list(Nonstop.objects.all().order_by('start')) nonstops = [x for x in nonstops if x.start != x.end] dawn = time(Schedule.DAY_HOUR_START, 0) - first_of_the_day = [x for x in nonstops if x.start <= dawn][-1] - nonstops = nonstops[nonstops.index(first_of_the_day):] + nonstops[:nonstops.index(first_of_the_day)] + try: + first_of_the_day = [x for x in nonstops if x.start <= dawn][-1] + nonstops = nonstops[nonstops.index(first_of_the_day):] + nonstops[:nonstops.index(first_of_the_day)] + except IndexError: + pass class NonstopSlot(WeekdayMixin): def __init__(self, nonstop, dt): -- GitLab