Commit 6895c302 authored by fred's avatar fred

add search

parent e758abcf
import re
import urllib2
import uuid
from django import template
......@@ -44,3 +46,25 @@ def news_inline(content=None, klass=None, logo=None):
'class': klass,
'logo': logo
}
@register.filter
def remove_tag_facet(url, facet):
facet = urllib2.quote(facet.encode('utf-8'), safe='')
return re.sub(r'&page=\d+', '', url.replace('&selected_facets=tags_exact:%s' % facet, ''))
@register.filter
def remove_category_facet(url, facet):
facet = urllib2.quote(facet.encode('utf-8'), safe='')
return re.sub(r'&page=\d+', '', url.replace('&selected_facets=categories_exact:%s' % facet, ''))
@register.filter
def append_tag_facet(url, facet):
facet = urllib2.quote(facet.encode('utf-8'), safe='')
return re.sub(r'&page=\d+', '', url + '&selected_facets=tags_exact:%s' % facet)
@register.filter
def append_category_facet(url, facet):
facet = urllib2.quote(facet.encode('utf-8'), safe='')
return re.sub(r'&page=\d+', '', url + '&selected_facets=categories_exact:%s' % facet)
from haystack.views import search_view_factory, FacetedSearchView
from haystack.forms import FacetedSearchForm
from haystack.query import SearchQuerySet
class SearchView(FacetedSearchView):
def extra_context(self):
context = super(SearchView, 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
sqs = SearchQuerySet().facet('categories').facet('tags')
view = search_view_factory(SearchView,
form_class=FacetedSearchForm,
searchqueryset=sqs)
......@@ -20,6 +20,8 @@ urlpatterns = patterns('',
url(r'^news/$', 'panikweb.views.news', name='news'),
url(r'^news/(?P<slug>[\w,-]+)$', 'panikweb.views.newsitem', name='news-view'),
url(r'^search/', 'panikweb.search.view', name='search'),
(r'^api/v2/', include('fiber.rest_api.urls')),
(r'^admin/fiber/', include('fiber.admin_urls')),
(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', {'packages': ('fiber',),}),
......
......@@ -489,4 +489,29 @@ body { font-size: 16px;}
#Panik {padding-top:1em}
#Panik *{color:black !important;border-bottom:2px solid black;}
#Listen.small-player ul.metas { display: none; }
#Listen.small-player div.content { padding: 5px 5%; }
ul.tag-facets {
font-size: 80%;
text-transform: lowercase;
font-family: "Reglo";
}
ul#search-results li {
margin: 0.5ex;
}
ul#search-results li.previous-page {
margin-bottom: 2ex;
text-align: left;
margin-left: 0ex;
font-style: italic;
}
ul#search-results li.next-page {
margin-top: 2ex;
text-align: right;
margin-right: 0;
font-style: italic;
}
......@@ -30,7 +30,7 @@
<h1>Radio Panik 105.4 FM</h1>
<!--{% block logo %}<img class="logo" src="{{ STATIC_URL }}/img/LogoPanik.jpg"/>{% endblock %}-->
</div>
<div id="Listen">
<div id="Listen" class="{% block player-class %}{% endblock %}">
{% block listen %}{% player %}{% endblock %}
</div>
......
......@@ -34,6 +34,11 @@
<span class="icon-info-sign" ></span>
<span class="iconLabel">About</span>
</a></li>
<li><form id="search" action="{% url 'search' %}">
<span class="icon-search" ></span>
<input name="q" type="search" class="iconLabel" placeholder="Rechercher..."></input>
</form></li>
</ul>
</div>
</nav>
{% extends 'panikdb/base.html' %}
{% load paniktags %}
{% block player-class %}small-player{% endblock %}
{% block nav %}
{% if query %}
<nav id="gridNav">
{% if facets.fields.categories %}
<ul>
{# Provide only the top 5 categories #}
{% for category in facets.fields.categories|slice:":5" %}
<li>
{% if category.0 in selected_categories %}
<strong><a href="{{ request.get_full_path|remove_category_facet:category.0 }}">{{ category.0 }}</a></strong> ({{ category.1 }})
{% else %}
<span><a href="{{ request.get_full_path|append_category_facet:category.0 }}">{{ category.0 }}</a> ({{ category.1 }})</span>
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
{% if facets.fields.tags %}
<ul class="tag-facets">
{# Provide only the top 5 tags #}
{% for tag in facets.fields.tags|slice:":20" %}
<li>
{% if tag.0 in selected_tags %}
<strong><a href="{{ request.get_full_path|remove_tag_facet:tag.0 }}">{{ tag.0 }}</a></strong> ({{ tag.1 }})
{% else %}
<span><a href="{{ request.get_full_path|append_tag_facet:tag.0 }}">{{ tag.0 }}</a> ({{ tag.1 }})</span>
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
</nav>
{% endif %}
{% endblock %}
{% block main %}
{% if not query %}
<h2>Recherche</h2>
<form method="get" action=".">
<table>
{{ form.as_table }}
<tr>
<td>&nbsp;</td>
<td>
<input type="submit" value="Rechercher">
</td>
</tr>
</table>
</form>
{% else %}
<ul id="search-results" class="list columns padded">
{% if page.has_previous %}
<li class="previous-page"><a href="?q={{ query }}&amp;page={{ page.previous_page_number }}">&laquo; Résultats précédénts</a></li>
{% endif %}
{% for result in page.object_list %}
<li>
{% if result.model_name == "episode" %}
<a href="{% url 'episode-view' emission_slug=result.object.emission.slug slug=result.object.slug %}">
{{ result.object.emission.title }}
{{ result.object.title }}
</a>
{% elif result.model_name == "emission" %}
<a href="{% url 'emission-view' slug=result.object.slug %}">
{{ result.object.title }}
</a>
{% else %}
{{ result.object.title }}
{% endif %}
</li>
{% endfor %}
{% if page.has_next %}
<li class="next-page"><a href="?q={{ query }}&amp;page={{ page.next_page_number }}">Résultats suivants &raquo;</a></li>
{% endif %}
</ul>
{% endif %}
{% endblock %}
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