]> git.0d.be Git - django-panik-emissions.git/blobdiff - emissions/models.py
prefill new episode with duration from schedule (instead of default)
[django-panik-emissions.git] / emissions / models.py
index dfc6a44ab0c0a8f1afa38b9df21f911bb0c36379..cca07713fee2c220c76a70d8f6ac556f1c1e5d8d 100644 (file)
@@ -178,7 +178,7 @@ class Emission(models.Model):
     def get_sorted_newsitems(self):
         return self.newsitem_set.select_related().order_by('-date')
 
-    def get_next_planned_date(self, since=None):
+    def get_next_planned_date_and_schedule(self, since=None):
         schedules = self.schedule_set.filter(rerun=False)
         if not schedules:
             return None
@@ -186,10 +186,19 @@ class Emission(models.Model):
             since = datetime.datetime.today()
         possible_dates = []
         for schedule in schedules:
-            possible_dates.append(schedule.get_next_planned_date(since))
+            possible_dates.append((schedule.get_next_planned_date(since), schedule))
         possible_dates.sort()
         return possible_dates[0]
 
+    def get_next_planned_date(self, since=None):
+        result = self.get_next_planned_date_and_schedule(since=since)
+        return result[0] if result else None
+
+    def get_next_planned_duration(self, since=None):
+        result = self.get_next_planned_date_and_schedule(since=since)
+        if not result:
+            return None
+        return result[1].duration or self.duration
 
 @python_2_unicode_compatible
 class Schedule(models.Model, WeekdayMixin):