Commit 8cee09e3 authored by fred's avatar fred

browse sounds using format rather than emission categories

parent e8db1239
......@@ -216,10 +216,10 @@ def replace ( string, args ):
return re.sub( search, replace, string )
@register.filter
def remove_tag_facet(url, facet):
def remove_facet(facet_id, url, facet):
scheme, netloc, path, query, fragment = list(urlparse.urlsplit(str(url)))
facet = 'tags_exact:%s' % facet.encode('utf-8')
facet = '%s_exact:%s' % (facet_id, 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)]
......@@ -227,51 +227,46 @@ def remove_tag_facet(url, facet):
url = urlparse.urlunsplit([scheme, netloc, path, query, None])
return re.sub(r'&page=\d+', '', url)
@register.filter
def remove_tag_facet(url, facet):
return remove_facet('tags', url, facet)
@register.filter
def remove_category_facet(url, facet):
scheme, netloc, path, query, fragment = list(urlparse.urlsplit(str(url)))
facet = 'categories_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)
return remove_facet('categories', url, facet)
@register.filter
def remove_news_category_facet(url, facet):
scheme, netloc, path, query, fragment = list(urlparse.urlsplit(str(url)))
facet = 'news_categories_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)
return remove_facet('news_categories', url, facet)
@register.filter
def append_tag_facet(url, facet):
def remove_format_facet(url, facet):
return remove_facet('format', url, facet)
def append_facet(facet_id, url, facet):
facet = urllib2.quote(facet.encode('utf-8'), safe='')
if not '?' in url:
url = url + '?'
return re.sub(r'&page=\d+', '', url + '&selected_facets=tags_exact:%s' % facet)
return re.sub(r'&page=\d+', '', url + '&selected_facets=%s_exact:%s' % (facet_id, facet))
@register.filter
def append_tag_facet(url, facet):
return append_facet('tags', url, facet)
@register.filter
def append_category_facet(url, facet):
facet = urllib2.quote(facet.encode('utf-8'), safe='')
if not '?' in url:
url = url + '?'
return re.sub(r'&page=\d+', '', url + '&selected_facets=categories_exact:%s' % facet)
return append_facet('categories', url, facet)
@register.filter
def append_news_category_facet(url, facet):
facet = urllib2.quote(facet.encode('utf-8'), safe='')
if not '?' in url:
url = url + '?'
return re.sub(r'&page=\d+', '', url + '&selected_facets=news_categories_exact:%s' % facet)
return append_facet('news_categories', url, facet)
@register.filter
def append_format_facet(url, facet):
return append_facet('format', url, facet)
@register.tag
def search_result_template(parser, token):
......
......@@ -174,23 +174,23 @@ class ListenArchivesView(FacetedSearchView):
template = 'listen/archives.html'
def __init__(self):
sqs = RelatedSearchQuerySet().models(SoundFile).facet('categories').facet('tags').order_by('-date')
sqs = RelatedSearchQuerySet().models(SoundFile).facet('format').facet('tags').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"
context['selected_categories'] = [
context['selected_format'] = [
x.split(':', 1)[1] for x in self.request.GET.getlist('selected_facets')
if x.startswith('categories_exact')]
if x.startswith('format_exact')]
context['selected_tags'] = [
x.split(':', 1)[1] for x in self.request.GET.getlist('selected_facets')
if x.startswith('tags_exact')]
if 'categories' in context['facets'].get('fields', []):
context['facets']['fields']['categories'] = [x for x in
context['facets']['fields']['categories'] if x[1] > 0]
context['facets']['fields']['categories'].sort()
if 'format' in context['facets'].get('fields', []):
context['facets']['fields']['format'] = [x for x in
context['facets']['fields']['format'] if x[1] > 0]
context['facets']['fields']['format'].sort()
if 'tags' in context['facets'].get('fields', []):
context['facets']['fields']['tags'] = [x for x in
context['facets']['fields']['tags'] if x[1] > 0]
......
......@@ -3,17 +3,17 @@
{% block title %}Sons - Archives{% endblock %}
{% block nav %}
<div class="search-filters">
{% if facets.fields.categories %}
{% if facets.fields.format %}
<nav>
<ul class="custom padded">
<li><span class="mainLabel">Genre :</span></li>
{% for category in facets.fields.categories %} <li>
{% if category.0 in selected_categories %}
<a class="check icon-check" href="{{ request.get_full_path|remove_category_facet:category.0 }}">
{{ category.0 }} | {{ category.1 }}
<li><span class="mainLabel">Format :</span></li>
{% for format in facets.fields.format %} <li>
{% if format.0 in selected_format %}
<a class="check icon-check" href="{{ request.get_full_path|remove_format_facet:format.0 }}">
{{ format.0 }} <span class="smooth">| {{ format.1 }}</span>
</a>
{% else %}
<a class="check icon-check-empty" href="{{ request.get_full_path|append_category_facet:category.0 }}">{{ category.0 }} | {{ category.1 }}</a></span>
<a class="check icon-check-empty" href="{{ request.get_full_path|append_format_facet:format.0 }}">{{ format.0 }} <span class="smooth">| {{ format.1 }}</span></a></span>
{% endif %}
</li>
{% endfor %}
......
......@@ -27,16 +27,14 @@
<a href="{% url 'episode-view' emission_slug=soundfile.episode.emission.slug slug=soundfile.episode.slug %}">{{ soundfile.episode.title }}</a>
</h5>
<div class="smooth metas">
<h5 class="title inBlock">
<a href="{% url 'emission-view' slug=soundfile.episode.emission.slug %}">{{ soundfile.episode.emission.title }}</a>
</h5>
{% if soundfile.episode.emission.categories %}
{% if soundfile.format %}
<span class="categories">
{% for category in soundfile.episode.emission.categories.all %}
{% if forloop.counter > 1 %} - {% endif %}<span class="category">{{category}}</span>
{% endfor%}
<span class="category">{{ soundfile.format.title }}</span>
</span>
{% endif %}
<h5 class="title inBlock">
<a href="{% url 'emission-view' slug=soundfile.episode.emission.slug %}">{{ soundfile.episode.emission.title }}</a>
</h5>
</div>
</div>
......
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