recherche: Majuscule aux facettes
[auf_framonde.git] / project / framonde / templatetags / auf.py
CommitLineData
099e7f84
PH
1# encoding: utf-8
2
3from django.utils.http import urlunquote, urlquote
4from django.utils.encoding import smart_text
5from django import template
6
7register = template.Library()
8
9
10@register.simple_tag(takes_context=True, name="show_facet")
11def do_show_facet(context, facet_name):
12 html = ""
13 if not 'fields' in context['facets']:
14 facets = []
15 else:
16 facets = context['facets']['fields'][facet_name]
17 selected_facets = context['form']['selected_facets'].value()
18 if not selected_facets:
19 selected_facets = []
20
21 path = context['request'].get_full_path()
22
23 for f in facets:
24 long_facet_name = "__".join([facet_name, urlquote(f[0])])
25
26 if urlunquote(long_facet_name) in selected_facets:
27 html += "<dd><a href='%s'><input onclick='window.location=\"%s\"; return true;'type='checkbox' checked='checked'/> %s</a> (%s)</dd>" % (path.replace(
28 "&selected_facets=" + long_facet_name,
29 "").replace(
30 "?selected_facets=" + long_facet_name,
31 "?"),
32 path.replace(
33 "&selected_facets=" + long_facet_name,
34 "").replace(
35 "?selected_facets=" + long_facet_name,
36 "?"),
37 smart_text(
514b9ced 38 f[0]).capitalize(), f[1])
099e7f84
PH
39 else:
40 if path.endswith('/'):
41 html += "<dd><a href='%s?selected_facets=%s'><input onclick='window.location=\"%s?selected_facets=%s\"; return true;'type='checkbox' />%s</a> (%s)</dd>" % (
514b9ced 42 path, long_facet_name, path, long_facet_name, smart_text(f[0]).capitalize(), f[1])
099e7f84
PH
43 else:
44 html += "<dd><a href='%s&selected_facets=%s'><input onclick='window.location=\"%s&selected_facets=%s\"; return true;'type='checkbox' /> %s</a> (%s)</dd>" % (
514b9ced 45 path, long_facet_name, path, long_facet_name, smart_text(f[0]).capitalize(), f[1])
099e7f84
PH
46 return html
47