Commit 1262807e authored by fred's avatar fred

sounds: add a facet for tags

parent 9777837d
......@@ -214,8 +214,15 @@ def replace ( string, args ):
@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, ''))
scheme, netloc, path, query, fragment = list(urlparse.urlsplit(str(url)))
facet = 'tags_exact:%s' % facet.encode('utf-8')
query_string = urlparse.parse_qsl(query)
query_string = [x for x in query_string if not (
x[0] == 'selected_facets' and x[1] == facet)]
query = '&'.join(['%s=%s' % x for x in query_string])
url = urlparse.urlunsplit([scheme, netloc, path, query, None])
return re.sub(r'&page=\d+', '', url)
@register.filter
def remove_category_facet(url, facet):
......
......@@ -163,7 +163,7 @@ class ListenArchivesView(FacetedSearchView):
template = 'listen/archives.html'
def __init__(self):
sqs = RelatedSearchQuerySet().models(SoundFile).facet('categories').order_by('-date')
sqs = RelatedSearchQuerySet().models(SoundFile).facet('categories').facet('tags').order_by('-date')
super(ListenArchivesView, self).__init__(searchqueryset=sqs,
form_class=ListenArchivesForm, results_per_page=20)
......@@ -173,6 +173,9 @@ class ListenArchivesView(FacetedSearchView):
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')]
context['facets']['fields']['categories'].sort()
return context
......
......@@ -11,12 +11,10 @@ pri, ei viris quaestio concludaturque qui, cu copiosae senserit quo. Cu dictas
officiis has, hinc libris aliquam pro te.
</p>
{% if facets.fields.categories %}
<nav>
{% if facets.fields.categories %}
<ul class="custom padded">
{% if facets.fields.categories %}
<li><span class="mainLabel">Genre :</span></li>
{% endif %}
{% for category in facets.fields.categories %} <li>
{% if category.0 in selected_categories %}
<a class="check icon-check count-{{ category.1 }}" href="{{ request.get_full_path|remove_category_facet:category.0 }}">
......@@ -28,8 +26,27 @@ officiis has, hinc libris aliquam pro te.
</li>
{% endfor %}
</ul>
{% endif %}
</nav>
{% endif %}
{% if facets.fields.tags %}
<nav>
<ul class="tag-facets custom padded">
<li><span class="mainLabel">Mots clés :</span></li>
{% for tag in facets.fields.tags|slice:":20" %} {# Provide only the top 20 tags #}
<li>
{% if tag.0 in selected_tags %}
<a class="check icon-check count-{{ tag.1 }}" href="{{ request.get_full_path|remove_tag_facet:tag.0 }}">
{{ tag.0 }} <span class="smooth">| {{ tag.1 }}</span>
</a>
{% else %}
<a class="check icon-check-empty count-{{ tag.1 }}" href="{{ request.get_full_path|append_tag_facet:tag.0 }}">{{ tag.0 }} <span class="smooth">| {{ tag.1 }}</span></a>
{% endif %}
</li>
{% endfor %}
</ul>
</nav>
{% endif %}
{% endblock %}
......@@ -39,6 +56,9 @@ officiis has, hinc libris aliquam pro te.
{% for category in selected_categories %}
<input type="hidden" name="selected_facets" value="categories_exact:{{category}}"/>
{% endfor %}
{% for tag in selected_tags %}
<input type="hidden" name="selected_facets" value="tags_exact:{{tag}}"/>
{% endfor %}
{{ form.as_table }}<button class="icon-search"></button>
</div>
</form>
......
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