author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 29 Mar 2010 10:20:01 +0200 | |
branch | stable |
changeset 5054 | cb066d29166a |
parent 4616 | 2f296c34aec4 |
child 5112 | 5bf8baecfaf8 |
permissions | -rw-r--r-- |
0 | 1 |
"""the facets box and some basic facets |
2 |
||
3 |
:organization: Logilab |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3717
diff
changeset
|
4 |
:copyright: 2008-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
9 |
||
10 |
from simplejson import dumps |
|
11 |
||
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2283
diff
changeset
|
12 |
from logilab.mtconverter import xml_escape |
0 | 13 |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
14 |
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
|
15 |
from cubicweb.selectors import (non_final_entity, multi_lines_rset, |
1132 | 16 |
match_context_prop, yes, relation_possible) |
0 | 17 |
from cubicweb.web.box import BoxTemplate |
1132 | 18 |
from cubicweb.web.facet import (AbstractFacet, FacetStringWidget, RelationFacet, |
2337
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
19 |
prepare_facets_rqlst, filter_hiddens, _cleanup_rqlst, |
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
20 |
_prepare_vocabulary_rqlst) |
0 | 21 |
|
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
22 |
@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
|
23 |
def contextview_selector(cls, req, rset=None, row=None, col=None, view=None, |
0 | 24 |
**kwargs): |
25 |
if view and getattr(view, 'filter_box_context_info', lambda: None)(): |
|
26 |
return 1 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
27 |
return 0 |
0 | 28 |
|
29 |
||
30 |
class FilterBox(BoxTemplate): |
|
31 |
"""filter results of a query""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
32 |
__regid__ = 'filter_box' |
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
|
33 |
__select__ = (((non_final_entity() & multi_lines_rset()) |
758
0c0dfd33a76d
instantiate selectors wherever needed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
742
diff
changeset
|
34 |
| contextview_selector() |
0c0dfd33a76d
instantiate selectors wherever needed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
742
diff
changeset
|
35 |
) & match_context_prop()) |
0 | 36 |
context = 'left' |
37 |
title = _('boxes_filter_box') |
|
38 |
visible = True # functionality provided by the search box by default |
|
39 |
order = 1 |
|
205
8ea3294e7427
make round corners optional on facet boxes
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
204
diff
changeset
|
40 |
roundcorners = True |
2214
a6b42cf05407
[facets] slightly better attr names
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2213
diff
changeset
|
41 |
|
2215
b1977f5263ac
by popular demand, let us setle on needs_xxx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2214
diff
changeset
|
42 |
needs_css = 'cubicweb.facets.css' |
3006
4d85386b06a5
rename cubicweb.formfilter.js into cubicweb.facets.js
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
43 |
needs_js = ('cubicweb.ajax.js', 'cubicweb.facets.js') |
2214
a6b42cf05407
[facets] slightly better attr names
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2213
diff
changeset
|
44 |
|
2325
363b66a15668
[cleaning] minor cleaning over last two checkins
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2323
diff
changeset
|
45 |
bk_linkbox_template = u'<div class="facetTitle">%s</div>' |
2283 | 46 |
|
0 | 47 |
def facetargs(self): |
48 |
"""this method returns the list of extra arguments that should |
|
49 |
be used by the facet |
|
50 |
""" |
|
51 |
return {} |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
52 |
|
0 | 53 |
def _get_context(self, view): |
54 |
context = getattr(view, 'filter_box_context_info', lambda: None)() |
|
55 |
if context: |
|
56 |
rset, vid, divid, paginate = context |
|
57 |
else: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
58 |
rset = self.cw_rset |
0 | 59 |
vid, divid = None, 'pageContent' |
4244
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
60 |
paginate = view and view.paginable |
0 | 61 |
return rset, vid, divid, paginate |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
62 |
|
0 | 63 |
def call(self, view=None): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
64 |
req = self._cw |
2215
b1977f5263ac
by popular demand, let us setle on needs_xxx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2214
diff
changeset
|
65 |
req.add_js( self.needs_js ) |
b1977f5263ac
by popular demand, let us setle on needs_xxx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2214
diff
changeset
|
66 |
req.add_css( self.needs_css) |
205
8ea3294e7427
make round corners optional on facet boxes
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
204
diff
changeset
|
67 |
if self.roundcorners: |
8ea3294e7427
make round corners optional on facet boxes
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
204
diff
changeset
|
68 |
req.html_headers.add_onload('jQuery(".facet").corner("tl br 10px");') |
1132 | 69 |
rset, vid, divid, paginate = self._get_context(view) |
0 | 70 |
if rset.rowcount < 2: # XXX done by selectors, though maybe necessary when rset has been hijacked |
71 |
return |
|
4616
2f296c34aec4
fix table view facet retreival, necessary since 95ccd84c892b. Also some cleanup in facet box
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4614
diff
changeset
|
72 |
rqlst = self.cw_rset.syntax_tree() |
2f296c34aec4
fix table view facet retreival, necessary since 95ccd84c892b. Also some cleanup in facet box
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4614
diff
changeset
|
73 |
# union not yet supported |
2f296c34aec4
fix table view facet retreival, necessary since 95ccd84c892b. Also some cleanup in facet box
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4614
diff
changeset
|
74 |
if len(rqlst.children) != 1: |
2f296c34aec4
fix table view facet retreival, necessary since 95ccd84c892b. Also some cleanup in facet box
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4614
diff
changeset
|
75 |
return () |
2f296c34aec4
fix table view facet retreival, necessary since 95ccd84c892b. Also some cleanup in facet box
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4614
diff
changeset
|
76 |
rqlst = rqlst.copy() |
4614
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
77 |
req.vreg.rqlhelper.annotate(rqlst) |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
78 |
mainvar, baserql = prepare_facets_rqlst(rqlst, rset.args) |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
79 |
widgets = [] |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
80 |
for facet in self.get_facets(rset, rqlst.children[0], mainvar): |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
81 |
if facet.cw_propval('visible'): |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
82 |
wdg = facet.get_widget() |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
83 |
if wdg is not None: |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
84 |
widgets.append(wdg) |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
85 |
if not widgets: |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
86 |
return |
4616
2f296c34aec4
fix table view facet retreival, necessary since 95ccd84c892b. Also some cleanup in facet box
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4614
diff
changeset
|
87 |
if vid is None: |
2f296c34aec4
fix table view facet retreival, necessary since 95ccd84c892b. Also some cleanup in facet box
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4614
diff
changeset
|
88 |
vid = req.form.get('vid') |
4614
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
89 |
if self.bk_linkbox_template: |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
90 |
self.display_bookmark_link(rset) |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
91 |
w = self.w |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
92 |
w(u'<form method="post" id="%sForm" cubicweb:facetargs="%s" action="">' % ( |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
93 |
divid, xml_escape(dumps([divid, vid, paginate, self.facetargs()])))) |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
94 |
w(u'<fieldset>') |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
95 |
hiddens = {'facets': ','.join(wdg.facet.__regid__ for wdg in widgets), |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
96 |
'baserql': baserql} |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
97 |
for param in ('subvid', 'vtitle'): |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
98 |
if param in req.form: |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
99 |
hiddens[param] = req.form[param] |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
100 |
filter_hiddens(w, **hiddens) |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
101 |
for wdg in widgets: |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
102 |
wdg.render(w=self.w) |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
103 |
w(u'</fieldset>\n</form>\n') |
0 | 104 |
|
2325
363b66a15668
[cleaning] minor cleaning over last two checkins
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2323
diff
changeset
|
105 |
def display_bookmark_link(self, rset): |
4045
f4a52abb6f4f
cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3720
diff
changeset
|
106 |
eschema = self._cw.vreg.schema.eschema('Bookmark') |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
107 |
if eschema.has_perm(self._cw, 'add'): |
2260
080167dad19e
split FilterBox call function
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2215
diff
changeset
|
108 |
bk_path = 'view?rql=%s' % rset.printable_rql() |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
109 |
bk_title = self._cw._('my custom search') |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
110 |
linkto = 'bookmarked_by:%s:subject' % self._cw.user.eid |
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
111 |
bk_add_url = self._cw.build_url('add/Bookmark', path=bk_path, title=bk_title, __linkto=linkto) |
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
112 |
bk_base_url = self._cw.build_url('add/Bookmark', title=bk_title, __linkto=linkto) |
2260
080167dad19e
split FilterBox call function
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2215
diff
changeset
|
113 |
bk_link = u'<a cubicweb:target="%s" id="facetBkLink" href="%s">%s</a>' % ( |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2283
diff
changeset
|
114 |
xml_escape(bk_base_url), |
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2283
diff
changeset
|
115 |
xml_escape(bk_add_url), |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
116 |
self._cw._('bookmark this search')) |
2325
363b66a15668
[cleaning] minor cleaning over last two checkins
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2323
diff
changeset
|
117 |
self.w(self.bk_linkbox_template % bk_link) |
2260
080167dad19e
split FilterBox call function
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2215
diff
changeset
|
118 |
|
4614
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
119 |
def get_facets(self, rset, rqlst, mainvar): |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
120 |
return self._cw.vreg['facets'].poss_visible_objects( |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
121 |
self._cw, rset=rset, rqlst=rqlst, |
95ccd84c892b
fix the bad rqlst syntax tree usage during facets initialization by copying it
Charles Hébert <charles.hebert@logilab.fr>
parents:
4320
diff
changeset
|
122 |
context='facetbox', filtered_variable=mainvar) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
123 |
|
0 | 124 |
# facets ###################################################################### |
125 |
||
126 |
class CreatedByFacet(RelationFacet): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
127 |
__regid__ = 'created_by-facet' |
0 | 128 |
rtype = 'created_by' |
129 |
target_attr = 'login' |
|
130 |
||
131 |
class InGroupFacet(RelationFacet): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
132 |
__regid__ = 'in_group-facet' |
0 | 133 |
rtype = 'in_group' |
134 |
target_attr = 'name' |
|
135 |
||
136 |
class InStateFacet(RelationFacet): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
137 |
__regid__ = 'in_state-facet' |
0 | 138 |
rtype = 'in_state' |
139 |
target_attr = 'name' |
|
140 |
||
141 |
# inherit from RelationFacet to benefit from its possible_values implementation |
|
142 |
class ETypeFacet(RelationFacet): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
143 |
__regid__ = 'etype-facet' |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
144 |
__select__ = yes() |
0 | 145 |
order = 1 |
146 |
rtype = 'is' |
|
147 |
target_attr = 'name' |
|
148 |
||
149 |
@property |
|
150 |
def title(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
151 |
return self._cw._('entity type') |
0 | 152 |
|
153 |
def vocabulary(self): |
|
154 |
"""return vocabulary for this facet, eg a list of 2-uple (label, value) |
|
155 |
""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
156 |
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
|
157 |
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
|
158 |
|
0 | 159 |
def add_rql_restrictions(self): |
160 |
"""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
|
161 |
value = self._cw.form.get(self.__regid__) |
0 | 162 |
if not value: |
163 |
return |
|
164 |
self.rqlst.add_type_restriction(self.filtered_variable, value) |
|
165 |
||
2337
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
166 |
def possible_values(self): |
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
167 |
"""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
|
168 |
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
|
169 |
""" |
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
170 |
rqlst = self.rqlst |
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
171 |
rqlst.save_state() |
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
172 |
try: |
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
173 |
_cleanup_rqlst(rqlst, self.filtered_variable) |
2340
65445ae67db0
optimize rql for ETypeFacet possible_values
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2339
diff
changeset
|
174 |
etype_var = _prepare_vocabulary_rqlst(rqlst, self.filtered_variable, self.rtype, self.role) |
65445ae67db0
optimize rql for ETypeFacet possible_values
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2339
diff
changeset
|
175 |
attrvar = rqlst.make_variable() |
65445ae67db0
optimize rql for ETypeFacet possible_values
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2339
diff
changeset
|
176 |
rqlst.add_selected(attrvar) |
65445ae67db0
optimize rql for ETypeFacet possible_values
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2339
diff
changeset
|
177 |
rqlst.add_relation(etype_var, 'name', attrvar) |
65445ae67db0
optimize rql for ETypeFacet possible_values
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2339
diff
changeset
|
178 |
return [etype for _, etype in self.rqlexec(rqlst.as_string())] |
2337
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
179 |
finally: |
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
180 |
rqlst.recover() |
0 | 181 |
|
182 |
class HasTextFacet(AbstractFacet): |
|
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
183 |
__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
|
184 |
__regid__ = 'has_text-facet' |
0 | 185 |
rtype = 'has_text' |
186 |
role = 'subject' |
|
187 |
order = 0 |
|
188 |
@property |
|
189 |
def title(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
190 |
return self._cw._('has_text') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
191 |
|
0 | 192 |
def get_widget(self): |
193 |
"""return the widget instance to use to display this facet |
|
194 |
||
195 |
default implentation expects a .vocabulary method on the facet and |
|
196 |
return a combobox displaying this vocabulary |
|
197 |
""" |
|
198 |
return FacetStringWidget(self) |
|
199 |
||
200 |
def add_rql_restrictions(self): |
|
201 |
"""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
|
202 |
value = self._cw.form.get(self.__regid__) |
0 | 203 |
if not value: |
204 |
return |
|
205 |
self.rqlst.add_constant_restriction(self.filtered_variable, 'has_text', value, 'String') |