]> git.0d.be Git - django-panik-emissions.git/commitdiff
don't crash when there are no nonstop zones
authorFrédéric Péters <fpeters@0d.be>
Thu, 24 Sep 2020 17:56:00 +0000 (19:56 +0200)
committerFrédéric Péters <fpeters@0d.be>
Thu, 24 Sep 2020 17:56:00 +0000 (19:56 +0200)
emissions/utils.py

index 366d56760473777d04f61dc0a8f770e211f0dd6f..def59d6353c77cc01baa342b6c170c89e2c979fd 100644 (file)
@@ -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):