Commit 0a2f32c0 authored by fred's avatar fred

listen archives page

parent fec22fea
......@@ -11,6 +11,7 @@ from django.db.models.query import QuerySet
from django.utils import simplejson
from datetime import datetime, timedelta
from emissions.models import Emission, Episode, NewsItem
from emissions.utils import period_program
from panikweb import utils
......@@ -94,8 +95,9 @@ def emission_inline(context, date=None):
}
@register.inclusion_tag('soundfiles/resume.html')
def soundfile_resume(soundfile):
return {'soundfile': soundfile}
def soundfile_resume(soundfile, date=None):
return {'soundfile': soundfile,
'date': date}
@register.inclusion_tag('includes/player.html', takes_context=False)
def player():
......@@ -225,5 +227,5 @@ def rfc822(datetime):
@register.inclusion_tag('includes/related.html', takes_context=False)
def related_objects(object):
sqs = search.MoreLikeThisSearchQuerySet()
sqs = search.MoreLikeThisSearchQuerySet().models(Emission, Episode, NewsItem)
return {'more_like_this': sqs.more_like_this(object)[:12]}
import haystack.backends.solr_backend
from haystack.query import SearchQuerySet
from haystack.query import SearchQuerySet, RelatedSearchQuerySet
from haystack.constants import ID, DJANGO_CT, DJANGO_ID
from haystack.utils import get_identifier
from haystack.backends import EmptyResults
from pysolr import SolrError
from django.conf import settings
from emissions.models import Emission, Episode, NewsItem, SoundFile
class MoreLikeThisSearchQuerySet(SearchQuerySet):
def more_like_this(self, model_instance, **kwargs):
......@@ -110,8 +111,9 @@ class CustomSolrSearchBackend(haystack.backends.solr_backend.SolrSearchBackend):
haystack.backends.solr_backend.SolrEngine.query = CustomSolrSearchQuery
haystack.backends.solr_backend.SolrEngine.backend = CustomSolrSearchBackend
import haystack.views
from haystack.views import search_view_factory, FacetedSearchView
from haystack.forms import FacetedSearchForm
from haystack.forms import FacetedSearchForm, SearchForm
class SearchView(FacetedSearchView):
......@@ -126,8 +128,34 @@ class SearchView(FacetedSearchView):
if x.startswith('tags_exact')]
return context
sqs = SearchQuerySet().facet('categories').facet('tags')
sqs = SearchQuerySet().models(Emission, Episode, NewsItem).facet('categories').facet('tags')
view = search_view_factory(SearchView,
form_class=FacetedSearchForm,
searchqueryset=sqs)
class ListenArchivesForm(SearchForm):
def no_query_found(self):
return self.searchqueryset.all()
def search(self):
sqs = super(ListenArchivesForm, self).search()
return sqs.load_all()
class ListenArchivesView(haystack.views.SearchView):
template = 'listen/archives.html'
def __init__(self):
sqs = RelatedSearchQuerySet().filter(django_ct='emissions.soundfile').order_by('-date')
super(ListenArchivesView, self).__init__(searchqueryset=sqs,
form_class=ListenArchivesForm, results_per_page=20)
def extra_context(self):
context = super(ListenArchivesView, self).extra_context()
context['sectionName'] = "Listen"
return context
listenArchives = search_view_factory(ListenArchivesView)
......@@ -20,7 +20,7 @@ urlpatterns = patterns('',
url(r'^ckeditor/', include('ckeditor.urls')),
url(r'^emissions/archives$', 'panikweb.views.emissionsArchives', name='emissionsArchives'),
url(r'^listen/$', 'panikweb.views.listen', name='listen'),
url(r'^listen/archives/$', 'panikweb.views.listenArchives', name='listenArchives'),
url(r'^listen/archives/$', 'panikweb.search.listenArchives', name='listenArchives'),
url(r'^news/$', 'panikweb.views.news', name='news'),
url(r'^news/archives/$', 'panikweb.views.newsArchives', name='newsArchives'),
url(r'^news/(?P<slug>[\w,-]+)$', 'panikweb.views.newsitemview', name='news-view'),
......
......@@ -519,7 +519,7 @@ class Listen(TemplateView):
where=['''datetime = (SELECT MIN(datetime)
FROM emissions_diffusion
WHERE episode_id = emissions_episode.id)'''],
tables=['emissions_diffusion'],).order_by('-first_diffusion') [:20]
tables=['emissions_diffusion'],).order_by('-first_diffusion') [:10]
context['categories'] = Category.objects.all()
......@@ -527,38 +527,6 @@ class Listen(TemplateView):
listen = Listen.as_view()
class ListenArchives(TemplateView):
template_name = 'listen/archives.html'
def get_context_data(self, **kwargs):
context = super(ListenArchives, self).get_context_data(**kwargs)
context['sectionName'] = "Listen"
context['episodes'] = Episode.objects.filter(
soundfile__podcastable=True, soundfile__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]
# 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
listenArchives = ListenArchives.as_view()
@cache_control(max_age=25)
@csrf_exempt
@to_json('api')
......
......@@ -6,10 +6,10 @@
{% block main %}
<div class="">
<div class="wrapper">
<ul class="padded custom columns list">
<ul class="padded custom list">
{% 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 %}
{% soundfile_resume soundfile=soundfile date=soundfile.first_diffusion %}
</li>
{% endfor %}
</ul>
......
......@@ -3,14 +3,41 @@
{% block title %}Listen - Archives{% endblock %}
{% block nav %}
{% listen_nav with klass="archives" %}
<form method="get" action="." class="padded center" id="search-form">
<div class="big ">
<label for="id_q">Rechercher:</label>
<input id="id_q" name="q" type="text" {% if search_query %}value="{{ search_query }}{% endif %}">
<button class="icon-search"></button>
</div>
</form>
{% endblock %}
{% block main %}
<form method="get" action="." class="padded center" id="search-form">
<div class="big">
{{ form.as_table }}<button class="icon-search"></button>
</div>
</form>
<div class="wrapper">
{% if not page.object_list %}
<div class="big error padded center">Sorry, no result with your query!</div>
{% else %}
{% if page.has_previous %}
<div class="previous-page cf">
<a class="button big left" href="?q={{ query }}&amp;page={{ page.previous_page_number }}">&laquo; Résultats précédénts</a>
</div>
{% endif %}
<ul class="padded custom columns list">
{% for result in page.object_list %}
<li>{% soundfile_resume soundfile=result.object date=result.date %}</li>
{% endfor %}
</ul>
{% if page.has_next %}
<div class="next-page cf">
<a class="button big right" href="?q={{ query }}&amp;page={{ page.next_page_number }}">Résultats suivants &raquo;</a>
</div>
{% endif %}
{% endif %}
</div>
{% endblock %}
......@@ -4,7 +4,7 @@
<ul class="inline padded">
<li><a href="{% url 'listen' %}" class="{% if class != "archives" %}active{% endif %}">
<span class="icon-bolt" ></span>
<span class="iconLabel">Dernières</span>
<span class="iconLabel">Derniers</span>
</a></li>
<li><a href="{% url 'listenArchives' %}" class="{% if class = "archives" %}active{% endif %}">
<span class="icon-archive" ></span>
......
......@@ -4,9 +4,9 @@
<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 class="day">{{ date|date:"D"|slice:":2"}}</div>
<div class="number">{{ date|date:"d" }}</div>
<div class="month">{{ date|date:"M y" }}</div>
</div>
</div>
<div class="logo">
......
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