Commit 2a344dd7 authored by fred's avatar fred
Browse files

update homepage to use new soundfile template

parent 0e9f806e
...@@ -414,8 +414,8 @@ class Home(TemplateView): ...@@ -414,8 +414,8 @@ class Home(TemplateView):
'datetime': datetime(2007, 1, day+1)}) 'datetime': datetime(2007, 1, day+1)})
context['days'] = days context['days'] = days
context['episodes'] = Episode.objects.prefetch_related('emission__categories').filter( context['soundfiles'] = SoundFile.objects.prefetch_related('episode__emission__categories').filter(
soundfile__podcastable=True, soundfile__fragment=False) \ podcastable=True, fragment=False) \
.select_related().extra(select={ .select_related().extra(select={
'first_diffusion': 'emissions_diffusion.datetime', }, 'first_diffusion': 'emissions_diffusion.datetime', },
select_params=(False, True), select_params=(False, True),
...@@ -424,17 +424,6 @@ class Home(TemplateView): ...@@ -424,17 +424,6 @@ class Home(TemplateView):
WHERE episode_id = emissions_episode.id)'''], WHERE episode_id = emissions_episode.id)'''],
tables=['emissions_diffusion'],).order_by('-first_diffusion') [:6] tables=['emissions_diffusion'],).order_by('-first_diffusion') [:6]
# 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['newsletter_form'] = SubscribeForm() context['newsletter_form'] = SubscribeForm()
return context return context
......
...@@ -28,9 +28,9 @@ ...@@ -28,9 +28,9 @@
<div class="wrapper"> <div class="wrapper">
<h2><a href="{% url 'listen' %}">Derniers sons</a></h2> <h2><a href="{% url 'listen' %}">Derniers sons</a></h2>
<ul class="custom columns list"> <ul class="custom columns list">
{% for episode in episodes %} {% for soundfile in soundfiles %}
<li class="item {% if episode.emission.categories.all.count = 0 %}nocat{% endif %} {% for category in episode.emission.categories.all %} {{ category|slugify }}{% endfor %}"> <li class="item {% if soundfile.episode.emission.categories.all.count = 0 %}nocat{% endif %} {% for category in soundfile.episode.emission.categories.all %} {{ category|slugify }}{% endfor %}">
{% episode_resume model="inline" klass="standalone"%} {% soundfile_resume soundfile=soundfile date=soundfile.first_diffusion %}
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
......
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