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