Commit 1d2ee959 authored by laron's avatar laron
Browse files

(TO BE CHECKED) Adding current episode/emission on player

parent c3a5781a
import datetime
from datetime import datetime, timedelta
import math
from django.views.generic.base import TemplateView
from emissions.models import Emission, Episode, Schedule
from emissions.models import Emission, Episode, Diffusion, SoundFile, Schedule
class ProgramView(TemplateView):
template_name = 'program.html'
......@@ -174,6 +174,30 @@ class Player(TemplateView):
def get_context_data(self, **kwargs):
context = super(Player, self).get_context_data(**kwargs)
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)]
episode = None
emission = None
if diffusions: # there should be only one
diffusion = diffusions[0]
episode = diffusion.episode
emission = episode.emission
else:
for schedule in Schedule.objects.all():
if not schedule.matches(now):
continue
emission = schedule.emission
break
context['episode'] = episode
context['emission'] = emission
context['emissions'] = Emission.objects.all().order_by('title')
return context
......
......@@ -10,6 +10,30 @@
</div>
<audio id="DirectStreamPanik" tabindex="0" src="http://streaming.domainepublic.net:8000/radiopanik.ogg" controls="controls">
</audio>
{% if episode %}
<div class="current">
<h5>{{ episode.title }}</h5>
{% for schedule in schedules %}
<div>{{ schedule.datetime|date:"l G:i" }}
<!--<div class="time">{{ schedule.datetime|date:"G:i" }}</div>-->
{% if schedule.rerun %} <span class="smooth">(rediff)</span> {% endif %}</div>
{% endfor %}
</div>
{% elif emission %}
<div class="current">
<h5>{{ emission.title }}</h5>
{% for schedule in schedules %}
<div>{{ schedule.datetime|date:"l G:i" }}
<!--<div class="time">{{ schedule.datetime|date:"G:i" }}</div>-->
{% if schedule.rerun %} <span class="smooth">(rediff)</span> {% endif %}</div>
{% endfor %}
</div>
{% else %}
<div class="current">
<h5>Non-stop</h5>
</div>
{% endif %}
<script type="text/javascript">
$(function() {
$("[data-audio-id]").click(function(e) {
......
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