Commit f204be4e authored by fred's avatar fred

display tags in episode view

parent 5dc43c16
...@@ -116,6 +116,20 @@ from haystack.views import search_view_factory, FacetedSearchView ...@@ -116,6 +116,20 @@ from haystack.views import search_view_factory, FacetedSearchView
from haystack.forms import FacetedSearchForm, SearchForm from haystack.forms import FacetedSearchForm, SearchForm
class GlobalSearchForm(FacetedSearchForm):
def no_query_found(self):
sqs = super(GlobalSearchForm, self).no_query_found()
if self.selected_facets:
sqs = self.searchqueryset.all()
for facet in self.selected_facets:
if ":" not in facet:
continue
field, value = facet.split(":", 1)
if value:
sqs = sqs.narrow(u'%s:"%s"' % (field, sqs.query.clean(value)))
return sqs
class SearchView(FacetedSearchView): class SearchView(FacetedSearchView):
def extra_context(self): def extra_context(self):
context = super(SearchView, self).extra_context() context = super(SearchView, self).extra_context()
...@@ -131,7 +145,7 @@ class SearchView(FacetedSearchView): ...@@ -131,7 +145,7 @@ class SearchView(FacetedSearchView):
sqs = SearchQuerySet().models(Emission, Episode, NewsItem).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=GlobalSearchForm,
searchqueryset=sqs) searchqueryset=sqs)
......
...@@ -41,10 +41,10 @@ ...@@ -41,10 +41,10 @@
{% if episode.redif %}<dt>Redifusion</dt><dd>{{ redif }}</dd>{% endif %} {% if episode.redif %}<dt>Redifusion</dt><dd>{{ redif }}</dd>{% endif %}
</dl> </dl>
{% endif %} {% endif %}
{% if episode.tagList %} {% if episode.tags.all %}
<ul class="custom inline"> <ul class="custom inline">
{% for tag in episode.tagList %} {% for tag in episode.tags.all %}
<li><button class="tag">{{ tag }}</button></li> <li><a class="tag" href="{% url 'search' %}?&selected_facets=tags_exact:{{tag.slug}}">{{ tag }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
{% endif %} {% endif %}
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<form method="get" action="." class="big center" id="search-form"> <form method="get" action="." class="big center" id="search-form">
{{ form.as_table }}<button class="icon-search"></button> {{ form.as_table }}<button class="icon-search"></button>
</form> </form>
{% if query %} {% if query or selected_tags %}
<nav> <nav>
{% if facets.fields.categories %} {% if facets.fields.categories %}
<ul class="custom padded"> <ul class="custom padded">
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
{% block main %} {% block main %}
{% if query %} {% if query or selected_tags %}
<div class="wrapper"> <div class="wrapper">
<div class="marged"> <div class="marged">
{% if not page.object_list %} {% if not page.object_list %}
......
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