]> git.0d.be Git - django-panik-emissions.git/commitdiff
add special case for daily program with same-day rerun
authorFrédéric Péters <fpeters@0d.be>
Sun, 10 Nov 2019 16:07:27 +0000 (17:07 +0100)
committerFrédéric Péters <fpeters@0d.be>
Sun, 10 Nov 2019 16:07:27 +0000 (17:07 +0100)
emissions/forms.py
emissions/models.py

index ef59c0fbc2a4ada0e9fb77888e7e8a91edea496b..6571a8a0215641d1c8aa647186a0d255c0cc3d5c 100644 (file)
@@ -184,7 +184,12 @@ class EpisodeNewForm(EpisodeForm):
 
     def get_diffusion_fields(self, emission):
         if emission:
-            schedules = Schedule.objects.filter(emission=emission, rerun=True).count() + 1
+            schedules = list(Schedule.objects.filter(emission=emission).order_by('datetime'))
+            if len(schedules) > 1 and schedules[0].datetime.date() == schedules[1].datetime.date():
+                # special case for daily program with same-day rerun
+                schedules = 2
+            else:
+                schedules = len([x for x in schedules if x.rerun]) + 1
         else:
             schedules = 1
         fields = ['first_diffusion']
index 88580eb44b86ca1ea8be8cfe73cd0022ef0b2821..c5b8917c236868caaaee0100b02cd15ad025d525 100644 (file)
@@ -237,6 +237,9 @@ class Schedule(models.Model, WeekdayMixin):
         else:
             return self.emission.duration
 
+    def end_datetime(self):
+        return self.datetime + datetime.timedelta(minutes=self.get_duration())
+
     def match_week(self, week_no):
         if week_no == 4:
             # this is the fifth week of the month, only return True for