Commit 0a2f32c0 authored by fred's avatar fred
Browse files

listen archives page

parent fec22fea
...@@ -11,6 +11,7 @@ from django.db.models.query import QuerySet ...@@ -11,6 +11,7 @@ from django.db.models.query import QuerySet
from django.utils import simplejson from django.utils import simplejson
from datetime import datetime, timedelta from datetime import datetime, timedelta
from emissions.models import Emission, Episode, NewsItem
from emissions.utils import period_program from emissions.utils import period_program
from panikweb import utils from panikweb import utils
...@@ -94,8 +95,9 @@ def emission_inline(context, date=None): ...@@ -94,8 +95,9 @@ def emission_inline(context, date=None):
} }
@register.inclusion_tag('soundfiles/resume.html') @register.inclusion_tag('soundfiles/resume.html')
def soundfile_resume(soundfile): def soundfile_resume(soundfile, date=None):
return {'soundfile': soundfile} return {'soundfile': soundfile,
'date': date}
@register.inclusion_tag('includes/player.html', takes_context=False) @register.inclusion_tag('includes/player.html', takes_context=False)
def player(): def player():
...@@ -225,5 +227,5 @@ def rfc822(datetime): ...@@ -225,5 +227,5 @@ def rfc822(datetime):
@register.inclusion_tag('includes/related.html', takes_context=False) @register.inclusion_tag('includes/related.html', takes_context=False)
def related_objects(object): def related_objects(object):
sqs = search.MoreLikeThisSearchQuerySet() sqs = search.MoreLikeThisSearchQuerySet().models(Emission, Episode, NewsItem)
return {'more_like_this': sqs.more_like_this(object)[:12]} return {'more_like_this': sqs.more_like_this(object)[:12]}
import haystack.backends.solr_backend 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.constants import ID, DJANGO_CT, DJANGO_ID
from haystack.utils import get_identifier from haystack.utils import get_identifier
from haystack.backends import EmptyResults from haystack.backends import EmptyResults
from pysolr import SolrError from pysolr import SolrError
from django.conf import settings from django.conf import settings
from emissions.models import Emission, Episode, NewsItem, SoundFile
class MoreLikeThisSearchQuerySet(SearchQuerySet): class MoreLikeThisSearchQuerySet(SearchQuerySet):
def more_like_this(self, model_instance, **kwargs): def more_like_this(self, model_instance, **kwargs):
...@@ -110,8 +111,9 @@ class CustomSolrSearchBackend(haystack.backends.solr_backend.SolrSearchBackend): ...@@ -110,8 +111,9 @@ class CustomSolrSearchBackend(haystack.backends.solr_backend.SolrSearchBackend):
haystack.backends.solr_backend.SolrEngine.query = CustomSolrSearchQuery haystack.backends.solr_backend.SolrEngine.query = CustomSolrSearchQuery
haystack.backends.solr_backend.SolrEngine.backend = CustomSolrSearchBackend haystack.backends.solr_backend.SolrEngine.backend = CustomSolrSearchBackend
import haystack.views
from haystack.views import search_view_factory, FacetedSearchView from haystack.views import search_view_factory, FacetedSearchView
from haystack.forms import FacetedSearchForm from haystack.forms import FacetedSearchForm, SearchForm
class SearchView(FacetedSearchView): class SearchView(FacetedSearchView):
...@@ -126,8 +128,34 @@ class SearchView(FacetedSearchView): ...@@ -126,8 +128,34 @@ class SearchView(FacetedSearchView):
if x.startswith('tags_exact')] if x.startswith('tags_exact')]
return context return context
sqs = SearchQuerySet().facet('categories').facet('tags') sqs = SearchQuerySet().models(Emission, Episode, NewsItem).facet('categories').facet('tags')
view = search_view_factory(SearchView, view = search_view_factory(SearchView,
form_class=FacetedSearchForm, form_class=FacetedSearchForm,
searchqueryset=sqs) 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('', ...@@ -20,7 +20,7 @@ urlpatterns = patterns('',
url(r'^ckeditor/', include('ckeditor.urls')), url(r'^ckeditor/', include('ckeditor.urls')),
url(r'^emissions/archives$', 'panikweb.views.emissionsArchives', name='emissionsArchives'), url(r'^emissions/archives$', 'panikweb.views.emissionsArchives', name='emissionsArchives'),
url(r'^listen/$', 'panikweb.views.listen', name='listen'), 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/$', 'panikweb.views.news', name='news'),
url(r'^news/archives/$', 'panikweb.views.newsArchives', name='newsArchives'), url(r'^news/archives/$', 'panikweb.views.newsArchives', name='newsArchives'),
url(r'^news/(?P<slug>[\w,-]+)$', 'panikweb.views.newsitemview', name='news-view'), url(r'^news/(?P<slug>[\w,-]+)$', 'panikweb.views.newsitemview', name='news-view'),
......
...@@ -519,7 +519,7 @@ class Listen(TemplateView): ...@@ -519,7 +519,7 @@ class Listen(TemplateView):
where=['''datetime = (SELECT MIN(datetime) where=['''datetime = (SELECT MIN(datetime)
FROM emissions_diffusion FROM emissions_diffusion
WHERE episode_id = emissions_episode.id)'''], 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() context['categories'] = Category.objects.all()
...@@ -527,38 +527,6 @@ class Listen(TemplateView): ...@@ -527,38 +527,6 @@ class Listen(TemplateView):
listen = Listen.as_view() 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) @cache_control(max_age=25)
@csrf_exempt @csrf_exempt
@to_json('api') @to_json('api')
......
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
{% block main %} {% block main %}
<div class=""> <div class="">
<div class="wrapper"> <div class="wrapper">
<ul class="padded custom columns list"> <ul class="padded custom list">
{% for soundfile in soundfiles %} {% 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 %}"> <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> </li>
{% endfor %} {% endfor %}
</ul> </ul>
......
...@@ -3,14 +3,41 @@ ...@@ -3,14 +3,41 @@
{% block title %}Listen - Archives{% endblock %} {% block title %}Listen - Archives{% endblock %}
{% block nav %} {% block nav %}
{% listen_nav with klass="archives" %} {% 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 %} {% endblock %}
{% block main %} {% 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 %} {% endblock %}
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<ul class="inline padded"> <ul class="inline padded">
<li><a href="{% url 'listen' %}" class="{% if class != "archives" %}active{% endif %}"> <li><a href="{% url 'listen' %}" class="{% if class != "archives" %}active{% endif %}">
<span class="icon-bolt" ></span> <span class="icon-bolt" ></span>
<span class="iconLabel">Dernières</span> <span class="iconLabel">Derniers</span>
</a></li> </a></li>
<li><a href="{% url 'listenArchives' %}" class="{% if class = "archives" %}active{% endif %}"> <li><a href="{% url 'listenArchives' %}" class="{% if class = "archives" %}active{% endif %}">
<span class="icon-archive" ></span> <span class="icon-archive" ></span>
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
<div class="episode inline cf"> <div class="episode inline cf">
<div class="dateBloc"> <div class="dateBloc">
<div class="date"> <div class="date">
<div class="day">{{ soundfile.first_diffusion|date:"D"|slice:":2"}}</div> <div class="day">{{ date|date:"D"|slice:":2"}}</div>
<div class="number">{{ soundfile.first_diffusion|date:"d" }}</div> <div class="number">{{ date|date:"d" }}</div>
<div class="month">{{ soundfile.first_diffusion|date:"M y" }}</div> <div class="month">{{ date|date:"M y" }}</div>
</div> </div>
</div> </div>
<div class="logo"> <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