author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 25 Oct 2010 15:29:45 +0200 | |
changeset 6620 | 43ba6cfcf75c |
parent 6582 | 8eb7883b4223 |
child 7300 | 4058ed1e3bc2 |
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" |
|
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 |
6620
43ba6cfcf75c
[facets] cleanup and use RelationAttributeFacet for InState
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
29 |
from cubicweb.web import component, facet |
0 | 30 |
|
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
31 |
@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
|
32 |
def contextview_selector(cls, req, rset=None, row=None, col=None, view=None, |
0 | 33 |
**kwargs): |
34 |
if view and getattr(view, 'filter_box_context_info', lambda: None)(): |
|
35 |
return 1 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
36 |
return 0 |
0 | 37 |
|
38 |
||
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
39 |
class FilterBox(component.CtxComponent): |
0 | 40 |
"""filter results of a query""" |
6463
67b0ad068f5d
i18n update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
41 |
__regid__ = 'facet.filters' |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
42 |
__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
|
43 |
| contextview_selector()) |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6040
diff
changeset
|
44 |
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
|
45 |
title = _('facet.filters') |
0 | 46 |
visible = True # functionality provided by the search box by default |
47 |
order = 1 |
|
205
8ea3294e7427
make round corners optional on facet boxes
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
204
diff
changeset
|
48 |
roundcorners = True |
2214
a6b42cf05407
[facets] slightly better attr names
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2213
diff
changeset
|
49 |
|
2215
b1977f5263ac
by popular demand, let us setle on needs_xxx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2214
diff
changeset
|
50 |
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
|
51 |
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
|
52 |
|
2325
363b66a15668
[cleaning] minor cleaning over last two checkins
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2323
diff
changeset
|
53 |
bk_linkbox_template = u'<div class="facetTitle">%s</div>' |
2283 | 54 |
|
0 | 55 |
def facetargs(self): |
56 |
"""this method returns the list of extra arguments that should |
|
57 |
be used by the facet |
|
58 |
""" |
|
59 |
return {} |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
60 |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6040
diff
changeset
|
61 |
def _get_context(self): |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6040
diff
changeset
|
62 |
view = self.cw_extra_kwargs.get('view') |
0 | 63 |
context = getattr(view, 'filter_box_context_info', lambda: None)() |
64 |
if context: |
|
65 |
rset, vid, divid, paginate = context |
|
66 |
else: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
67 |
rset = self.cw_rset |
0 | 68 |
vid, divid = None, 'pageContent' |
4244
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
69 |
paginate = view and view.paginable |
0 | 70 |
return rset, vid, divid, paginate |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
71 |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6040
diff
changeset
|
72 |
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
|
73 |
req = self._cw |
2215
b1977f5263ac
by popular demand, let us setle on needs_xxx
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2214
diff
changeset
|
74 |
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
|
75 |
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
|
76 |
if self.roundcorners: |
8ea3294e7427
make round corners optional on facet boxes
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
204
diff
changeset
|
77 |
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
|
78 |
rset, vid, divid, paginate = self._get_context() |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6040
diff
changeset
|
79 |
# 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
|
80 |
if rset.rowcount < 2: |
0 | 81 |
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
|
82 |
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
|
83 |
# 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
|
84 |
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
|
85 |
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
|
86 |
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
|
87 |
req.vreg.rqlhelper.annotate(rqlst) |
6620
43ba6cfcf75c
[facets] cleanup and use RelationAttributeFacet for InState
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
88 |
mainvar, baserql = facet.prepare_facets_rqlst(rqlst, rset.args) |
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 |
widgets = [] |
6620
43ba6cfcf75c
[facets] cleanup and use RelationAttributeFacet for InState
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
90 |
for facetobj in self.get_facets(rset, rqlst.children[0], mainvar): |
43ba6cfcf75c
[facets] cleanup and use RelationAttributeFacet for InState
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
91 |
wdg = facetobj.get_widget() |
43ba6cfcf75c
[facets] cleanup and use RelationAttributeFacet for InState
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
92 |
if wdg is not None: |
43ba6cfcf75c
[facets] cleanup and use RelationAttributeFacet for InState
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
93 |
widgets.append(wdg) |
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
|
94 |
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
|
95 |
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
|
96 |
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
|
97 |
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
|
98 |
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
|
99 |
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
|
100 |
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
|
101 |
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
|
102 |
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
|
103 |
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
|
104 |
'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
|
105 |
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
|
106 |
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
|
107 |
hiddens[param] = req.form[param] |
6620
43ba6cfcf75c
[facets] cleanup and use RelationAttributeFacet for InState
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
108 |
facet.filter_hiddens(w, **hiddens) |
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
|
109 |
for wdg in widgets: |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6040
diff
changeset
|
110 |
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
|
111 |
w(u'</fieldset>\n</form>\n') |
0 | 112 |
|
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
|
113 |
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
|
114 |
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
|
115 |
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
|
116 |
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
|
117 |
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
|
118 |
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
|
119 |
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
|
120 |
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
|
121 |
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
|
122 |
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
|
123 |
__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
|
124 |
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
|
125 |
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
|
126 |
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
|
127 |
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
|
128 |
return self.bk_linkbox_template % bk_link |
2260
080167dad19e
split FilterBox call function
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2215
diff
changeset
|
129 |
|
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
|
130 |
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
|
131 |
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
|
132 |
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
|
133 |
context='facetbox', filtered_variable=mainvar) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
134 |
|
0 | 135 |
# facets ###################################################################### |
136 |
||
6620
43ba6cfcf75c
[facets] cleanup and use RelationAttributeFacet for InState
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
137 |
class CWSourceFacet(facet.RelationFacet): |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6141
diff
changeset
|
138 |
__regid__ = 'cw_source-facet' |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6141
diff
changeset
|
139 |
rtype = 'cw_source' |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6141
diff
changeset
|
140 |
target_attr = 'name' |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6141
diff
changeset
|
141 |
|
6620
43ba6cfcf75c
[facets] cleanup and use RelationAttributeFacet for InState
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
142 |
class CreatedByFacet(facet.RelationFacet): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
143 |
__regid__ = 'created_by-facet' |
0 | 144 |
rtype = 'created_by' |
145 |
target_attr = 'login' |
|
146 |
||
6620
43ba6cfcf75c
[facets] cleanup and use RelationAttributeFacet for InState
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
147 |
class InGroupFacet(facet.RelationFacet): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
148 |
__regid__ = 'in_group-facet' |
0 | 149 |
rtype = 'in_group' |
150 |
target_attr = 'name' |
|
151 |
||
6620
43ba6cfcf75c
[facets] cleanup and use RelationAttributeFacet for InState
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
152 |
class InStateFacet(facet.RelationAttributeFacet): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
153 |
__regid__ = 'in_state-facet' |
0 | 154 |
rtype = 'in_state' |
155 |
target_attr = 'name' |
|
156 |
||
157 |
# inherit from RelationFacet to benefit from its possible_values implementation |
|
6620
43ba6cfcf75c
[facets] cleanup and use RelationAttributeFacet for InState
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
158 |
class ETypeFacet(facet.RelationFacet): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
159 |
__regid__ = 'etype-facet' |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
160 |
__select__ = yes() |
0 | 161 |
order = 1 |
162 |
rtype = 'is' |
|
163 |
target_attr = 'name' |
|
164 |
||
165 |
@property |
|
166 |
def title(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
167 |
return self._cw._('entity type') |
0 | 168 |
|
169 |
def vocabulary(self): |
|
170 |
"""return vocabulary for this facet, eg a list of 2-uple (label, value) |
|
171 |
""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
172 |
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
|
173 |
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
|
174 |
|
0 | 175 |
def add_rql_restrictions(self): |
176 |
"""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
|
177 |
value = self._cw.form.get(self.__regid__) |
0 | 178 |
if not value: |
179 |
return |
|
180 |
self.rqlst.add_type_restriction(self.filtered_variable, value) |
|
181 |
||
2337
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
182 |
def possible_values(self): |
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
183 |
"""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
|
184 |
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
|
185 |
""" |
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
186 |
rqlst = self.rqlst |
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
187 |
rqlst.save_state() |
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
188 |
try: |
6620
43ba6cfcf75c
[facets] cleanup and use RelationAttributeFacet for InState
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
189 |
facet._cleanup_rqlst(rqlst, self.filtered_variable) |
43ba6cfcf75c
[facets] cleanup and use RelationAttributeFacet for InState
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
190 |
etype_var = facet._prepare_vocabulary_rqlst( |
43ba6cfcf75c
[facets] cleanup and use RelationAttributeFacet for InState
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
191 |
rqlst, self.filtered_variable, self.rtype, self.role) |
2340
65445ae67db0
optimize rql for ETypeFacet possible_values
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2339
diff
changeset
|
192 |
attrvar = rqlst.make_variable() |
65445ae67db0
optimize rql for ETypeFacet possible_values
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2339
diff
changeset
|
193 |
rqlst.add_selected(attrvar) |
65445ae67db0
optimize rql for ETypeFacet possible_values
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2339
diff
changeset
|
194 |
rqlst.add_relation(etype_var, 'name', attrvar) |
65445ae67db0
optimize rql for ETypeFacet possible_values
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2339
diff
changeset
|
195 |
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
|
196 |
finally: |
6620e5abcd99
select right possible_values for ETypeFacet
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2323
diff
changeset
|
197 |
rqlst.recover() |
0 | 198 |
|
6620
43ba6cfcf75c
[facets] cleanup and use RelationAttributeFacet for InState
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
199 |
class HasTextFacet(facet.AbstractFacet): |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
200 |
__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
|
201 |
__regid__ = 'has_text-facet' |
0 | 202 |
rtype = 'has_text' |
203 |
role = 'subject' |
|
204 |
order = 0 |
|
205 |
@property |
|
206 |
def title(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
207 |
return self._cw._('has_text') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
208 |
|
0 | 209 |
def get_widget(self): |
210 |
"""return the widget instance to use to display this facet |
|
211 |
||
212 |
default implentation expects a .vocabulary method on the facet and |
|
213 |
return a combobox displaying this vocabulary |
|
214 |
""" |
|
6620
43ba6cfcf75c
[facets] cleanup and use RelationAttributeFacet for InState
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
215 |
return facet.FacetStringWidget(self) |
0 | 216 |
|
217 |
def add_rql_restrictions(self): |
|
218 |
"""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
|
219 |
value = self._cw.form.get(self.__regid__) |
0 | 220 |
if not value: |
221 |
return |
|
222 |
self.rqlst.add_constant_restriction(self.filtered_variable, 'has_text', value, 'String') |