Commit d692fe05 authored by fred's avatar fred

fill /listen/ page with soundfile objects, not episodes

parent b4f356de
......@@ -93,6 +93,10 @@ def emission_inline(context, date=None):
'schedules': context.get('schedules'),
}
@register.inclusion_tag('soundfiles/resume.html')
def soundfile_resume(soundfile):
return {'soundfile': soundfile}
@register.inclusion_tag('includes/player.html', takes_context=False)
def player():
return {'unique': uuid.uuid4()}
......
......@@ -520,26 +520,16 @@ class Listen(TemplateView):
def get_context_data(self, **kwargs):
context = super(Listen, self).get_context_data(**kwargs)
context['sectionName'] = "Listen"
context['episodes'] = Episode.objects.prefetch_related('emission__categories').filter(
soundfile__podcastable=True, soundfile__fragment=False) \
context['soundfiles'] = SoundFile.objects.prefetch_related('episode__emission__categories').filter(
podcastable=True, fragment=False) \
.select_related().extra(select={
'first_diffusion': 'emissions_diffusion.datetime', },
select_params=(False, True),
where=['''datetime = (SELECT MIN(datetime)
FROM emissions_diffusion
WHERE episode_id = emissions_episode.id)'''],
tables=['emissions_diffusion'],).order_by('-first_diffusion') [:60]
tables=['emissions_diffusion'],).order_by('-first_diffusion') [:20]
# get all related soundfiles in a single query
soundfiles = {}
for soundfile in SoundFile.objects.select_related().filter(podcastable=True,
fragment=False, episode__in=[x.id for x in context['episodes']]):
soundfiles[soundfile.episode_id] = soundfile
# replace dynamic property by a static attribute, to avoid database
# lookups
for episode in context['episodes']:
episode.main_sound = soundfiles.get(episode.id)
context['categories'] = Category.objects.all()
return context
......
......@@ -7,9 +7,9 @@
<div class="">
<div class="wrapper">
<ul class="padded custom columns list">
{% for episode in episodes %}
<li class="item {% if episode.emission.categories.all.count = 0 %}nocat{% endif %} {% for category in episode.emission.categories.all %} {{ category|slugify }}{% endfor %}">
{% episode_resume model="inline" klass="standalone" %}
{% for soundfile in soundfiles %}
<li class="item {% if soundfile.episode.emission.categories.all.count = 0 %}nocat{% endif %} {% for category in soundfile.episode.emission.categories.all %} {{ category|slugify }}{% endfor %}">
{% soundfile_resume soundfile=soundfile %}
</li>
{% endfor %}
</ul>
......
{% load thumbnails %}
{% load paniktags %}
{% load staticfiles %}
<div class="episode inline cf">
<div class="dateBloc">
<div class="date">
<div class="day">{{ soundfile.first_diffusion|date:"D"|slice:":2"}}</div>
<div class="number">{{ soundfile.first_diffusion|date:"d" }}</div>
<div class="month">{{ soundfile.first_diffusion|date:"M y" }}</div>
</div>
</div>
<div class="logo">
{% if soundfile.episode.image %}
<img src="{{ soundfile.episode.image|thumbnail:'60x60' }}"/>
{% elif episode.emission.image %}
<img src="{{ soundfile.episode.emission.image|thumbnail:'60x60' }}"/>
{% else %}
<img class="smooth" style="width:60px;" src="{% static "img/defaultLogo.png" %}"/>
{% endif %}
</div>
<div class="content">
<div class="sound right">{% audio sound=soundfile %}</div>
<div class="title ellipsis">
<h5 class=" inBlock title {% if model = "inline" %}ellipsis{% endif %}">
<a href="{% url 'episode-view' emission_slug=soundfile.episode.emission.slug slug=soundfile.episode.slug %}">{{ soundfile.episode.title }}</a>
</h5>
<div class="smooth metas">
<h5 class="title inBlock">
<a href="{% url 'emission-view' slug=soundfile.episode.emission.slug %}">{{ soundfile.episode.emission.title }}</a>
</h5>
{% if soundfile.episode.emission.categories %}
<span class="categories">
{% for category in soundfile.episode.emission.categories.all %}
{% if forloop.counter > 1 %} - {% endif %}<span class="category"><span class="inBlock icon-{{category|slugify}}">&nbsp;</span>{{category}}</span>
{% endfor%}
</span>
{% endif %}
</div>
</div>
{% if soundfile.episode.subtitle %}
<div class="description ellipsis">
{{ soundfile.episode.subtitle|truncatewords:20}}
</div>
{% elif soundfile.episode.text %}
<div class="description ellipsis">
{{ soundfile.episode.text|safe|striptags|truncatewords:20}}
</div>
{% endif %}
</div>
</div>
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