Commit 58222fec authored by fred's avatar fred
Browse files

update whatsonair to be based on day_program

parent a51e5f14
......@@ -19,28 +19,25 @@ def whatsonair():
from models import Diffusion, Schedule
now = datetime.now()
date_start = now - timedelta(days=1)
date_end = now + timedelta(days=1)
diffusions = Diffusion.objects.filter(
datetime__range=(date_start, date_end)).order_by('datetime')
diffusions = [x for x in diffusions if x.datetime <= now and
now <= x.datetime + timedelta(minutes=x.episode.emission.duration)]
program = day_program(now)
program = [x for x in program if not x.datetime > now]
episode = None
emission = None
if diffusions: # there should be only one
diffusion = diffusions[0]
episode = diffusion.episode
emission = episode.emission
episode = None
current_slot = None
if program and program[-1].datetime + timedelta(minutes=program[-1].get_duration()) > now:
current_slot = program[-1]
if isinstance(current_slot, Schedule):
emission = current_slot.emission
elif isinstance(current_slot, Diffusion):
episode = current_slot.episode
emission = episode.emission
else:
for schedule in Schedule.objects.all():
if not schedule.matches(now):
continue
emission = schedule.emission
break
pass
return {'emission': emission,
'episode': episode}
'episode': episode,
'current_slot': current_slot}
def day_program(date):
......
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