author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 05 Feb 2010 11:57:52 +0100 | |
changeset 4468 | f958628cadc1 |
parent 4466 | 8b0ca7904820 |
child 4546 | f8ac61376b2b |
permissions | -rw-r--r-- |
0 | 1 |
"""contains utility functions and some visual component to restrict results of |
2 |
a search |
|
3 |
||
4 |
:organization: Logilab |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
5 |
:copyright: 2008-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1933
diff
changeset
|
7 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 8 |
""" |
9 |
__docformat__ = "restructuredtext en" |
|
10 |
||
11 |
from itertools import chain |
|
12 |
from copy import deepcopy |
|
2152 | 13 |
from datetime import date, datetime, timedelta |
0 | 14 |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
15 |
from logilab.mtconverter import xml_escape |
0 | 16 |
from logilab.common.graph import has_path |
17 |
from logilab.common.decorators import cached |
|
4466
8b0ca7904820
moved generic datetime manipulation function to lgc
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4333
diff
changeset
|
18 |
from logilab.common.date import datetime2ticks, ustrftime |
0 | 19 |
from logilab.common.compat import all |
20 |
||
21 |
from rql import parse, nodes |
|
22 |
||
23 |
from cubicweb import Unauthorized, typed_eid |
|
2305
8f6dbe884700
import display_name
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2152
diff
changeset
|
24 |
from cubicweb.schema import display_name |
4466
8b0ca7904820
moved generic datetime manipulation function to lgc
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4333
diff
changeset
|
25 |
from cubicweb.utils import make_uid |
838
f2c56312b03a
rename abstract_* selectors into partial_* + add docstrings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
782
diff
changeset
|
26 |
from cubicweb.selectors import match_context_prop, partial_relation_possible |
2656
a93ae0f6c0ad
R [base classes] only AppObject remaning, no more AppRsetObject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
27 |
from cubicweb.appobject import AppObject |
0 | 28 |
from cubicweb.web.htmlwidgets import HTMLWidget |
29 |
||
30 |
## rqlst manipulation functions used by facets ################################ |
|
31 |
||
32 |
def prepare_facets_rqlst(rqlst, args=None): |
|
33 |
"""prepare a syntax tree to generate facet filters |
|
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
34 |
|
0 | 35 |
* remove ORDERBY clause |
36 |
* cleanup selection (remove everything) |
|
37 |
* undefine unnecessary variables |
|
38 |
* set DISTINCT |
|
39 |
* unset LIMIT/OFFSET |
|
40 |
""" |
|
41 |
if len(rqlst.children) > 1: |
|
42 |
raise NotImplementedError('FIXME: union not yet supported') |
|
43 |
select = rqlst.children[0] |
|
44 |
mainvar = filtered_variable(select) |
|
45 |
select.set_limit(None) |
|
46 |
select.set_offset(None) |
|
47 |
baserql = select.as_string(kwargs=args) |
|
48 |
# cleanup sort terms |
|
49 |
select.remove_sort_terms() |
|
50 |
# selection: only vocabulary entity |
|
51 |
for term in select.selection[:]: |
|
52 |
select.remove_selected(term) |
|
53 |
# remove unbound variables which only have some type restriction |
|
54 |
for dvar in select.defined_vars.values(): |
|
55 |
if not (dvar is mainvar or dvar.stinfo['relations']): |
|
56 |
select.undefine_variable(dvar) |
|
57 |
# global tree config: DISTINCT, LIMIT, OFFSET |
|
58 |
select.set_distinct(True) |
|
59 |
return mainvar, baserql |
|
60 |
||
61 |
def filtered_variable(rqlst): |
|
62 |
vref = rqlst.selection[0].iget_nodes(nodes.VariableRef).next() |
|
63 |
return vref.variable |
|
64 |
||
65 |
||
66 |
def get_facet(req, facetid, rqlst, mainvar): |
|
4333
7add8a73a168
[vreg] object_by_id should not have been deprecated. Fix facets.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
67 |
return req.vreg['facets'].object_by_id(facetid, req, rqlst=rqlst, |
7add8a73a168
[vreg] object_by_id should not have been deprecated. Fix facets.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
68 |
filtered_variable=mainvar) |
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
69 |
|
0 | 70 |
|
71 |
def filter_hiddens(w, **kwargs): |
|
72 |
for key, val in kwargs.items(): |
|
73 |
w(u'<input type="hidden" name="%s" value="%s" />' % ( |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
74 |
key, xml_escape(val))) |
0 | 75 |
|
76 |
||
77 |
def _may_be_removed(rel, schema, mainvar): |
|
78 |
"""if the given relation may be removed from the tree, return the variable |
|
79 |
on the other side of `mainvar`, else return None |
|
80 |
Conditions: |
|
81 |
* the relation is an attribute selection of the main variable |
|
82 |
* the relation is optional relation linked to the main variable |
|
83 |
* the relation is a mandatory relation linked to the main variable |
|
84 |
without any restriction on the other variable |
|
85 |
""" |
|
86 |
lhs, rhs = rel.get_variable_parts() |
|
87 |
rschema = schema.rschema(rel.r_type) |
|
88 |
if lhs.variable is mainvar: |
|
89 |
try: |
|
90 |
ovar = rhs.variable |
|
91 |
except AttributeError: |
|
92 |
# constant restriction |
|
93 |
# XXX: X title LOWER(T) if it makes sense? |
|
94 |
return None |
|
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3333
diff
changeset
|
95 |
if rschema.final: |
0 | 96 |
if len(ovar.stinfo['relations']) == 1: |
97 |
# attribute selection |
|
98 |
return ovar |
|
99 |
return None |
|
100 |
opt = 'right' |
|
101 |
cardidx = 0 |
|
102 |
elif getattr(rhs, 'variable', None) is mainvar: |
|
103 |
ovar = lhs.variable |
|
104 |
opt = 'left' |
|
105 |
cardidx = 1 |
|
106 |
else: |
|
107 |
# not directly linked to the main variable |
|
108 |
return None |
|
109 |
if rel.optional in (opt, 'both'): |
|
110 |
# optional relation |
|
111 |
return ovar |
|
4073
03681ba6da0b
cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3720
diff
changeset
|
112 |
if all(rdef.cardinality[cardidx] in '1+' |
03681ba6da0b
cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3720
diff
changeset
|
113 |
for rdef in rschema.rdefs.values()): |
0 | 114 |
# mandatory relation without any restriction on the other variable |
115 |
for orel in ovar.stinfo['relations']: |
|
116 |
if rel is orel: |
|
117 |
continue |
|
118 |
if _may_be_removed(orel, schema, ovar) is None: |
|
119 |
return None |
|
120 |
return ovar |
|
121 |
return None |
|
122 |
||
123 |
def _add_rtype_relation(rqlst, mainvar, rtype, role): |
|
1149 | 124 |
"""add a relation relying `mainvar` to entities linked by the `rtype` |
125 |
relation (where `mainvar` has `role`) |
|
126 |
||
127 |
return the inserted variable for linked entities. |
|
128 |
""" |
|
0 | 129 |
newvar = rqlst.make_variable() |
130 |
if role == 'object': |
|
1149 | 131 |
rqlst.add_relation(newvar, rtype, mainvar) |
0 | 132 |
else: |
1149 | 133 |
rqlst.add_relation(mainvar, rtype, newvar) |
134 |
return newvar |
|
0 | 135 |
|
136 |
def _prepare_vocabulary_rqlst(rqlst, mainvar, rtype, role): |
|
137 |
"""prepare a syntax tree to generate a filter vocabulary rql using the given |
|
138 |
relation: |
|
139 |
* create a variable to filter on this relation |
|
140 |
* add the relation |
|
141 |
* add the new variable to GROUPBY clause if necessary |
|
142 |
* add the new variable to the selection |
|
143 |
""" |
|
1149 | 144 |
newvar = _add_rtype_relation(rqlst, mainvar, rtype, role) |
0 | 145 |
if rqlst.groupby: |
146 |
rqlst.add_group_var(newvar) |
|
147 |
rqlst.add_selected(newvar) |
|
1149 | 148 |
return newvar |
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
149 |
|
0 | 150 |
def _remove_relation(rqlst, rel, var): |
151 |
"""remove a constraint relation from the syntax tree""" |
|
152 |
# remove the relation |
|
153 |
rqlst.remove_node(rel) |
|
154 |
# remove relations where the filtered variable appears on the |
|
155 |
# lhs and rhs is a constant restriction |
|
156 |
extra = [] |
|
157 |
for vrel in var.stinfo['relations']: |
|
158 |
if vrel is rel: |
|
159 |
continue |
|
160 |
if vrel.children[0].variable is var: |
|
161 |
if not vrel.children[1].get_nodes(nodes.Constant): |
|
162 |
extra.append(vrel) |
|
163 |
rqlst.remove_node(vrel) |
|
164 |
return extra |
|
165 |
||
166 |
def _set_orderby(rqlst, newvar, sortasc, sortfuncname): |
|
167 |
if sortfuncname is None: |
|
168 |
rqlst.add_sort_var(newvar, sortasc) |
|
169 |
else: |
|
170 |
vref = nodes.variable_ref(newvar) |
|
171 |
vref.register_reference() |
|
172 |
sortfunc = nodes.Function(sortfuncname) |
|
173 |
sortfunc.append(vref) |
|
174 |
term = nodes.SortTerm(sortfunc, sortasc) |
|
175 |
rqlst.add_sort_term(term) |
|
176 |
||
177 |
def insert_attr_select_relation(rqlst, mainvar, rtype, role, attrname, |
|
178 |
sortfuncname=None, sortasc=True): |
|
3329
8430f6c693a1
cleanup, smarter sort control to avoid it when not necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3328
diff
changeset
|
179 |
"""modify a syntax tree to : |
8430f6c693a1
cleanup, smarter sort control to avoid it when not necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3328
diff
changeset
|
180 |
* link a new variable to `mainvar` through `rtype` (where mainvar has `role`) |
8430f6c693a1
cleanup, smarter sort control to avoid it when not necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3328
diff
changeset
|
181 |
* retrieve only the newly inserted variable and its `attrname` |
8430f6c693a1
cleanup, smarter sort control to avoid it when not necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3328
diff
changeset
|
182 |
|
8430f6c693a1
cleanup, smarter sort control to avoid it when not necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3328
diff
changeset
|
183 |
Sorting: |
8430f6c693a1
cleanup, smarter sort control to avoid it when not necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3328
diff
changeset
|
184 |
* on `attrname` ascendant (`sortasc`=True) or descendant (`sortasc`=False) |
8430f6c693a1
cleanup, smarter sort control to avoid it when not necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3328
diff
changeset
|
185 |
* on `sortfuncname`(`attrname`) if `sortfuncname` is specified |
8430f6c693a1
cleanup, smarter sort control to avoid it when not necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3328
diff
changeset
|
186 |
* no sort if `sortasc` is None |
8430f6c693a1
cleanup, smarter sort control to avoid it when not necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3328
diff
changeset
|
187 |
""" |
0 | 188 |
_cleanup_rqlst(rqlst, mainvar) |
1149 | 189 |
var = _prepare_vocabulary_rqlst(rqlst, mainvar, rtype, role) |
0 | 190 |
# not found, create one |
191 |
attrvar = rqlst.make_variable() |
|
1149 | 192 |
rqlst.add_relation(var, attrname, attrvar) |
0 | 193 |
# if query is grouped, we have to add the attribute variable |
194 |
if rqlst.groupby: |
|
195 |
if not attrvar in rqlst.groupby: |
|
196 |
rqlst.add_group_var(attrvar) |
|
3329
8430f6c693a1
cleanup, smarter sort control to avoid it when not necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3328
diff
changeset
|
197 |
if sortasc is not None: |
8430f6c693a1
cleanup, smarter sort control to avoid it when not necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3328
diff
changeset
|
198 |
_set_orderby(rqlst, attrvar, sortasc, sortfuncname) |
0 | 199 |
# add attribute variable to selection |
200 |
rqlst.add_selected(attrvar) |
|
201 |
# add is restriction if necessary |
|
202 |
if not mainvar.stinfo['typerels']: |
|
203 |
etypes = frozenset(sol[mainvar.name] for sol in rqlst.solutions) |
|
204 |
rqlst.add_type_restriction(mainvar, etypes) |
|
205 |
return var |
|
206 |
||
207 |
def _cleanup_rqlst(rqlst, mainvar): |
|
208 |
"""cleanup tree from unnecessary restriction: |
|
209 |
* attribute selection |
|
210 |
* optional relations linked to the main variable |
|
211 |
* mandatory relations linked to the main variable |
|
212 |
""" |
|
213 |
if rqlst.where is None: |
|
214 |
return |
|
215 |
schema = rqlst.root.schema |
|
216 |
toremove = set() |
|
217 |
vargraph = deepcopy(rqlst.vargraph) # graph representing links between variable |
|
218 |
for rel in rqlst.where.get_nodes(nodes.Relation): |
|
219 |
ovar = _may_be_removed(rel, schema, mainvar) |
|
220 |
if ovar is not None: |
|
221 |
toremove.add(ovar) |
|
222 |
removed = set() |
|
223 |
while toremove: |
|
224 |
trvar = toremove.pop() |
|
225 |
trvarname = trvar.name |
|
226 |
# remove paths using this variable from the graph |
|
227 |
linkedvars = vargraph.pop(trvarname) |
|
228 |
for ovarname in linkedvars: |
|
229 |
vargraph[ovarname].remove(trvarname) |
|
230 |
# remove relation using this variable |
|
231 |
for rel in chain(trvar.stinfo['relations'], trvar.stinfo['typerels']): |
|
232 |
if rel in removed: |
|
233 |
# already removed |
|
234 |
continue |
|
235 |
rqlst.remove_node(rel) |
|
236 |
removed.add(rel) |
|
237 |
# cleanup groupby clause |
|
238 |
if rqlst.groupby: |
|
239 |
for vref in rqlst.groupby[:]: |
|
240 |
if vref.name == trvarname: |
|
241 |
rqlst.remove_group_var(vref) |
|
242 |
# we can also remove all variables which are linked to this variable |
|
243 |
# and have no path to the main variable |
|
244 |
for ovarname in linkedvars: |
|
408
a8814ff6824e
reactivate tests and fix bug triggering removal of undesired relation (eg type restriction) in some cases
sylvain.thenault@logilab.fr
parents:
407
diff
changeset
|
245 |
if ovarname == mainvar.name: |
a8814ff6824e
reactivate tests and fix bug triggering removal of undesired relation (eg type restriction) in some cases
sylvain.thenault@logilab.fr
parents:
407
diff
changeset
|
246 |
continue |
0 | 247 |
if not has_path(vargraph, ovarname, mainvar.name): |
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
248 |
toremove.add(rqlst.defined_vars[ovarname]) |
0 | 249 |
|
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
250 |
|
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
251 |
|
0 | 252 |
## base facet classes ######################################################### |
2656
a93ae0f6c0ad
R [base classes] only AppObject remaning, no more AppRsetObject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
253 |
class AbstractFacet(AppObject): |
0 | 254 |
__abstract__ = True |
255 |
__registry__ = 'facets' |
|
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2770
diff
changeset
|
256 |
cw_property_defs = { |
0 | 257 |
_('visible'): dict(type='Boolean', default=True, |
258 |
help=_('display the box or not')), |
|
259 |
_('order'): dict(type='Int', default=99, |
|
260 |
help=_('display order of the box')), |
|
496
e25a3c2f5393
set default to empty string, not None
sylvain.thenault@logilab.fr
parents:
467
diff
changeset
|
261 |
_('context'): dict(type='String', default='', |
0 | 262 |
# None <-> both |
446
3a3ab6bbccc5
use empty string instead of None as possible context value to avoid getting an <optgroup> tag in associated widget
sylvain.thenault@logilab.fr
parents:
408
diff
changeset
|
263 |
vocabulary=(_('tablefilter'), _('facetbox'), ''), |
0 | 264 |
help=_('context where this box should be displayed')), |
265 |
} |
|
266 |
visible = True |
|
446
3a3ab6bbccc5
use empty string instead of None as possible context value to avoid getting an <optgroup> tag in associated widget
sylvain.thenault@logilab.fr
parents:
408
diff
changeset
|
267 |
context = '' |
0 | 268 |
needs_update = False |
269 |
start_unfolded = True |
|
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
270 |
|
2658
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
271 |
def __init__(self, req, rset=None, rqlst=None, filtered_variable=None, |
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
272 |
**kwargs): |
2890
fdcb8a2bb6eb
fix __init__ parameters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2799
diff
changeset
|
273 |
super(AbstractFacet, self).__init__(req, rset=rset, **kwargs) |
0 | 274 |
assert rset is not None or rqlst is not None |
275 |
assert filtered_variable |
|
276 |
# facet retreived using `object_by_id` from an ajax call |
|
277 |
if rset is None: |
|
2658
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
278 |
self.init_from_form(rqlst=rqlst) |
0 | 279 |
# facet retreived from `select` using the result set to filter |
280 |
else: |
|
2658
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
281 |
self.init_from_rset() |
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
282 |
self.filtered_variable = filtered_variable |
0 | 283 |
|
284 |
def init_from_rset(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
285 |
self.rqlst = self.cw_rset.syntax_tree().children[0] |
0 | 286 |
|
287 |
def init_from_form(self, rqlst): |
|
288 |
self.rqlst = rqlst |
|
289 |
||
290 |
@property |
|
291 |
def operator(self): |
|
292 |
# OR between selected values by default |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
293 |
return self._cw.form.get(self.__regid__ + '_andor', 'OR') |
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
294 |
|
0 | 295 |
def get_widget(self): |
296 |
"""return the widget instance to use to display this facet |
|
297 |
""" |
|
298 |
raise NotImplementedError |
|
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
299 |
|
0 | 300 |
def add_rql_restrictions(self): |
301 |
"""add restriction for this facet into the rql syntax tree""" |
|
302 |
raise NotImplementedError |
|
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
303 |
|
0 | 304 |
|
305 |
class VocabularyFacet(AbstractFacet): |
|
306 |
needs_update = True |
|
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
307 |
|
0 | 308 |
def get_widget(self): |
309 |
"""return the widget instance to use to display this facet |
|
310 |
||
311 |
default implentation expects a .vocabulary method on the facet and |
|
312 |
return a combobox displaying this vocabulary |
|
313 |
""" |
|
314 |
vocab = self.vocabulary() |
|
315 |
if len(vocab) <= 1: |
|
316 |
return None |
|
317 |
wdg = FacetVocabularyWidget(self) |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
318 |
selected = frozenset(typed_eid(eid) for eid in self._cw.list_form_param(self.__regid__)) |
0 | 319 |
for label, value in vocab: |
320 |
if value is None: |
|
321 |
wdg.append(FacetSeparator(label)) |
|
322 |
else: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
323 |
wdg.append(FacetItem(self._cw, label, value, value in selected)) |
0 | 324 |
return wdg |
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
325 |
|
0 | 326 |
def vocabulary(self): |
327 |
"""return vocabulary for this facet, eg a list of 2-uple (label, value) |
|
328 |
""" |
|
329 |
raise NotImplementedError |
|
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
330 |
|
0 | 331 |
def possible_values(self): |
332 |
"""return a list of possible values (as string since it's used to |
|
333 |
compare to a form value in javascript) for this facet |
|
334 |
""" |
|
335 |
raise NotImplementedError |
|
336 |
||
337 |
def support_and(self): |
|
338 |
return False |
|
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
339 |
|
0 | 340 |
def rqlexec(self, rql, args=None, cachekey=None): |
341 |
try: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
342 |
return self._cw.execute(rql, args, cachekey) |
0 | 343 |
except Unauthorized: |
344 |
return [] |
|
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
345 |
|
0 | 346 |
|
347 |
class RelationFacet(VocabularyFacet): |
|
838
f2c56312b03a
rename abstract_* selectors into partial_* + add docstrings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
782
diff
changeset
|
348 |
__select__ = partial_relation_possible() & match_context_prop() |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
722
diff
changeset
|
349 |
# class attributes to configure the rel ation facet |
0 | 350 |
rtype = None |
1433 | 351 |
role = 'subject' |
0 | 352 |
target_attr = 'eid' |
353 |
# set this to a stored procedure name if you want to sort on the result of |
|
354 |
# this function's result instead of direct value |
|
355 |
sortfunc = None |
|
356 |
# ascendant/descendant sorting |
|
357 |
sortasc = True |
|
3328
76888cd23d83
facets enhancement: can now set label_vid to use a view instead of a simple attribute as label
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
358 |
# if you want to call a view on the entity instead of using `target_attr` |
76888cd23d83
facets enhancement: can now set label_vid to use a view instead of a simple attribute as label
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
359 |
label_vid = None |
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
360 |
|
0 | 361 |
@property |
362 |
def title(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
363 |
return display_name(self._cw, self.rtype, form=self.role) |
0 | 364 |
|
365 |
def vocabulary(self): |
|
366 |
"""return vocabulary for this facet, eg a list of 2-uple (label, value) |
|
367 |
""" |
|
368 |
rqlst = self.rqlst |
|
369 |
rqlst.save_state() |
|
3329
8430f6c693a1
cleanup, smarter sort control to avoid it when not necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3328
diff
changeset
|
370 |
if self.label_vid is not None and self.sortfunc is None: |
8430f6c693a1
cleanup, smarter sort control to avoid it when not necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3328
diff
changeset
|
371 |
sort = None # will be sorted on label |
8430f6c693a1
cleanup, smarter sort control to avoid it when not necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3328
diff
changeset
|
372 |
else: |
8430f6c693a1
cleanup, smarter sort control to avoid it when not necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3328
diff
changeset
|
373 |
sort = self.sortasc |
0 | 374 |
try: |
375 |
mainvar = self.filtered_variable |
|
376 |
insert_attr_select_relation(rqlst, mainvar, self.rtype, self.role, |
|
3329
8430f6c693a1
cleanup, smarter sort control to avoid it when not necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3328
diff
changeset
|
377 |
self.target_attr, self.sortfunc, sort) |
346
5bbb01a133ae
add try except to avoid error w/ unsupported stuff, log it and return incomplete filter form
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
203
diff
changeset
|
378 |
try: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
379 |
rset = self.rqlexec(rqlst.as_string(), self.cw_rset.args, self.cw_rset.cachekey) |
346
5bbb01a133ae
add try except to avoid error w/ unsupported stuff, log it and return incomplete filter form
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
203
diff
changeset
|
380 |
except: |
5bbb01a133ae
add try except to avoid error w/ unsupported stuff, log it and return incomplete filter form
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
203
diff
changeset
|
381 |
self.exception('error while getting vocabulary for %s, rql: %s', |
5bbb01a133ae
add try except to avoid error w/ unsupported stuff, log it and return incomplete filter form
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
203
diff
changeset
|
382 |
self, rqlst.as_string()) |
5bbb01a133ae
add try except to avoid error w/ unsupported stuff, log it and return incomplete filter form
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
203
diff
changeset
|
383 |
return () |
0 | 384 |
finally: |
385 |
rqlst.recover() |
|
386 |
return self.rset_vocabulary(rset) |
|
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
387 |
|
0 | 388 |
def possible_values(self): |
389 |
"""return a list of possible values (as string since it's used to |
|
390 |
compare to a form value in javascript) for this facet |
|
391 |
""" |
|
392 |
rqlst = self.rqlst |
|
393 |
rqlst.save_state() |
|
394 |
try: |
|
395 |
_cleanup_rqlst(rqlst, self.filtered_variable) |
|
396 |
_prepare_vocabulary_rqlst(rqlst, self.filtered_variable, self.rtype, self.role) |
|
397 |
return [str(x) for x, in self.rqlexec(rqlst.as_string())] |
|
398 |
finally: |
|
399 |
rqlst.recover() |
|
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
400 |
|
0 | 401 |
def rset_vocabulary(self, rset): |
3328
76888cd23d83
facets enhancement: can now set label_vid to use a view instead of a simple attribute as label
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
402 |
if self.label_vid is None: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
403 |
_ = self._cw._ |
3328
76888cd23d83
facets enhancement: can now set label_vid to use a view instead of a simple attribute as label
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
404 |
return [(_(label), eid) for eid, label in rset] |
76888cd23d83
facets enhancement: can now set label_vid to use a view instead of a simple attribute as label
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
405 |
if self.sortfunc is None: |
76888cd23d83
facets enhancement: can now set label_vid to use a view instead of a simple attribute as label
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
406 |
return sorted((entity.view(self.label_vid), entity.eid) |
76888cd23d83
facets enhancement: can now set label_vid to use a view instead of a simple attribute as label
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
407 |
for entity in rset.entities()) |
76888cd23d83
facets enhancement: can now set label_vid to use a view instead of a simple attribute as label
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
408 |
return [(entity.view(self.label_vid), entity.eid) |
76888cd23d83
facets enhancement: can now set label_vid to use a view instead of a simple attribute as label
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
409 |
for entity in rset.entities()] |
0 | 410 |
|
411 |
@cached |
|
412 |
def support_and(self): |
|
3456
1a63a252601f
[facets] typo fix
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
413 |
rschema = self._cw.vreg.schema.rschema(self.rtype) |
0 | 414 |
# XXX when called via ajax, no rset to compute possible types |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
415 |
possibletypes = self.cw_rset and self.cw_rset.column_types(0) |
4087 | 416 |
for rdef in rschema.rdefs.itervalues(): |
0 | 417 |
if possibletypes is not None: |
418 |
if self.role == 'subject': |
|
4087 | 419 |
if not rdef.subject in possibletypes: |
0 | 420 |
continue |
4087 | 421 |
elif not rdef.object in possibletypes: |
0 | 422 |
continue |
4089
ff92c7d692bf
typos, api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4087
diff
changeset
|
423 |
if rdef.role_cardinality(self.role) in '+*': |
0 | 424 |
return True |
425 |
return False |
|
426 |
||
427 |
def add_rql_restrictions(self): |
|
428 |
"""add restriction for this facet into the rql syntax tree""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
429 |
value = self._cw.form.get(self.__regid__) |
0 | 430 |
if not value: |
431 |
return |
|
432 |
mainvar = self.filtered_variable |
|
1149 | 433 |
restrvar = _add_rtype_relation(self.rqlst, mainvar, self.rtype, self.role) |
0 | 434 |
if isinstance(value, basestring): |
435 |
# only one value selected |
|
436 |
self.rqlst.add_eid_restriction(restrvar, value) |
|
437 |
elif self.operator == 'OR': |
|
438 |
# multiple values with OR operator |
|
439 |
# set_distinct only if rtype cardinality is > 1 |
|
440 |
if self.support_and(): |
|
441 |
self.rqlst.set_distinct(True) |
|
442 |
self.rqlst.add_eid_restriction(restrvar, value) |
|
443 |
else: |
|
444 |
# multiple values with AND operator |
|
445 |
self.rqlst.add_eid_restriction(restrvar, value.pop()) |
|
446 |
while value: |
|
1149 | 447 |
restrvar = _add_rtype_relation(self.rqlst, mainvar, self.rtype, self.role) |
0 | 448 |
self.rqlst.add_eid_restriction(restrvar, value.pop()) |
449 |
||
450 |
||
451 |
class AttributeFacet(RelationFacet): |
|
452 |
# attribute type |
|
453 |
attrtype = 'String' |
|
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
454 |
# type of comparison: default is an exact match on the attribute value |
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
455 |
comparator = '=' # could be '<', '<=', '>', '>=' |
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
456 |
|
0 | 457 |
def vocabulary(self): |
458 |
"""return vocabulary for this facet, eg a list of 2-uple (label, value) |
|
459 |
""" |
|
460 |
rqlst = self.rqlst |
|
461 |
rqlst.save_state() |
|
462 |
try: |
|
463 |
mainvar = self.filtered_variable |
|
464 |
_cleanup_rqlst(rqlst, mainvar) |
|
1149 | 465 |
newvar = _prepare_vocabulary_rqlst(rqlst, mainvar, self.rtype, self.role) |
0 | 466 |
_set_orderby(rqlst, newvar, self.sortasc, self.sortfunc) |
346
5bbb01a133ae
add try except to avoid error w/ unsupported stuff, log it and return incomplete filter form
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
203
diff
changeset
|
467 |
try: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
468 |
rset = self.rqlexec(rqlst.as_string(), self.cw_rset.args, self.cw_rset.cachekey) |
346
5bbb01a133ae
add try except to avoid error w/ unsupported stuff, log it and return incomplete filter form
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
203
diff
changeset
|
469 |
except: |
5bbb01a133ae
add try except to avoid error w/ unsupported stuff, log it and return incomplete filter form
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
203
diff
changeset
|
470 |
self.exception('error while getting vocabulary for %s, rql: %s', |
5bbb01a133ae
add try except to avoid error w/ unsupported stuff, log it and return incomplete filter form
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
203
diff
changeset
|
471 |
self, rqlst.as_string()) |
5bbb01a133ae
add try except to avoid error w/ unsupported stuff, log it and return incomplete filter form
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
203
diff
changeset
|
472 |
return () |
0 | 473 |
finally: |
474 |
rqlst.recover() |
|
475 |
return self.rset_vocabulary(rset) |
|
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
476 |
|
0 | 477 |
def rset_vocabulary(self, rset): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
478 |
_ = self._cw._ |
0 | 479 |
return [(_(value), value) for value, in rset] |
480 |
||
481 |
def support_and(self): |
|
482 |
return False |
|
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
483 |
|
0 | 484 |
def add_rql_restrictions(self): |
485 |
"""add restriction for this facet into the rql syntax tree""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
486 |
value = self._cw.form.get(self.__regid__) |
0 | 487 |
if not value: |
488 |
return |
|
489 |
mainvar = self.filtered_variable |
|
490 |
self.rqlst.add_constant_restriction(mainvar, self.rtype, value, |
|
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
491 |
self.attrtype, self.comparator) |
0 | 492 |
|
493 |
||
494 |
class FilterRQLBuilder(object): |
|
495 |
"""called by javascript to get a rql string from filter form""" |
|
496 |
||
497 |
def __init__(self, req): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
498 |
self._cw = req |
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
499 |
|
0 | 500 |
def build_rql(self):#, tablefilter=False): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
501 |
form = self._cw.form |
0 | 502 |
facetids = form['facets'].split(',') |
503 |
select = parse(form['baserql']).children[0] # XXX Union unsupported yet |
|
504 |
mainvar = filtered_variable(select) |
|
505 |
toupdate = [] |
|
506 |
for facetid in facetids: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
507 |
facet = get_facet(self._cw, facetid, select, mainvar) |
0 | 508 |
facet.add_rql_restrictions() |
509 |
if facet.needs_update: |
|
510 |
toupdate.append(facetid) |
|
511 |
return select.as_string(), toupdate |
|
512 |
||
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
513 |
|
2010
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
514 |
class RangeFacet(AttributeFacet): |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
515 |
attrtype = 'Float' # only numerical types are supported |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
516 |
|
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
517 |
@property |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
518 |
def wdgclass(self): |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
519 |
return FacetRangeWidget |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
520 |
|
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
521 |
def get_widget(self): |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
522 |
"""return the widget instance to use to display this facet |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
523 |
""" |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
524 |
values = set(value for _, value in self.vocabulary() if value is not None) |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
525 |
return self.wdgclass(self, min(values), max(values)) |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
526 |
|
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
527 |
def infvalue(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
528 |
return self._cw.form.get('%s_inf' % self.__regid__) |
2010
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
529 |
|
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
530 |
def supvalue(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
531 |
return self._cw.form.get('%s_sup' % self.__regid__) |
2010
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
532 |
|
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
533 |
def formatvalue(self, value): |
2020
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
534 |
"""format `value` before in order to insert it in the RQL query""" |
2010
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
535 |
return unicode(value) |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
536 |
|
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
537 |
def add_rql_restrictions(self): |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
538 |
infvalue = self.infvalue() |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
539 |
if infvalue is None: # nothing sent |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
540 |
return |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
541 |
supvalue = self.supvalue() |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
542 |
self.rqlst.add_constant_restriction(self.filtered_variable, |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
543 |
self.rtype, |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
544 |
self.formatvalue(infvalue), |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
545 |
self.attrtype, '>=') |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
546 |
self.rqlst.add_constant_restriction(self.filtered_variable, |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
547 |
self.rtype, |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
548 |
self.formatvalue(supvalue), |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
549 |
self.attrtype, '<=') |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
550 |
|
3329
8430f6c693a1
cleanup, smarter sort control to avoid it when not necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3328
diff
changeset
|
551 |
|
2010
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
552 |
class DateRangeFacet(RangeFacet): |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
553 |
attrtype = 'Date' # only date types are supported |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
554 |
|
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
555 |
@property |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
556 |
def wdgclass(self): |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
557 |
return DateFacetRangeWidget |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
558 |
|
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
559 |
def formatvalue(self, value): |
2020
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
560 |
"""format `value` before in order to insert it in the RQL query""" |
2010
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
561 |
return '"%s"' % date.fromtimestamp(float(value) / 1000).strftime('%Y/%m/%d') |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
562 |
|
2020
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
563 |
|
2014
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
564 |
class HasRelationFacet(AbstractFacet): |
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
565 |
rtype = None # override me in subclass |
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
566 |
role = 'subject' # role of filtered entity in the relation |
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
567 |
|
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
568 |
@property |
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
569 |
def title(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
570 |
return display_name(self._cw, self.rtype, self.role) |
2014
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
571 |
|
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
572 |
def support_and(self): |
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
573 |
return False |
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
574 |
|
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
575 |
def get_widget(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
576 |
return CheckBoxFacetWidget(self._cw, self, |
2014
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
577 |
'%s:%s' % (self.rtype, self), |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
578 |
self._cw.form.get(self.__regid__)) |
2014
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
579 |
|
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
580 |
def add_rql_restrictions(self): |
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
581 |
"""add restriction for this facet into the rql syntax tree""" |
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
582 |
self.rqlst.set_distinct(True) # XXX |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
583 |
value = self._cw.form.get(self.__regid__) |
2014
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
584 |
if not value: # no value sent for this facet |
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
585 |
return |
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
586 |
var = self.rqlst.make_variable() |
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
587 |
if self.role == 'subject': |
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
588 |
self.rqlst.add_relation(self.filtered_variable, self.rtype, var) |
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
589 |
else: |
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
590 |
self.rqlst.add_relation(var, self.rtype, self.filtered_variable) |
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
591 |
|
3329
8430f6c693a1
cleanup, smarter sort control to avoid it when not necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3328
diff
changeset
|
592 |
|
0 | 593 |
## html widets ################################################################ |
594 |
||
595 |
class FacetVocabularyWidget(HTMLWidget): |
|
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
596 |
|
0 | 597 |
def __init__(self, facet): |
598 |
self.facet = facet |
|
599 |
self.items = [] |
|
600 |
||
601 |
def append(self, item): |
|
602 |
self.items.append(item) |
|
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
603 |
|
0 | 604 |
def _render(self): |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
605 |
title = xml_escape(self.facet.title) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
606 |
facetid = xml_escape(self.facet.__regid__) |
949
1fba39d6ee70
fix in facets (avoid to have an horizontal space between facets when facets are unfold)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
536
diff
changeset
|
607 |
self.w(u'<div id="%s" class="facet">\n' % facetid) |
0 | 608 |
self.w(u'<div class="facetTitle" cubicweb:facetName="%s">%s</div>\n' % |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
609 |
(xml_escape(facetid), title)) |
0 | 610 |
if self.facet.support_and(): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
611 |
_ = self.facet._cw._ |
0 | 612 |
self.w(u'''<select name="%s" class="radio facetOperator" title="%s"> |
613 |
<option value="OR">%s</option> |
|
614 |
<option value="AND">%s</option> |
|
615 |
</select>''' % (facetid + '_andor', _('and/or between different values'), |
|
616 |
_('OR'), _('AND'))) |
|
368
84a5106840fa
facet widgets css cleanup
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
346
diff
changeset
|
617 |
cssclass = '' |
84a5106840fa
facet widgets css cleanup
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
346
diff
changeset
|
618 |
if not self.facet.start_unfolded: |
84a5106840fa
facet widgets css cleanup
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
346
diff
changeset
|
619 |
cssclass += ' hidden' |
949
1fba39d6ee70
fix in facets (avoid to have an horizontal space between facets when facets are unfold)
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
536
diff
changeset
|
620 |
if len(self.items) > 6: |
1132 | 621 |
cssclass += ' overflowed' |
0 | 622 |
self.w(u'<div class="facetBody%s">\n' % cssclass) |
623 |
for item in self.items: |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1933
diff
changeset
|
624 |
item.render(w=self.w) |
0 | 625 |
self.w(u'</div>\n') |
626 |
self.w(u'</div>\n') |
|
627 |
||
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
628 |
|
0 | 629 |
class FacetStringWidget(HTMLWidget): |
630 |
def __init__(self, facet): |
|
631 |
self.facet = facet |
|
632 |
self.value = None |
|
633 |
||
634 |
def _render(self): |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
635 |
title = xml_escape(self.facet.title) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
636 |
facetid = xml_escape(self.facet.__regid__) |
0 | 637 |
self.w(u'<div id="%s" class="facet">\n' % facetid) |
638 |
self.w(u'<div class="facetTitle" cubicweb:facetName="%s">%s</div>\n' % |
|
639 |
(facetid, title)) |
|
640 |
self.w(u'<input name="%s" type="text" value="%s" />\n' % (facetid, self.value or u'')) |
|
641 |
self.w(u'</div>\n') |
|
642 |
||
643 |
||
1896
8182746170c6
work in progress: new 'range facet' usable for numerical values, still lacks the form.submit on mouseUp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1433
diff
changeset
|
644 |
class FacetRangeWidget(HTMLWidget): |
2020
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
645 |
formatter = 'function (value) {return value;}' |
1896
8182746170c6
work in progress: new 'range facet' usable for numerical values, still lacks the form.submit on mouseUp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1433
diff
changeset
|
646 |
onload = u''' |
2020
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
647 |
var _formatter = %(formatter)s; |
1896
8182746170c6
work in progress: new 'range facet' usable for numerical values, still lacks the form.submit on mouseUp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1433
diff
changeset
|
648 |
jQuery("#%(sliderid)s").slider({ |
2020
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
649 |
range: true, |
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
650 |
min: %(minvalue)s, |
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
651 |
max: %(maxvalue)s, |
1896
8182746170c6
work in progress: new 'range facet' usable for numerical values, still lacks the form.submit on mouseUp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1433
diff
changeset
|
652 |
values: [%(minvalue)s, %(maxvalue)s], |
1933
f40ee76ecdf1
[facet][RangeFacet] submit facet form when the user stops sliding
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1896
diff
changeset
|
653 |
stop: function(event, ui) { // submit when the user stops sliding |
f40ee76ecdf1
[facet][RangeFacet] submit facet form when the user stops sliding
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1896
diff
changeset
|
654 |
var form = $('#%(sliderid)s').closest('form'); |
f40ee76ecdf1
[facet][RangeFacet] submit facet form when the user stops sliding
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1896
diff
changeset
|
655 |
buildRQL.apply(null, evalJSON(form.attr('cubicweb:facetargs'))); |
f40ee76ecdf1
[facet][RangeFacet] submit facet form when the user stops sliding
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1896
diff
changeset
|
656 |
}, |
2020
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
657 |
slide: function(event, ui) { |
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
658 |
jQuery('#%(sliderid)s_inf').html(_formatter(ui.values[0])); |
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
659 |
jQuery('#%(sliderid)s_sup').html(_formatter(ui.values[1])); |
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
660 |
jQuery('input[name=%(facetid)s_inf]').val(ui.values[0]); |
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
661 |
jQuery('input[name=%(facetid)s_sup]').val(ui.values[1]); |
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
662 |
} |
1896
8182746170c6
work in progress: new 'range facet' usable for numerical values, still lacks the form.submit on mouseUp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1433
diff
changeset
|
663 |
}); |
2020
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
664 |
// use JS formatter to format value on page load |
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
665 |
jQuery('#%(sliderid)s_inf').html(_formatter(jQuery('input[name=%(facetid)s_inf]').val())); |
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
666 |
jQuery('#%(sliderid)s_sup').html(_formatter(jQuery('input[name=%(facetid)s_sup]').val())); |
1896
8182746170c6
work in progress: new 'range facet' usable for numerical values, still lacks the form.submit on mouseUp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1433
diff
changeset
|
667 |
''' |
2020
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
668 |
#'# make emacs happier |
1896
8182746170c6
work in progress: new 'range facet' usable for numerical values, still lacks the form.submit on mouseUp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1433
diff
changeset
|
669 |
def __init__(self, facet, minvalue, maxvalue): |
8182746170c6
work in progress: new 'range facet' usable for numerical values, still lacks the form.submit on mouseUp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1433
diff
changeset
|
670 |
self.facet = facet |
8182746170c6
work in progress: new 'range facet' usable for numerical values, still lacks the form.submit on mouseUp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1433
diff
changeset
|
671 |
self.minvalue = minvalue |
8182746170c6
work in progress: new 'range facet' usable for numerical values, still lacks the form.submit on mouseUp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1433
diff
changeset
|
672 |
self.maxvalue = maxvalue |
8182746170c6
work in progress: new 'range facet' usable for numerical values, still lacks the form.submit on mouseUp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1433
diff
changeset
|
673 |
|
8182746170c6
work in progress: new 'range facet' usable for numerical values, still lacks the form.submit on mouseUp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1433
diff
changeset
|
674 |
def _render(self): |
8182746170c6
work in progress: new 'range facet' usable for numerical values, still lacks the form.submit on mouseUp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1433
diff
changeset
|
675 |
facet = self.facet |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
676 |
facet._cw.add_js('ui.slider.js') |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
677 |
facet._cw.add_css('ui.all.css') |
3333
c61a526b530e
[widgets] change make_uid() seed to make slider ids xhtml-valid
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3329
diff
changeset
|
678 |
sliderid = make_uid('theslider') |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
679 |
facetid = xml_escape(self.facet.__regid__) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
680 |
facet._cw.html_headers.add_onload(self.onload % { |
2020
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
681 |
'sliderid': sliderid, |
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
682 |
'facetid': facetid, |
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
683 |
'minvalue': self.minvalue, |
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
684 |
'maxvalue': self.maxvalue, |
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
685 |
'formatter': self.formatter, |
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
686 |
}) |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
687 |
title = xml_escape(self.facet.title) |
1896
8182746170c6
work in progress: new 'range facet' usable for numerical values, still lacks the form.submit on mouseUp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1433
diff
changeset
|
688 |
self.w(u'<div id="%s" class="facet">\n' % facetid) |
8182746170c6
work in progress: new 'range facet' usable for numerical values, still lacks the form.submit on mouseUp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1433
diff
changeset
|
689 |
self.w(u'<div class="facetTitle" cubicweb:facetName="%s">%s</div>\n' % |
8182746170c6
work in progress: new 'range facet' usable for numerical values, still lacks the form.submit on mouseUp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1433
diff
changeset
|
690 |
(facetid, title)) |
2020
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
691 |
self.w(u'<span id="%s_inf"></span> - <span id="%s_sup"></span>' |
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
692 |
% (sliderid, sliderid)) |
1896
8182746170c6
work in progress: new 'range facet' usable for numerical values, still lacks the form.submit on mouseUp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1433
diff
changeset
|
693 |
self.w(u'<input type="hidden" name="%s_inf" value="%s" />' |
8182746170c6
work in progress: new 'range facet' usable for numerical values, still lacks the form.submit on mouseUp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1433
diff
changeset
|
694 |
% (facetid, self.minvalue)) |
8182746170c6
work in progress: new 'range facet' usable for numerical values, still lacks the form.submit on mouseUp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1433
diff
changeset
|
695 |
self.w(u'<input type="hidden" name="%s_sup" value="%s" />' |
8182746170c6
work in progress: new 'range facet' usable for numerical values, still lacks the form.submit on mouseUp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1433
diff
changeset
|
696 |
% (facetid, self.maxvalue)) |
8182746170c6
work in progress: new 'range facet' usable for numerical values, still lacks the form.submit on mouseUp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1433
diff
changeset
|
697 |
self.w(u'<div id="%s"></div>' % sliderid) |
8182746170c6
work in progress: new 'range facet' usable for numerical values, still lacks the form.submit on mouseUp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1433
diff
changeset
|
698 |
self.w(u'</div>\n') |
8182746170c6
work in progress: new 'range facet' usable for numerical values, still lacks the form.submit on mouseUp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1433
diff
changeset
|
699 |
|
8182746170c6
work in progress: new 'range facet' usable for numerical values, still lacks the form.submit on mouseUp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1433
diff
changeset
|
700 |
|
2010
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
701 |
class DateFacetRangeWidget(FacetRangeWidget): |
2149
6a631ec5cc71
fix date rounding issue in DateFacetRangeWidget
Florent <florent@secondweb.fr>
parents:
2130
diff
changeset
|
702 |
|
2020
fe437afc8fb7
[facet] refactor values formatting in RangeFacets
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2016
diff
changeset
|
703 |
formatter = 'function (value) {return (new Date(parseFloat(value))).strftime(DATE_FMT);}' |
2149
6a631ec5cc71
fix date rounding issue in DateFacetRangeWidget
Florent <florent@secondweb.fr>
parents:
2130
diff
changeset
|
704 |
|
6a631ec5cc71
fix date rounding issue in DateFacetRangeWidget
Florent <florent@secondweb.fr>
parents:
2130
diff
changeset
|
705 |
def round_max_value(self, d): |
6a631ec5cc71
fix date rounding issue in DateFacetRangeWidget
Florent <florent@secondweb.fr>
parents:
2130
diff
changeset
|
706 |
'round to upper value to avoid filtering out the max value' |
2152 | 707 |
return datetime(d.year, d.month, d.day) + timedelta(days=1) |
2149
6a631ec5cc71
fix date rounding issue in DateFacetRangeWidget
Florent <florent@secondweb.fr>
parents:
2130
diff
changeset
|
708 |
|
2010
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
709 |
def __init__(self, facet, minvalue, maxvalue): |
2149
6a631ec5cc71
fix date rounding issue in DateFacetRangeWidget
Florent <florent@secondweb.fr>
parents:
2130
diff
changeset
|
710 |
maxvalue = self.round_max_value(maxvalue) |
2010
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
711 |
super(DateFacetRangeWidget, self).__init__(facet, |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
712 |
datetime2ticks(minvalue), |
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
713 |
datetime2ticks(maxvalue)) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
714 |
fmt = facet._cw.property_value('ui.date-format') |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
715 |
facet._cw.html_headers.define_var('DATE_FMT', fmt) |
2010
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
716 |
|
c594323929cb
[facet] provide a DateRangeFacet (still need to refactor, maybe create a CWWidget)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
717 |
|
0 | 718 |
class FacetItem(HTMLWidget): |
719 |
||
203
60cd67acf7fd
FacetItem now takes req as first parameter of __init__, THIS IS BACKWARD INCOMPATIBLE
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
720 |
selected_img = "black-check.png" |
60cd67acf7fd
FacetItem now takes req as first parameter of __init__, THIS IS BACKWARD INCOMPATIBLE
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
721 |
unselected_img = "no-check-no-border.png" |
0 | 722 |
|
203
60cd67acf7fd
FacetItem now takes req as first parameter of __init__, THIS IS BACKWARD INCOMPATIBLE
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
723 |
def __init__(self, req, label, value, selected=False): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
724 |
self._cw = req |
0 | 725 |
self.label = label |
726 |
self.value = value |
|
727 |
self.selected = selected |
|
728 |
||
729 |
def _render(self): |
|
730 |
if self.selected: |
|
731 |
cssclass = ' facetValueSelected' |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
732 |
imgsrc = self._cw.datadir_url + self.selected_img |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
733 |
imgalt = self._cw._('selected') |
0 | 734 |
else: |
735 |
cssclass = '' |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
736 |
imgsrc = self._cw.datadir_url + self.unselected_img |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
737 |
imgalt = self._cw._('not selected') |
0 | 738 |
self.w(u'<div class="facetValue facetCheckBox%s" cubicweb:value="%s">\n' |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
739 |
% (cssclass, xml_escape(unicode(self.value)))) |
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2658
diff
changeset
|
740 |
self.w(u'<img src="%s" alt="%s"/> ' % (imgsrc, imgalt)) |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
741 |
self.w(u'<a href="javascript: {}">%s</a>' % xml_escape(self.label)) |
0 | 742 |
self.w(u'</div>') |
743 |
||
3329
8430f6c693a1
cleanup, smarter sort control to avoid it when not necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3328
diff
changeset
|
744 |
|
2014
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
745 |
class CheckBoxFacetWidget(HTMLWidget): |
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
746 |
selected_img = "black-check.png" |
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
747 |
unselected_img = "black-uncheck.png" |
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
748 |
|
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
749 |
def __init__(self, req, facet, value, selected): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
750 |
self._cw = req |
2014
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
751 |
self.facet = facet |
2016
a6638de6d4da
[views] reindent web/facet.py
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2014
diff
changeset
|
752 |
self.value = value |
a6638de6d4da
[views] reindent web/facet.py
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2014
diff
changeset
|
753 |
self.selected = selected |
2014
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
754 |
|
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
755 |
def _render(self): |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
756 |
title = xml_escape(self.facet.title) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
757 |
facetid = xml_escape(self.facet.__regid__) |
2016
a6638de6d4da
[views] reindent web/facet.py
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2014
diff
changeset
|
758 |
self.w(u'<div id="%s" class="facet">\n' % facetid) |
a6638de6d4da
[views] reindent web/facet.py
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2014
diff
changeset
|
759 |
if self.selected: |
2014
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
760 |
cssclass = ' facetValueSelected' |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
761 |
imgsrc = self._cw.datadir_url + self.selected_img |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
762 |
imgalt = self._cw._('selected') |
2014
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
763 |
else: |
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
764 |
cssclass = '' |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
765 |
imgsrc = self._cw.datadir_url + self.unselected_img |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
766 |
imgalt = self._cw._('not selected') |
2014
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
767 |
self.w(u'<div class="facetValue facetCheckBox%s" cubicweb:value="%s">\n' |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2305
diff
changeset
|
768 |
% (cssclass, xml_escape(unicode(self.value)))) |
2016
a6638de6d4da
[views] reindent web/facet.py
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2014
diff
changeset
|
769 |
self.w(u'<div class="facetCheckBoxWidget">') |
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2658
diff
changeset
|
770 |
self.w(u'<img src="%s" alt="%s" cubicweb:unselimg="true" /> ' % (imgsrc, imgalt)) |
2130
caa5acbecc08
[javascript] provide a simple function to limit textarea size (+minor cosmetic changes)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2020
diff
changeset
|
771 |
self.w(u'<label class="facetTitle" cubicweb:facetName="%s"><a href="javascript: {}">%s</a></label>' % (facetid, title)) |
2014
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
772 |
self.w(u'</div>\n') |
71a9ab77d9f8
[facet] provide hasRelationFacet (backport from CMHN)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2010
diff
changeset
|
773 |
self.w(u'</div>\n') |
2016
a6638de6d4da
[views] reindent web/facet.py
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2014
diff
changeset
|
774 |
self.w(u'</div>\n') |
0 | 775 |
|
3329
8430f6c693a1
cleanup, smarter sort control to avoid it when not necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3328
diff
changeset
|
776 |
|
0 | 777 |
class FacetSeparator(HTMLWidget): |
778 |
def __init__(self, label=None): |
|
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2658
diff
changeset
|
779 |
self.label = label or u' ' |
467
a6f056bc7d1d
[facets] AttributeFacet can now declare which kind of comparator they want to use, default is '=' (+ tidy trailing white spaces)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
446
diff
changeset
|
780 |
|
0 | 781 |
def _render(self): |
782 |
pass |