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