]> git.0d.be Git - django-panik-emissions.git/commitdiff
fix handling of nonstop slots spanning the day separation time
authorFrédéric Péters <fpeters@0d.be>
Wed, 5 Oct 2016 14:16:09 +0000 (16:16 +0200)
committerFrédéric Péters <fpeters@0d.be>
Wed, 5 Oct 2016 14:16:09 +0000 (16:16 +0200)
emissions/utils.py

index a0e7a682da828a667487a6a7adb3c5908d5486bb..9e43d4aee38d1f8f6512ebf278e11dd853bb1ce5 100644 (file)
@@ -180,6 +180,7 @@ def period_program(date_start, date_end, prefetch_sounds=True,
 
     # last step is adding nonstop zones between slots
     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)]
@@ -221,6 +222,7 @@ def period_program(date_start, date_end, prefetch_sounds=True,
                         dt = dt.replace(hour=dawn.hour, minute=dawn.minute)
                         cells.append(cls(nonstop, dt))
 
+            cells.sort(key=lambda x: x.datetime)
             return cells
 
 
@@ -240,8 +242,12 @@ def period_program(date_start, date_end, prefetch_sounds=True,
             if slot_end < next_slot.datetime:
                 next_day_start = next_slot.datetime.replace(hour=5, minute=0)
                 if slot_end < next_day_start and next_slot.datetime > next_day_start:
-                    program[i+1:i+1] = NonstopSlot.get_serie(slot_end, next_day_start) + \
-                            NonstopSlot.get_serie(next_day_start, next_slot.datetime)
+                    nonstop_day_slots = NonstopSlot.get_serie(slot_end, next_day_start)
+                    nonstop_next_day_slots = NonstopSlot.get_serie(next_day_start, next_slot.datetime)
+                    if nonstop_day_slots and nonstop_next_day_slots and \
+                            nonstop_day_slots[-1].label == nonstop_next_day_slots[0].label:
+                        nonstop_next_day_slots = nonstop_next_day_slots[1:]
+                    program[i+1:i+1] = nonstop_day_slots + nonstop_next_day_slots
                 else:
                     program[i+1:i+1] = NonstopSlot.get_serie(slot_end, next_slot.datetime)