-
Notifications
You must be signed in to change notification settings - Fork 2k
/
facets.html
186 lines (152 loc) · 6.7 KB
/
facets.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/"
xmlns:xi="http://www.w3.org/2001/XInclude"
py:strip=""
>
<!--
Construct a facet <div> populated with links to filtered results.
name
The field name identifying the facet field, eg. "tags"
title
The title of the facet, eg. "Tags", or "Tag Cloud"
label_function
Renders the human-readable label for each facet value.
If defined, this should be a callable that accepts a `facet_item`.
eg. lambda facet_item: facet_item.display_name.upper()
By default it displays the facet item's display name, which should
usually be good enough
if_empty
A string, which if defined, and the list of possible facet items is empty,
is displayed in lieu of an empty list.
count_label
A callable which accepts an integer, and returns a string. This controls
how a facet-item's count is displayed.
-->
<py:def function="facet_div(name, title, limit=5, label_function=lambda item: item.display_name, if_empty=None, count_label=lambda c: ' (%d)'%c)">
<div py:if="if_empty is not None or h.new_facet_items(name, limit)" class="facet-box">
<h2>${h.facet_title(title)}</h2>
<ul class="facet-options">
${facet_li(name, limit=limit, label_function=label_function, if_empty=None, count_label=count_label)}
</ul>
<p py:if="not h.new_facet_items(name, limit)">${if_empty}</p>
</div>
</py:def>
<!--
Generate <li>s for facet items. The generated tags are not wrapped by any
other tag, ie - it's up to the caller to wrap them in something suitable.
name
The field name identifying the facet field, eg. "tags"
label_function
Renders the human-readable label for each facet value.
If defined, this should be a callable that accepts a `facet_item`.
eg. lambda facet_item: facet_item.display_name.upper()
By default it displays the facet item's display name, which should
usually be good enough
if_empty
A string, which if defined, and the list of possible facet items is empty,
is displayed in a <li> tag in lieu of an empty list.
count_label
A callable which accepts an integer, and returns a string. This controls
how a facet-item's count is displayed.
-->
<py:def function="facet_li(name, limit=5, label_function=lambda item: item.display_name, if_empty=None, count_label=lambda c: ' (%d)'%c)">
<li py:if="if_empty and not h.new_facet_items(name, limit)">${if_empty}</li>
<li py:for="facet_item in h.new_facet_items(name, limit)">
<a href="${c.drill_down_url(**{name: facet_item.name})}">
${label_function(facet_item)}
</a>
${count_label(facet_item['count'])}
</li>
</py:def>
<!--
DEPRECATED. Provided only for backward compatibility with existing plugins.
Use `facet_div` instead.
Similar to the above, `facet_div` function; this helper creates a <div>
populated with links to filtered search results.
Differences with the preferred `facet_div` function:
* `title` argument is a callable
* `label` is a callable that accepts a string cf. `label_function` which is
a callable that accepts a `facet_item`.
code
The field name identifying the facet field, eg. "tags"
title
A callable used to render the title for the facet. The callable must accept
one string argument, the `code` argument passed in above. Obviously, this
is a bit redundant.
label
Renders the human-readable label for each facet value.
If defined, this should be a callable that accepts a facet_item's name as a
string.
if_empty
A string, which if defined, and the list of possible facet items is empty,
is displayed in lieu of an empty list.
count_label
A callable which accepts an integer, and returns a string. This controls
how a facet-item's count is displayed.
-->
<py:def function="facet_sidebar(code, limit=5, label=lambda n: n, title=h.facet_title, if_empty=None, count_label=lambda c: ' (%d)'%c)">
<?python
import logging
logging.getLogger('ckan.templates.facets').warning("Deprecated function: ckan/templates/facets.html:facet_sidebar()")
?>
<div py:if="if_empty is not None or h.new_facet_items(code, limit)" class="facet-box">
<h2>${title(code)}</h2>
<ul class="facet-options">
<li py:for="facet_item in h.new_facet_items(code, limit)"
py:if="not (code, facet_item.name) in c.fields">
<a href="${c.drill_down_url(**{code: facet_item.name})}">
<span py:if="'format' in code.lower()">${h.icon(h.format_icon(facet_item.name))}</span>
${label(facet_item.name)}</a>${count_label(facet_item['count'])}
</li>
</ul>
<p py:if="not h.new_facet_items(code, limit)">${if_empty}</p>
</div>
</py:def>
<!--
DEPRECATED. Provided only for backward compatibility with existing plugins.
Use `facet_li` instead.
Construct a possibly empty list of <li> elements containing links to further
search results
This is different from `facet_sidebar` and `facet_div` (above) in that it
requires the caller to wrap up the resulting <li> elements in whatever dom
element they need. But it *does* allow for filters to displayed in a
hierarchy.
label
Renders the human-readable label for each facet value.
If defined, this should be a callable that accepts a facet_item's name as a
string.
if_empty
If if_empty is not None and there are no facets to filter on, then a single
<li> element is generated, with the text specified by if_empty
-->
<py:def function="facet_list_items(code, limit=5, label=lambda n: n, if_empty=None)">
<?python
import logging
logging.getLogger('ckan.templates.facets').warning("Deprecated function:ckan/templates/facets.html:facet_list_items()")
?>
<li py:if="if_empty and not h.new_facet_items(code, limit)">${if_empty}</li>
<li py:for="facet_item in h.new_facet_items(code, limit)"
py:if="not (code, facet_item.name) in c.fields">
<a href="${c.drill_down_url(**{code: facet_item.name})}">${label(facet_item.name)}</a> (facet_item['count'])
</li>
</py:def>
<py:def function="field_list()">
<div class="filter-list" py:if="c.fields">
<div class="filter-entry" py:for="(field, value) in c.fields">
<span class="name">${h.facet_title(field)}</span>
<span class="value" py:choose="">
<py:when test="c.translated_fields and c.translated_fields.has_key((field,value))">
${c.translated_fields[(field,value)]}
</py:when>
<py:otherwise>
${value}
</py:otherwise>
</span>
<a href="${c.remove_field(field, value)}">
${h.icon('unfilter')}
</a>
</div>
</div>
</py:def>
</html>