author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Mon, 04 Jul 2011 12:37:44 +0200 | |
changeset 7614 | 40f33b3d3ea6 |
parent 7610 | 838a0c910bb5 |
child 7663 | fb2501d29587 |
permissions | -rw-r--r-- |
7402
826e5663a686
[facets/table] vertically group facets by two when possible in order to have a more compact horizontal layout in table filter form
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7300
diff
changeset
|
1 |
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5940
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
18 |
"""the facets box and some basic facets""" |
0 | 19 |
|
20 |
__docformat__ = "restructuredtext en" |
|
6582
8eb7883b4223
[pylint] fix a bug of pylint detected errors and i18n pb (calling builtins._ instead of req._)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6463
diff
changeset
|
21 |
_ = unicode |
0 | 22 |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2283
diff
changeset
|
23 |
from logilab.mtconverter import xml_escape |
0 | 24 |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
25 |
from cubicweb.appobject import objectify_selector |
4320
4efd4c306746
closes #345410: two_lines_rset, two_cols_rset, two_etypes_rset are badly named
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
26 |
from cubicweb.selectors import (non_final_entity, multi_lines_rset, |
1132 | 27 |
match_context_prop, yes, relation_possible) |
5940
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
28 |
from cubicweb.utils import json_dumps |
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
29 |
from cubicweb.web import component, facet as facetbase |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
30 |
|
7606
01b49ec8fe80
[facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7605
diff
changeset
|
31 |
def facets(req, rset, context, mainvar=None): |
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
32 |
"""return the base rql and a list of widgets for facets applying to the |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
33 |
given rset/context (cached version) |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
34 |
""" |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
35 |
try: |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
36 |
cache = req.__rset_facets |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
37 |
except AttributeError: |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
38 |
cache = req.__rset_facets = {} |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
39 |
try: |
7606
01b49ec8fe80
[facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7605
diff
changeset
|
40 |
return cache[(rset, context, mainvar)] |
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
41 |
except KeyError: |
7606
01b49ec8fe80
[facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7605
diff
changeset
|
42 |
facets = _facets(req, rset, context, mainvar) |
01b49ec8fe80
[facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7605
diff
changeset
|
43 |
cache[(rset, context, mainvar)] = facets |
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
44 |
return facets |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
45 |
|
7606
01b49ec8fe80
[facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7605
diff
changeset
|
46 |
def _facets(req, rset, context, mainvar): |
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
47 |
"""return the base rql and a list of widgets for facets applying to the |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
48 |
given rset/context |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
49 |
""" |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
50 |
# XXX done by selectors, though maybe necessary when rset has been hijacked |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
51 |
# (e.g. contextview_selector matched) |
7606
01b49ec8fe80
[facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7605
diff
changeset
|
52 |
origqlst = rset.syntax_tree() |
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
53 |
# union not yet supported |
7606
01b49ec8fe80
[facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7605
diff
changeset
|
54 |
if len(origqlst.children) != 1: |
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
55 |
return None, () |
7606
01b49ec8fe80
[facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7605
diff
changeset
|
56 |
rqlst = origqlst.copy() |
01b49ec8fe80
[facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7605
diff
changeset
|
57 |
select = rqlst.children[0] |
01b49ec8fe80
[facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7605
diff
changeset
|
58 |
filtered_variable, baserql = facetbase.init_facets(rset, select, mainvar) |
01b49ec8fe80
[facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7605
diff
changeset
|
59 |
wdgs = [(facet, facet.get_widget()) for facet in req.vreg['facets'].poss_visible_objects( |
01b49ec8fe80
[facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7605
diff
changeset
|
60 |
req, rset=rset, rqlst=origqlst, select=select, context=context, |
01b49ec8fe80
[facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7605
diff
changeset
|
61 |
filtered_variable=filtered_variable)] |
01b49ec8fe80
[facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7605
diff
changeset
|
62 |
return baserql, [wdg for facet, wdg in wdgs if wdg is not None] |
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
63 |
|
0 | 64 |
|
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
65 |
@objectify_selector |
2161
200481e7b156
prepare time where it won't be mandatory to give rset to select()
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
66 |
def contextview_selector(cls, req, rset=None, row=None, col=None, view=None, |
0 | 67 |
**kwargs): |
68 |
if view and getattr(view, 'filter_box_context_info', lambda: None)(): |
|
69 |
return 1 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
70 |
return 0 |
0 | 71 |
|
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
72 |
@objectify_selector |
7606
01b49ec8fe80
[facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7605
diff
changeset
|
73 |
def has_facets(cls, req, rset=None, mainvar=None, **kwargs): |
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
74 |
if rset is None: |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
75 |
return 0 |
7606
01b49ec8fe80
[facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7605
diff
changeset
|
76 |
return len(facets(req, rset, cls.__regid__, mainvar)[1]) |
0 | 77 |
|
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
78 |
|
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
79 |
def filter_hiddens(w, baserql, wdgs, **kwargs): |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
80 |
kwargs['facets'] = ','.join(wdg.facet.__regid__ for wdg in wdgs) |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
81 |
kwargs['baserql'] = baserql |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
82 |
for key, val in kwargs.items(): |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
83 |
w(u'<input type="hidden" name="%s" value="%s" />' % ( |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
84 |
key, xml_escape(val))) |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
85 |
|
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
86 |
|
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
87 |
class FacetFilterMixIn(object): |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
88 |
needs_js = ['cubicweb.ajax.js', 'cubicweb.facets.js'] |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
89 |
needs_css = ['cubicweb.facets.css'] |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
90 |
roundcorners = True |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
91 |
|
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
92 |
def generate_form(self, w, rset, divid, vid, vidargs, |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
93 |
paginate=False, cssclass='', **hiddens): |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
94 |
"""display a form to filter some view's content""" |
7606
01b49ec8fe80
[facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7605
diff
changeset
|
95 |
mainvar = self.cw_extra_kwargs.get('mainvar') |
01b49ec8fe80
[facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7605
diff
changeset
|
96 |
baserql, wdgs = facets(self._cw, rset, self.__regid__, mainvar) |
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
97 |
if not wdgs: # may happen in contextview_selector matched |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
98 |
return |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
99 |
self._cw.add_js(self.needs_js) |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
100 |
self._cw.add_css(self.needs_css) |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
101 |
self._cw.html_headers.define_var('facetLoadingMsg', |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
102 |
self._cw._('facet-loading-msg')) |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
103 |
if self.roundcorners: |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
104 |
self._cw.html_headers.add_onload( |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
105 |
'jQuery(".facet").corner("tl br 10px");') |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
106 |
# drop False / None values from vidargs |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
107 |
vidargs = dict((k, v) for k, v in vidargs.iteritems() if v) |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
108 |
facetargs = xml_escape(json_dumps([divid, vid, paginate, vidargs])) |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
109 |
w(u'<form id="%sForm" class="%s" method="post" action="" ' |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
110 |
'cubicweb:facetargs="%s" >' % (divid, cssclass, facetargs)) |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
111 |
w(u'<fieldset>') |
7606
01b49ec8fe80
[facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7605
diff
changeset
|
112 |
if mainvar: |
01b49ec8fe80
[facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7605
diff
changeset
|
113 |
hiddens['mainvar'] = mainvar |
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
114 |
filter_hiddens(w, baserql, wdgs, **hiddens) |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
115 |
self.layout_widgets(w, self.sorted_widgets(wdgs)) |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
116 |
w(u'</fieldset>\n') |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
117 |
w(u'</form>\n') |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
118 |
|
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
119 |
def sorted_widgets(self, wdgs): |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
120 |
"""sort widgets: by default sort by widget height, then according to |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
121 |
widget.order (the original widgets order) |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
122 |
""" |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
123 |
return sorted(wdgs, key=lambda x: x.height()) |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
124 |
|
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
125 |
def layout_widgets(self, w, wdgs): |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
126 |
"""layout widgets: by default simply render each of them |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
127 |
(i.e. succession of <div>) |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
128 |
""" |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
129 |
for wdg in wdgs: |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
130 |
wdg.render(w=w) |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
131 |
|
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
132 |
|
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
133 |
class FilterBox(FacetFilterMixIn, component.CtxComponent): |
0 | 134 |
"""filter results of a query""" |
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
135 |
__regid__ = 'facet.filterbox' |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
136 |
__select__ = ((non_final_entity() & has_facets()) |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
137 |
| contextview_selector()) # can't use has_facets because of |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
138 |
# contextview mecanism |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6040
diff
changeset
|
139 |
context = 'left' # XXX doesn't support 'incontext', only 'left' or 'right' |
6463
67b0ad068f5d
i18n update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
140 |
title = _('facet.filters') |
0 | 141 |
visible = True # functionality provided by the search box by default |
142 |
order = 1 |
|
2214
a6b42cf05407
[facets] slightly better attr names
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2213
diff
changeset
|
143 |
|
2325
363b66a15668
[cleaning] minor cleaning over last two checkins
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2323
diff
changeset
|
144 |
bk_linkbox_template = u'<div class="facetTitle">%s</div>' |
2283 | 145 |
|
7614
40f33b3d3ea6
[facetbox] put the facet box in a box
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7610
diff
changeset
|
146 |
def render_body(self, w, **kwargs): |
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
147 |
req = self._cw |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
148 |
rset, vid, divid, paginate = self._get_context() |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
149 |
if len(rset) < 2: |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
150 |
return |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
151 |
if vid is None: |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
152 |
vid = req.form.get('vid') |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
153 |
if self.bk_linkbox_template and req.vreg.schema['Bookmark'].has_perm(req, 'add'): |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
154 |
w(self.bookmark_link(rset)) |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
155 |
hiddens = {} |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
156 |
for param in ('subvid', 'vtitle'): |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
157 |
if param in req.form: |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
158 |
hiddens[param] = req.form[param] |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
159 |
self.generate_form(w, rset, divid, vid, self.vidargs(), |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
160 |
paginate=paginate, **hiddens) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
161 |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6040
diff
changeset
|
162 |
def _get_context(self): |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6040
diff
changeset
|
163 |
view = self.cw_extra_kwargs.get('view') |
0 | 164 |
context = getattr(view, 'filter_box_context_info', lambda: None)() |
165 |
if context: |
|
166 |
rset, vid, divid, paginate = context |
|
167 |
else: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
168 |
rset = self.cw_rset |
0 | 169 |
vid, divid = None, 'pageContent' |
4244
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
170 |
paginate = view and view.paginable |
0 | 171 |
return rset, vid, divid, paginate |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
172 |
|
6040
9ae260b2d1c4
[facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5940
diff
changeset
|
173 |
def bookmark_link(self, rset): |
9ae260b2d1c4
[facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5940
diff
changeset
|
174 |
req = self._cw |
9ae260b2d1c4
[facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5940
diff
changeset
|
175 |
bk_path = u'rql=%s' % req.url_quote(rset.printable_rql()) |
9ae260b2d1c4
[facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5940
diff
changeset
|
176 |
if req.form.get('vid'): |
9ae260b2d1c4
[facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5940
diff
changeset
|
177 |
bk_path += u'&vid=%s' % req.url_quote(req.form['vid']) |
9ae260b2d1c4
[facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5940
diff
changeset
|
178 |
bk_path = u'view?' + bk_path |
9ae260b2d1c4
[facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5940
diff
changeset
|
179 |
bk_title = req._('my custom search') |
9ae260b2d1c4
[facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5940
diff
changeset
|
180 |
linkto = u'bookmarked_by:%s:subject' % req.user.eid |
9ae260b2d1c4
[facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5940
diff
changeset
|
181 |
bkcls = req.vreg['etypes'].etype_class('Bookmark') |
9ae260b2d1c4
[facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5940
diff
changeset
|
182 |
bk_add_url = bkcls.cw_create_url(req, path=bk_path, title=bk_title, |
9ae260b2d1c4
[facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5940
diff
changeset
|
183 |
__linkto=linkto) |
9ae260b2d1c4
[facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5940
diff
changeset
|
184 |
bk_base_url = bkcls.cw_create_url(req, title=bk_title, __linkto=linkto) |
9ae260b2d1c4
[facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5940
diff
changeset
|
185 |
bk_link = u'<a cubicweb:target="%s" id="facetBkLink" href="%s">%s</a>' % ( |
9ae260b2d1c4
[facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5940
diff
changeset
|
186 |
xml_escape(bk_base_url), xml_escape(bk_add_url), |
9ae260b2d1c4
[facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5940
diff
changeset
|
187 |
req._('bookmark this search')) |
9ae260b2d1c4
[facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5940
diff
changeset
|
188 |
return self.bk_linkbox_template % bk_link |
2260
080167dad19e
split FilterBox call function
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2215
diff
changeset
|
189 |
|
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
190 |
def vidargs(self): |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
191 |
"""this method returns the list of extra arguments that should be used |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
192 |
by the filter or the view using it |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
193 |
""" |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
194 |
return {} |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
195 |
|
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
196 |
|
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
197 |
from cubicweb.view import AnyRsetView |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
198 |
|
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
199 |
class FilterTable(FacetFilterMixIn, AnyRsetView): |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
200 |
__regid__ = 'facet.filtertable' |
7610
838a0c910bb5
[selectors, facet] make is_instance and other EClassSelector subclass gather entity classes from 'select' and 'filtered_variable' context information. Closes #1796732
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7606
diff
changeset
|
201 |
__select__ = has_facets() |
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
202 |
wdg_stack_size = 8 |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
203 |
|
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
204 |
def call(self, vid, divid, vidargs, cssclass=''): |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
205 |
self.generate_form(self.w, self.cw_rset, divid, vid, vidargs, |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
206 |
cssclass=cssclass, fromformfilter='1', |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
207 |
# divid=divid XXX |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
208 |
) |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
209 |
|
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
210 |
def layout_widgets(self, w, wdgs): |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
211 |
"""layout widgets: put them in a table where each column should have |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
212 |
sum(wdg.height()) < wdg_stack_size. |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
213 |
""" |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
214 |
w(u'<table class="filter">\n') |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
215 |
widget_queue = [] |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
216 |
queue_height = 0 |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
217 |
w(u'<tr>\n') |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
218 |
for wdg in wdgs: |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
219 |
height = wdg.height() |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
220 |
if queue_height + height <= self.wdg_stack_size: |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
221 |
widget_queue.append(wdg) |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
222 |
queue_height += height |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
223 |
continue |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
224 |
w(u'<td>') |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
225 |
for queued in widget_queue: |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
226 |
queued.render(w=w) |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
227 |
w(u'</td>') |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
228 |
widget_queue = [wdg] |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
229 |
queue_height = height |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
230 |
if widget_queue: |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
231 |
w(u'<td>') |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
232 |
for queued in widget_queue: |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
233 |
queued.render(w=w) |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
234 |
w(u'</td>') |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
235 |
w(u'</tr>\n') |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
236 |
w(u'</table>\n') |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
237 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
238 |
|
0 | 239 |
# facets ###################################################################### |
240 |
||
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
241 |
class CWSourceFacet(facetbase.RelationFacet): |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6141
diff
changeset
|
242 |
__regid__ = 'cw_source-facet' |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6141
diff
changeset
|
243 |
rtype = 'cw_source' |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6141
diff
changeset
|
244 |
target_attr = 'name' |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6141
diff
changeset
|
245 |
|
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
246 |
class CreatedByFacet(facetbase.RelationFacet): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
247 |
__regid__ = 'created_by-facet' |
0 | 248 |
rtype = 'created_by' |
249 |
target_attr = 'login' |
|
250 |
||
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
251 |
class InGroupFacet(facetbase.RelationFacet): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
252 |
__regid__ = 'in_group-facet' |
0 | 253 |
rtype = 'in_group' |
254 |
target_attr = 'name' |
|
255 |
||
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
256 |
class InStateFacet(facetbase.RelationAttributeFacet): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
257 |
__regid__ = 'in_state-facet' |
0 | 258 |
rtype = 'in_state' |
259 |
target_attr = 'name' |
|
260 |
||
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7600
diff
changeset
|
261 |
|
0 | 262 |
# inherit from RelationFacet to benefit from its possible_values implementation |
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
263 |
class ETypeFacet(facetbase.RelationFacet): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
264 |
__regid__ = 'etype-facet' |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
265 |
__select__ = yes() |
0 | 266 |
order = 1 |
267 |
rtype = 'is' |
|
268 |
target_attr = 'name' |
|
269 |
||
270 |
@property |
|
271 |
def title(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
272 |
return self._cw._('entity type') |
0 | 273 |
|
274 |
def vocabulary(self): |
|
275 |
"""return vocabulary for this facet, eg a list of 2-uple (label, value) |
|
276 |
""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
277 |
etypes = self.cw_rset.column_types(0) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
278 |
return sorted((self._cw._(etype), etype) for etype in etypes) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
279 |
|
0 | 280 |
def add_rql_restrictions(self): |
281 |
"""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:
3377
diff
changeset
|
282 |
value = self._cw.form.get(self.__regid__) |
0 | 283 |
if not value: |
284 |
return |
|
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7600
diff
changeset
|
285 |
self.select.add_type_restriction(self.filtered_variable, value) |
0 | 286 |
|
2337
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
287 |
def possible_values(self): |
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
288 |
"""return a list of possible values (as string since it's used to |
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
289 |
compare to a form value in javascript) for this facet |
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
290 |
""" |
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7600
diff
changeset
|
291 |
select = self.select |
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7600
diff
changeset
|
292 |
select.save_state() |
2337
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
293 |
try: |
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7600
diff
changeset
|
294 |
facetbase.cleanup_select(select, self.filtered_variable) |
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7600
diff
changeset
|
295 |
etype_var = facetbase.prepare_vocabulary_select( |
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7600
diff
changeset
|
296 |
select, self.filtered_variable, self.rtype, self.role) |
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7600
diff
changeset
|
297 |
attrvar = select.make_variable() |
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7600
diff
changeset
|
298 |
select.add_selected(attrvar) |
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7600
diff
changeset
|
299 |
select.add_relation(etype_var, 'name', attrvar) |
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7600
diff
changeset
|
300 |
return [etype for _, etype in self.rqlexec(select.as_string())] |
2337
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
301 |
finally: |
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7600
diff
changeset
|
302 |
select.recover() |
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7600
diff
changeset
|
303 |
|
0 | 304 |
|
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
305 |
class HasTextFacet(facetbase.AbstractFacet): |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
306 |
__select__ = relation_possible('has_text', 'subject') & match_context_prop() |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
307 |
__regid__ = 'has_text-facet' |
0 | 308 |
rtype = 'has_text' |
309 |
role = 'subject' |
|
310 |
order = 0 |
|
7402
826e5663a686
[facets/table] vertically group facets by two when possible in order to have a more compact horizontal layout in table filter form
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7300
diff
changeset
|
311 |
|
826e5663a686
[facets/table] vertically group facets by two when possible in order to have a more compact horizontal layout in table filter form
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7300
diff
changeset
|
312 |
@property |
826e5663a686
[facets/table] vertically group facets by two when possible in order to have a more compact horizontal layout in table filter form
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7300
diff
changeset
|
313 |
def wdgclass(self): |
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7402
diff
changeset
|
314 |
return facetbase.FacetStringWidget |
7402
826e5663a686
[facets/table] vertically group facets by two when possible in order to have a more compact horizontal layout in table filter form
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7300
diff
changeset
|
315 |
|
0 | 316 |
@property |
317 |
def title(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
318 |
return self._cw._('has_text') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
319 |
|
0 | 320 |
def get_widget(self): |
321 |
"""return the widget instance to use to display this facet |
|
322 |
||
323 |
default implentation expects a .vocabulary method on the facet and |
|
324 |
return a combobox displaying this vocabulary |
|
325 |
""" |
|
7402
826e5663a686
[facets/table] vertically group facets by two when possible in order to have a more compact horizontal layout in table filter form
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7300
diff
changeset
|
326 |
return self.wdgclass(self) |
0 | 327 |
|
328 |
def add_rql_restrictions(self): |
|
329 |
"""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:
3377
diff
changeset
|
330 |
value = self._cw.form.get(self.__regid__) |
0 | 331 |
if not value: |
332 |
return |
|
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7600
diff
changeset
|
333 |
self.select.add_constant_restriction(self.filtered_variable, 'has_text', value, 'String') |