Commit 76bde5ff authored by fred's avatar fred

prefill new episode with duration from schedule (instead of default)

parent ecd8c4dc
......@@ -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):
......
......@@ -176,7 +176,7 @@ class EpisodeCreateView(CreateView):
def get_initial(self):
initial = super(EpisodeCreateView, self).get_initial()
initial['emission'] = Emission.objects.get(slug=self.kwargs.get('emission_slug'))
initial['duration'] = initial['emission'].duration
initial['duration'] = initial['emission'].get_next_planned_duration()
initial['first_diffusion'] = initial['emission'].get_next_planned_date()
for i, schedule in enumerate(
Schedule.objects.filter(emission=initial['emission'],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment