author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Mon, 04 Oct 2010 18:56:05 +0200 | |
changeset 6389 | 72ba82a26e05 |
parent 6141 | b8287e54b528 |
child 6427 | c8a5ac2d1eaa |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
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" |
|
21 |
||
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2283
diff
changeset
|
22 |
from logilab.mtconverter import xml_escape |
0 | 23 |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
24 |
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
|
25 |
from cubicweb.selectors import (non_final_entity, multi_lines_rset, |
1132 | 26 |
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
|
27 |
from cubicweb.utils import json_dumps |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
28 |
from cubicweb.web import component |
1132 | 29 |
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
|
30 |
prepare_facets_rqlst, filter_hiddens, _cleanup_rqlst, |
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
31 |
_prepare_vocabulary_rqlst) |
0 | 32 |
|
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
33 |
@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
|
34 |
def contextview_selector(cls, req, rset=None, row=None, col=None, view=None, |
0 | 35 |
**kwargs): |
36 |
if view and getattr(view, 'filter_box_context_info', lambda: None)(): |
|
37 |
return 1 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
38 |
return 0 |
0 | 39 |
|
40 |
||
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
41 |
class FilterBox(component.CtxComponent): |
0 | 42 |
"""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
|
43 |
__regid__ = 'filter_box' |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
44 |
__select__ = ((non_final_entity() & multi_lines_rset()) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
45 |
| contextview_selector()) |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6040
diff
changeset
|
46 |
context = 'left' # XXX doesn't support 'incontext', only 'left' or 'right' |
0 | 47 |
title = _('boxes_filter_box') |
48 |
visible = True # functionality provided by the search box by default |
|
49 |
order = 1 |
|
205
8ea3294e7427
make round corners optional on facet boxes
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
204
diff
changeset
|
50 |
roundcorners = True |
2214
a6b42cf05407
[facets] slightly better attr names
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2213
diff
changeset
|
51 |
|
2215
b1977f5263ac
by popular demand, let us setle on needs_xxx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2214
diff
changeset
|
52 |
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
|
53 |
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
|
54 |
|
2325
363b66a15668
[cleaning] minor cleaning over last two checkins
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2323
diff
changeset
|
55 |
bk_linkbox_template = u'<div class="facetTitle">%s</div>' |
2283 | 56 |
|
0 | 57 |
def facetargs(self): |
58 |
"""this method returns the list of extra arguments that should |
|
59 |
be used by the facet |
|
60 |
""" |
|
61 |
return {} |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
62 |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6040
diff
changeset
|
63 |
def _get_context(self): |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6040
diff
changeset
|
64 |
view = self.cw_extra_kwargs.get('view') |
0 | 65 |
context = getattr(view, 'filter_box_context_info', lambda: None)() |
66 |
if context: |
|
67 |
rset, vid, divid, paginate = context |
|
68 |
else: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
69 |
rset = self.cw_rset |
0 | 70 |
vid, divid = None, 'pageContent' |
4244
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
71 |
paginate = view and view.paginable |
0 | 72 |
return rset, vid, divid, paginate |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
73 |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6040
diff
changeset
|
74 |
def render(self, w, **kwargs): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
75 |
req = self._cw |
2215
b1977f5263ac
by popular demand, let us setle on needs_xxx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2214
diff
changeset
|
76 |
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
|
77 |
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
|
78 |
if self.roundcorners: |
8ea3294e7427
make round corners optional on facet boxes
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
204
diff
changeset
|
79 |
req.html_headers.add_onload('jQuery(".facet").corner("tl br 10px");') |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6040
diff
changeset
|
80 |
rset, vid, divid, paginate = self._get_context() |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6040
diff
changeset
|
81 |
# XXX done by selectors, though maybe necessary when rset has been hijacked |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6040
diff
changeset
|
82 |
if rset.rowcount < 2: |
0 | 83 |
return |
5282
d7f72547208e
[facet] fix #873742: erroenously use self.cw_rset instead of context rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5112
diff
changeset
|
84 |
rqlst = rset.syntax_tree() |
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
|
85 |
# 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
|
86 |
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
|
87 |
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
|
88 |
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
|
89 |
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
|
90 |
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
|
91 |
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
|
92 |
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
|
93 |
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
|
94 |
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
|
95 |
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
|
96 |
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
|
97 |
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
|
98 |
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
|
99 |
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
|
100 |
vid = req.form.get('vid') |
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
|
101 |
if self.bk_linkbox_template and req.vreg.schema['Bookmark'].has_perm(req, 'add'): |
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
|
102 |
w(self.bookmark_link(rset)) |
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
|
103 |
w(u'<form method="post" id="%sForm" cubicweb:facetargs="%s" action="">' % ( |
5940
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
104 |
divid, xml_escape(json_dumps([divid, vid, paginate, self.facetargs()])))) |
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
|
105 |
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
|
106 |
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
|
107 |
'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
|
108 |
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
|
109 |
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
|
110 |
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
|
111 |
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
|
112 |
for wdg in widgets: |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6040
diff
changeset
|
113 |
wdg.render(w=w) |
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
|
114 |
w(u'</fieldset>\n</form>\n') |
0 | 115 |
|
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
|
116 |
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
|
117 |
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
|
118 |
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
|
119 |
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
|
120 |
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
|
121 |
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
|
122 |
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
|
123 |
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
|
124 |
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
|
125 |
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
|
126 |
__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
|
127 |
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
|
128 |
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
|
129 |
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
|
130 |
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
|
131 |
return self.bk_linkbox_template % bk_link |
2260
080167dad19e
split FilterBox call function
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2215
diff
changeset
|
132 |
|
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
|
133 |
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
|
134 |
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
|
135 |
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
|
136 |
context='facetbox', filtered_variable=mainvar) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
137 |
|
0 | 138 |
# facets ###################################################################### |
139 |
||
140 |
class CreatedByFacet(RelationFacet): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
141 |
__regid__ = 'created_by-facet' |
0 | 142 |
rtype = 'created_by' |
143 |
target_attr = 'login' |
|
144 |
||
145 |
class InGroupFacet(RelationFacet): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
146 |
__regid__ = 'in_group-facet' |
0 | 147 |
rtype = 'in_group' |
148 |
target_attr = 'name' |
|
149 |
||
150 |
class InStateFacet(RelationFacet): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
151 |
__regid__ = 'in_state-facet' |
0 | 152 |
rtype = 'in_state' |
153 |
target_attr = 'name' |
|
154 |
||
155 |
# inherit from RelationFacet to benefit from its possible_values implementation |
|
156 |
class ETypeFacet(RelationFacet): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
157 |
__regid__ = 'etype-facet' |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
158 |
__select__ = yes() |
0 | 159 |
order = 1 |
160 |
rtype = 'is' |
|
161 |
target_attr = 'name' |
|
162 |
||
163 |
@property |
|
164 |
def title(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
165 |
return self._cw._('entity type') |
0 | 166 |
|
167 |
def vocabulary(self): |
|
168 |
"""return vocabulary for this facet, eg a list of 2-uple (label, value) |
|
169 |
""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
170 |
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
|
171 |
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
|
172 |
|
0 | 173 |
def add_rql_restrictions(self): |
174 |
"""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
|
175 |
value = self._cw.form.get(self.__regid__) |
0 | 176 |
if not value: |
177 |
return |
|
178 |
self.rqlst.add_type_restriction(self.filtered_variable, value) |
|
179 |
||
2337
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
180 |
def possible_values(self): |
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
181 |
"""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
|
182 |
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
|
183 |
""" |
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
184 |
rqlst = self.rqlst |
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
185 |
rqlst.save_state() |
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
186 |
try: |
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
187 |
_cleanup_rqlst(rqlst, self.filtered_variable) |
2340
65445ae67db0
optimize rql for ETypeFacet possible_values
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2339
diff
changeset
|
188 |
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
|
189 |
attrvar = rqlst.make_variable() |
65445ae67db0
optimize rql for ETypeFacet possible_values
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2339
diff
changeset
|
190 |
rqlst.add_selected(attrvar) |
65445ae67db0
optimize rql for ETypeFacet possible_values
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2339
diff
changeset
|
191 |
rqlst.add_relation(etype_var, 'name', attrvar) |
65445ae67db0
optimize rql for ETypeFacet possible_values
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2339
diff
changeset
|
192 |
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
|
193 |
finally: |
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
194 |
rqlst.recover() |
0 | 195 |
|
196 |
class HasTextFacet(AbstractFacet): |
|
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
197 |
__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
|
198 |
__regid__ = 'has_text-facet' |
0 | 199 |
rtype = 'has_text' |
200 |
role = 'subject' |
|
201 |
order = 0 |
|
202 |
@property |
|
203 |
def title(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
204 |
return self._cw._('has_text') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
205 |
|
0 | 206 |
def get_widget(self): |
207 |
"""return the widget instance to use to display this facet |
|
208 |
||
209 |
default implentation expects a .vocabulary method on the facet and |
|
210 |
return a combobox displaying this vocabulary |
|
211 |
""" |
|
212 |
return FacetStringWidget(self) |
|
213 |
||
214 |
def add_rql_restrictions(self): |
|
215 |
"""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
|
216 |
value = self._cw.form.get(self.__regid__) |
0 | 217 |
if not value: |
218 |
return |
|
219 |
self.rqlst.add_constant_restriction(self.filtered_variable, 'has_text', value, 'String') |