diff --git a/emissions/utils.py b/emissions/utils.py index 366d56760473777d04f61dc0a8f770e211f0dd6f..def59d6353c77cc01baa342b6c170c89e2c979fd 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):