Commit c0fdbaaa authored by fred's avatar fred

search: highligth selected facets

parent 9db4406f
......@@ -12,6 +12,8 @@ from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
import haystack.views
from .models import Emission, Episode, Diffusion, Category, Schedule, SoundFile
from .forms import EmissionForm, EpisodeForm, EpisodeNewForm, ScheduleForm, \
DiffusionForm, SoundFileForm
......@@ -199,3 +201,15 @@ class DiffusionDeleteView(RedirectView):
Diffusion.objects.filter(id=pk).delete()
return reverse('episode-view', kwargs={'emission_slug': str(emission_slug),
'slug': str(slug)})
class FacetedSearchView(haystack.views.FacetedSearchView):
def extra_context(self):
context = super(FacetedSearchView, self).extra_context()
context['selected_categories'] = [
x.split(':', 1)[1] for x in self.request.GET.getlist('selected_facets')
if x.startswith('categories_exact')]
context['selected_tags'] = [
x.split(':', 1)[1] for x in self.request.GET.getlist('selected_facets')
if x.startswith('tags_exact')]
return context
......@@ -16,12 +16,17 @@
{% if query %}
<!-- Begin faceting. -->
<p>
{% if facets.fields.categories %}
Catégories :
{# Provide only the top 5 categories #}
{% for category in facets.fields.categories|slice:":5" %}
{% if category.0 in selected_categories %}
<strong>{{ category.0 }}</strong> ({{ category.1 }})
{% else %}
<span><a href="{{ request.get_full_path }}&amp;selected_facets=categories_exact:{{ category.0|urlencode }}">{{ category.0 }}</a> ({{ category.1 }})</span>
{% endif %}
{% endfor %}
{% else %}
No categories facets.
......@@ -33,7 +38,11 @@
Tags :
{# Provide only the top 5 tags #}
{% for tag in facets.fields.tags|slice:":5" %}
{% if tag.0 in selected_tags %}
<strong>{{ tag.0 }}</strong> ({{ tag.1 }})
{% else %}
<span><a href="{{ request.get_full_path }}&amp;selected_facets=tags_exact:{{ tag.0|urlencode }}">{{ tag.0 }}</a> ({{ tag.1 }})</span>
{% endif %}
{% endfor %}
{% else %}
No tags facets.
......
......@@ -6,10 +6,12 @@ from django.core.urlresolvers import reverse_lazy
from django.contrib import admin
admin.autodiscover()
from haystack.views import FacetedSearchView, search_view_factory
from haystack.views import search_view_factory
from haystack.forms import FacetedSearchForm
from haystack.query import SearchQuerySet
from emissions.views import FacetedSearchView
sqs = SearchQuerySet().facet('categories').facet('tags')
urlpatterns = patterns('',
......
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