author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 07 Jul 2010 12:09:29 +0200 | |
changeset 5917 | 64198285352e |
parent 5727 | 29afb9e715bb |
child 5940 | 0e3ae19b181a |
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:
5377
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:
5377
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:
5377
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:
5377
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:
5377
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:
5377
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:
5377
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:
5377
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:
5377
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:
5377
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:
5377
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:
5377
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:
5377
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:
5377
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:
5377
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:
5377
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5528 | 18 |
"""generic table view, including filtering abilities""" |
0 | 19 |
__docformat__ = "restructuredtext en" |
20 |
||
5377
84d14ddfae13
[python2.6] prefer python2.6's builtin json module over simplejson
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5312
diff
changeset
|
21 |
try: |
84d14ddfae13
[python2.6] prefer python2.6's builtin json module over simplejson
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5312
diff
changeset
|
22 |
from json import dumps |
84d14ddfae13
[python2.6] prefer python2.6's builtin json module over simplejson
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5312
diff
changeset
|
23 |
except ImportError: |
84d14ddfae13
[python2.6] prefer python2.6's builtin json module over simplejson
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5312
diff
changeset
|
24 |
from simplejson import dumps |
0 | 25 |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2226
diff
changeset
|
26 |
from logilab.mtconverter import xml_escape |
0 | 27 |
|
1132 | 28 |
from cubicweb.selectors import nonempty_rset, match_form_params |
762 | 29 |
from cubicweb.utils import make_uid |
30 |
from cubicweb.view import EntityView, AnyRsetView |
|
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
31 |
from cubicweb import tags |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
32 |
from cubicweb.uilib import toggle_action, limitsize, htmlescape |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
33 |
from cubicweb.web import jsonize |
0 | 34 |
from cubicweb.web.htmlwidgets import (TableWidget, TableColumn, MenuWidget, |
762 | 35 |
PopupBoxMenu, BoxLink) |
0 | 36 |
from cubicweb.web.facet import prepare_facets_rqlst, filter_hiddens |
37 |
||
38 |
class TableView(AnyRsetView): |
|
5312
d2dbba898a96
[doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4618
diff
changeset
|
39 |
"""The table view accepts any non-empty rset. It uses |
d2dbba898a96
[doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4618
diff
changeset
|
40 |
introspection on the result set to compute column names and the |
d2dbba898a96
[doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4618
diff
changeset
|
41 |
proper way to display the cells. |
d2dbba898a96
[doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4618
diff
changeset
|
42 |
It is however highly configurable and accepts a wealth of options. |
d2dbba898a96
[doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4618
diff
changeset
|
43 |
""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
44 |
__regid__ = 'table' |
0 | 45 |
title = _('table') |
46 |
finalview = 'final' |
|
497
68d4211518c5
refactor table views to share more code and to avoid empty filter table in some case
sylvain.thenault@logilab.fr
parents:
469
diff
changeset
|
47 |
|
68d4211518c5
refactor table views to share more code and to avoid empty filter table in some case
sylvain.thenault@logilab.fr
parents:
469
diff
changeset
|
48 |
def form_filter(self, divid, displaycols, displayactions, displayfilter, |
5669
1340f14c38c9
[table] propagate paginate
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5668
diff
changeset
|
49 |
paginate, hidden=True): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
50 |
rqlst = self.cw_rset.syntax_tree() |
497
68d4211518c5
refactor table views to share more code and to avoid empty filter table in some case
sylvain.thenault@logilab.fr
parents:
469
diff
changeset
|
51 |
# union not yet supported |
68d4211518c5
refactor table views to share more code and to avoid empty filter table in some case
sylvain.thenault@logilab.fr
parents:
469
diff
changeset
|
52 |
if len(rqlst.children) != 1: |
68d4211518c5
refactor table views to share more code and to avoid empty filter table in some case
sylvain.thenault@logilab.fr
parents:
469
diff
changeset
|
53 |
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:
4252
diff
changeset
|
54 |
rqlst = rqlst.copy() |
2f296c34aec4
fix table view facet retreival, necessary since 95ccd84c892b. Also some cleanup in facet box
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
55 |
self._cw.vreg.rqlhelper.annotate(rqlst) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
56 |
mainvar, baserql = prepare_facets_rqlst(rqlst, self.cw_rset.args) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
57 |
wdgs = [facet.get_widget() for facet in self._cw.vreg['facets'].poss_visible_objects( |
4618
412a9f1f5fd0
[facet] rqlst should be the select node
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4617
diff
changeset
|
58 |
self._cw, rset=self.cw_rset, rqlst=rqlst.children[0], context='tablefilter', |
521
b3430af22580
fix table filter form: get_widget shouldn't be called once rqlst has been recovered
sylvain.thenault@logilab.fr
parents:
513
diff
changeset
|
59 |
filtered_variable=mainvar)] |
b3430af22580
fix table filter form: get_widget shouldn't be called once rqlst has been recovered
sylvain.thenault@logilab.fr
parents:
513
diff
changeset
|
60 |
wdgs = [wdg for wdg in wdgs if wdg is not None] |
b3430af22580
fix table filter form: get_widget shouldn't be called once rqlst has been recovered
sylvain.thenault@logilab.fr
parents:
513
diff
changeset
|
61 |
if wdgs: |
b3430af22580
fix table filter form: get_widget shouldn't be called once rqlst has been recovered
sylvain.thenault@logilab.fr
parents:
513
diff
changeset
|
62 |
self._generate_form(divid, baserql, wdgs, hidden, |
5669
1340f14c38c9
[table] propagate paginate
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5668
diff
changeset
|
63 |
vidargs={'paginate': paginate, |
1340f14c38c9
[table] propagate paginate
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5668
diff
changeset
|
64 |
'displaycols': displaycols, |
497
68d4211518c5
refactor table views to share more code and to avoid empty filter table in some case
sylvain.thenault@logilab.fr
parents:
469
diff
changeset
|
65 |
'displayactions': displayactions, |
68d4211518c5
refactor table views to share more code and to avoid empty filter table in some case
sylvain.thenault@logilab.fr
parents:
469
diff
changeset
|
66 |
'displayfilter': displayfilter}) |
68d4211518c5
refactor table views to share more code and to avoid empty filter table in some case
sylvain.thenault@logilab.fr
parents:
469
diff
changeset
|
67 |
return self.show_hide_actions(divid, not hidden) |
68d4211518c5
refactor table views to share more code and to avoid empty filter table in some case
sylvain.thenault@logilab.fr
parents:
469
diff
changeset
|
68 |
return () |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
69 |
|
521
b3430af22580
fix table filter form: get_widget shouldn't be called once rqlst has been recovered
sylvain.thenault@logilab.fr
parents:
513
diff
changeset
|
70 |
def _generate_form(self, divid, baserql, fwidgets, hidden=True, vidargs={}): |
0 | 71 |
"""display a form to filter table's content. This should only |
5312
d2dbba898a96
[doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4618
diff
changeset
|
72 |
occur when a context eid is given |
0 | 73 |
""" |
5312
d2dbba898a96
[doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4618
diff
changeset
|
74 |
w = self.w |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
75 |
self._cw.add_css('cubicweb.facets.css') |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
76 |
self._cw.add_js( ('cubicweb.ajax.js', 'cubicweb.facets.js')) |
0 | 77 |
# drop False / None values from vidargs |
78 |
vidargs = dict((k, v) for k, v in vidargs.iteritems() if v) |
|
5312
d2dbba898a96
[doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4618
diff
changeset
|
79 |
w(u'<form method="post" cubicweb:facetargs="%s" action="">' % |
5529
7446f5807b33
[table view] should use __regid__ instead of hard-coded 'table' view identifier
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5528
diff
changeset
|
80 |
xml_escape(dumps([divid, self.__regid__, False, vidargs]))) |
5312
d2dbba898a96
[doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4618
diff
changeset
|
81 |
w(u'<fieldset id="%sForm" class="%s">' % (divid, hidden and 'hidden' or '')) |
d2dbba898a96
[doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4618
diff
changeset
|
82 |
w(u'<input type="hidden" name="divid" value="%s" />' % divid) |
d2dbba898a96
[doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4618
diff
changeset
|
83 |
w(u'<input type="hidden" name="fromformfilter" value="1" />') |
d2dbba898a96
[doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4618
diff
changeset
|
84 |
filter_hiddens(w, facets=','.join(wdg.facet.__regid__ for wdg in fwidgets), |
3129
fab471bee6c1
[facets] duhh, necessary fromformfilter hidden was missing
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3128
diff
changeset
|
85 |
baserql=baserql) |
5312
d2dbba898a96
[doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4618
diff
changeset
|
86 |
w(u'<table class="filter">\n') |
d2dbba898a96
[doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4618
diff
changeset
|
87 |
w(u'<tr>\n') |
521
b3430af22580
fix table filter form: get_widget shouldn't be called once rqlst has been recovered
sylvain.thenault@logilab.fr
parents:
513
diff
changeset
|
88 |
for wdg in fwidgets: |
5312
d2dbba898a96
[doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4618
diff
changeset
|
89 |
w(u'<td>') |
d2dbba898a96
[doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4618
diff
changeset
|
90 |
wdg.render(w=w) |
d2dbba898a96
[doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4618
diff
changeset
|
91 |
w(u'</td>\n') |
d2dbba898a96
[doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4618
diff
changeset
|
92 |
w(u'</tr>\n') |
d2dbba898a96
[doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4618
diff
changeset
|
93 |
w(u'</table>\n') |
d2dbba898a96
[doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4618
diff
changeset
|
94 |
w(u'</fieldset>\n') |
d2dbba898a96
[doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4618
diff
changeset
|
95 |
w(u'</form>\n') |
0 | 96 |
|
97 |
def main_var_index(self): |
|
98 |
"""returns the index of the first non-attribute variable among the RQL |
|
99 |
selected variables |
|
100 |
""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
101 |
eschema = self._cw.vreg.schema.eschema |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
102 |
for i, etype in enumerate(self.cw_rset.description[0]): |
0 | 103 |
try: |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3228
diff
changeset
|
104 |
if not eschema(etype).final: |
0 | 105 |
return i |
106 |
except KeyError: # XXX possible? |
|
107 |
continue |
|
108 |
return None |
|
109 |
||
5239
471554b842d2
[schema view] the final touch. Things are getting nicely displayed, and code clean
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5234
diff
changeset
|
110 |
def displaycols(self, displaycols, headers): |
0 | 111 |
if displaycols is None: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
112 |
if 'displaycols' in self._cw.form: |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
113 |
displaycols = [int(idx) for idx in self._cw.form['displaycols']] |
5239
471554b842d2
[schema view] the final touch. Things are getting nicely displayed, and code clean
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5234
diff
changeset
|
114 |
elif headers is not None: |
471554b842d2
[schema view] the final touch. Things are getting nicely displayed, and code clean
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5234
diff
changeset
|
115 |
displaycols = range(len(headers)) |
0 | 116 |
else: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
117 |
displaycols = range(len(self.cw_rset.syntax_tree().children[0].selection)) |
0 | 118 |
return displaycols |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
119 |
|
0 | 120 |
def call(self, title=None, subvid=None, displayfilter=None, headers=None, |
469 | 121 |
displaycols=None, displayactions=None, actions=(), divid=None, |
5617
f0bc8f5ddee2
[tableview] support for json-paginated table if paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5529
diff
changeset
|
122 |
cellvids=None, cellattrs=None, mainindex=None, |
f0bc8f5ddee2
[tableview] support for json-paginated table if paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5529
diff
changeset
|
123 |
paginate=False, page_size=None): |
5312
d2dbba898a96
[doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4618
diff
changeset
|
124 |
"""Produces a table displaying a composite query |
0 | 125 |
|
126 |
:param title: title added before table |
|
127 |
:param subvid: cell view |
|
128 |
:param displayfilter: filter that selects rows to display |
|
129 |
:param headers: columns' titles |
|
130 |
""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
131 |
req = self._cw |
0 | 132 |
req.add_js('jquery.tablesorter.js') |
853
4f6cd02bd71f
Use specific css files directly in views code
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
527
diff
changeset
|
133 |
req.add_css(('cubicweb.tablesorter.css', 'cubicweb.tableview.css')) |
2226
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
134 |
# compute label first since the filter form may remove some necessary |
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
135 |
# information from the rql syntax tree |
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
136 |
if mainindex is None: |
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
137 |
mainindex = self.main_var_index() |
2206
009e2856afcb
columns_labels is an AnyRsetView method...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2204
diff
changeset
|
138 |
computed_labels = self.columns_labels(mainindex) |
0 | 139 |
hidden = True |
140 |
if not subvid and 'subvid' in req.form: |
|
141 |
subvid = req.form.pop('subvid') |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
142 |
divid = divid or req.form.get('divid') or 'rs%s' % make_uid(id(self.cw_rset)) |
0 | 143 |
actions = list(actions) |
144 |
if mainindex is None: |
|
145 |
displayfilter, displayactions = False, False |
|
146 |
else: |
|
147 |
if displayfilter is None and 'displayfilter' in req.form: |
|
148 |
displayfilter = True |
|
149 |
if req.form['displayfilter'] == 'shown': |
|
150 |
hidden = False |
|
151 |
if displayactions is None and 'displayactions' in req.form: |
|
152 |
displayactions = True |
|
5239
471554b842d2
[schema view] the final touch. Things are getting nicely displayed, and code clean
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5234
diff
changeset
|
153 |
displaycols = self.displaycols(displaycols, headers) |
0 | 154 |
fromformfilter = 'fromformfilter' in req.form |
155 |
# if fromformfilter is true, this is an ajax call and we only want to |
|
156 |
# replace the inner div, so don't regenerate everything under the if |
|
157 |
# below |
|
158 |
if not fromformfilter: |
|
3009 | 159 |
self.w(u'<div class="section">') |
0 | 160 |
if not title and 'title' in req.form: |
161 |
title = req.form['title'] |
|
162 |
if title: |
|
163 |
self.w(u'<h2 class="tableTitle">%s</h2>\n' % title) |
|
164 |
if displayfilter: |
|
497
68d4211518c5
refactor table views to share more code and to avoid empty filter table in some case
sylvain.thenault@logilab.fr
parents:
469
diff
changeset
|
165 |
actions += self.form_filter(divid, displaycols, displayfilter, |
5669
1340f14c38c9
[table] propagate paginate
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5668
diff
changeset
|
166 |
displayactions, paginate) |
0 | 167 |
elif displayfilter: |
168 |
actions += self.show_hide_actions(divid, True) |
|
5668
7bd6a8a126b8
no more need for specific handling of table view's displayaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5632
diff
changeset
|
169 |
self.w(u'<div id="%s">' % divid) |
0 | 170 |
if displayactions: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
171 |
actionsbycat = self._cw.vreg['actions'].possible_actions(req, self.cw_rset) |
3228
7b05b2709439
[actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3129
diff
changeset
|
172 |
for action in actionsbycat.get('mainactions', ()): |
7b05b2709439
[actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3129
diff
changeset
|
173 |
for action in action.actual_actions(): |
7b05b2709439
[actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3129
diff
changeset
|
174 |
actions.append( (action.url(), req._(action.title), |
7b05b2709439
[actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3129
diff
changeset
|
175 |
action.html_class(), None) ) |
0 | 176 |
# render actions menu |
177 |
if actions: |
|
178 |
self.render_actions(divid, actions) |
|
179 |
# render table |
|
5617
f0bc8f5ddee2
[tableview] support for json-paginated table if paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5529
diff
changeset
|
180 |
if paginate: |
f0bc8f5ddee2
[tableview] support for json-paginated table if paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5529
diff
changeset
|
181 |
self.divid = divid # XXX iirk (see usage in page_navigation_url) |
f0bc8f5ddee2
[tableview] support for json-paginated table if paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5529
diff
changeset
|
182 |
self.paginate(page_size=page_size, show_all_option=False) |
0 | 183 |
table = TableWidget(self) |
2204
3472c5498478
use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2115
diff
changeset
|
184 |
for column in self.get_columns(computed_labels, displaycols, headers, |
3472c5498478
use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2115
diff
changeset
|
185 |
subvid, cellvids, cellattrs, mainindex): |
0 | 186 |
table.append_column(column) |
187 |
table.render(self.w) |
|
188 |
self.w(u'</div>\n') |
|
189 |
if not fromformfilter: |
|
190 |
self.w(u'</div>\n') |
|
191 |
||
5617
f0bc8f5ddee2
[tableview] support for json-paginated table if paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5529
diff
changeset
|
192 |
def page_navigation_url(self, navcomp, path, params): |
5619
a2c9a55b5a9d
[tableview] don't fail with AttributeError when paginated as main content view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5617
diff
changeset
|
193 |
if hasattr(self, 'divid'): |
a2c9a55b5a9d
[tableview] don't fail with AttributeError when paginated as main content view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5617
diff
changeset
|
194 |
divid = self.divid |
a2c9a55b5a9d
[tableview] don't fail with AttributeError when paginated as main content view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5617
diff
changeset
|
195 |
else: |
5622
aa93a64c53d7
[tableview] use pageContent instead of paginated-content as default div id, paginated-content doesn't seems used anymore
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5619
diff
changeset
|
196 |
divid = params.get('divid', 'pageContent'), |
5617
f0bc8f5ddee2
[tableview] support for json-paginated table if paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5529
diff
changeset
|
197 |
rql = params.pop('rql', self.cw_rset.printable_rql()) |
f0bc8f5ddee2
[tableview] support for json-paginated table if paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5529
diff
changeset
|
198 |
# latest 'true' used for 'swap' mode |
f0bc8f5ddee2
[tableview] support for json-paginated table if paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5529
diff
changeset
|
199 |
return 'javascript: replacePageChunk(%s, %s, %s, %s, true)' % ( |
5619
a2c9a55b5a9d
[tableview] don't fail with AttributeError when paginated as main content view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5617
diff
changeset
|
200 |
dumps(divid), dumps(rql), dumps(self.__regid__), dumps(params)) |
5617
f0bc8f5ddee2
[tableview] support for json-paginated table if paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5529
diff
changeset
|
201 |
|
0 | 202 |
def show_hide_actions(self, divid, currentlydisplayed=False): |
203 |
showhide = u';'.join(toggle_action('%s%s' % (divid, what))[11:] |
|
204 |
for what in ('Form', 'Show', 'Hide', 'Actions')) |
|
205 |
showhide = 'javascript:' + showhide |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
206 |
showlabel = self._cw._('show filter form') |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
207 |
hidelabel = self._cw._('hide filter form') |
0 | 208 |
if currentlydisplayed: |
209 |
return [(showhide, showlabel, 'hidden', '%sShow' % divid), |
|
210 |
(showhide, hidelabel, None, '%sHide' % divid)] |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
211 |
return [(showhide, showlabel, None, '%sShow' % divid), |
0 | 212 |
(showhide, hidelabel, 'hidden', '%sHide' % divid)] |
213 |
||
214 |
def render_actions(self, divid, actions): |
|
215 |
box = MenuWidget('', 'tableActionsBox', _class='', islist=False) |
|
5467
57372dbfd114
[https] fix resource urls in https version of a site: should use the https version as well to avoid warnings from the nrowser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
216 |
label = tags.img(src=self._cw.uiprops['PUCE_DOWN'], |
3890
d7a270f50f54
backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
217 |
alt=xml_escape(self._cw._('action(s) on this selection'))) |
0 | 218 |
menu = PopupBoxMenu(label, isitem=False, link_class='actionsBox', |
219 |
ident='%sActions' % divid) |
|
220 |
box.append(menu) |
|
221 |
for url, label, klass, ident in actions: |
|
222 |
menu.append(BoxLink(url, label, klass, ident=ident, escape=True)) |
|
223 |
box.render(w=self.w) |
|
224 |
self.w(u'<div class="clear"/>') |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
225 |
|
2204
3472c5498478
use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2115
diff
changeset
|
226 |
def get_columns(self, computed_labels, displaycols, headers, subvid, |
3472c5498478
use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2115
diff
changeset
|
227 |
cellvids, cellattrs, mainindex): |
0 | 228 |
columns = [] |
3729
e4f20b74af51
remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3720
diff
changeset
|
229 |
eschema = self._cw.vreg.schema.eschema |
2204
3472c5498478
use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2115
diff
changeset
|
230 |
for colindex, label in enumerate(computed_labels): |
0 | 231 |
if colindex not in displaycols: |
232 |
continue |
|
233 |
# compute column header |
|
234 |
if headers is not None: |
|
235 |
label = headers[displaycols.index(colindex)] |
|
5503
5b7eb0839da3
[table view] take care to None label
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
236 |
if colindex == mainindex and label is not None: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
237 |
label += ' (%s)' % self.cw_rset.rowcount |
0 | 238 |
column = TableColumn(label, colindex) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
239 |
coltype = self.cw_rset.description[0][colindex] |
0 | 240 |
# compute column cell view (if coltype is None, it's a left outer |
241 |
# join, use the default non final subvid) |
|
242 |
if cellvids and colindex in cellvids: |
|
243 |
column.append_renderer(cellvids[colindex], colindex) |
|
3729
e4f20b74af51
remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3720
diff
changeset
|
244 |
elif coltype is not None and eschema(coltype).final: |
0 | 245 |
column.append_renderer(self.finalview, colindex) |
246 |
else: |
|
247 |
column.append_renderer(subvid or 'incontext', colindex) |
|
248 |
if cellattrs and colindex in cellattrs: |
|
249 |
for name, value in cellattrs[colindex].iteritems(): |
|
1138
22f634977c95
make pylint happy, fix some bugs on the way
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
250 |
column.add_attr(name, value) |
0 | 251 |
# add column |
252 |
columns.append(column) |
|
253 |
return columns |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
254 |
|
0 | 255 |
|
1730
cec526a96535
fix 'render' method name conflict
sylvain.thenault@logilab.fr
parents:
1635
diff
changeset
|
256 |
def render_cell(self, cellvid, row, col, w): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
257 |
self._cw.view('cell', self.cw_rset, row=row, col=col, cellvid=cellvid, w=w) |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
258 |
|
0 | 259 |
def get_rows(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
260 |
return self.cw_rset |
0 | 261 |
|
262 |
@htmlescape |
|
263 |
@jsonize |
|
264 |
@limitsize(10) |
|
265 |
def sortvalue(self, row, col): |
|
266 |
# XXX it might be interesting to try to limit value's |
|
267 |
# length as much as possible (e.g. by returning the 10 |
|
268 |
# first characters of a string) |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
269 |
val = self.cw_rset[row][col] |
0 | 270 |
if val is None: |
271 |
return u'' |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
272 |
etype = self.cw_rset.description[row][col] |
3729
e4f20b74af51
remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3720
diff
changeset
|
273 |
if self._cw.vreg.schema.eschema(etype).final: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
274 |
entity, rtype = self.cw_rset.related_entity(row, col) |
0 | 275 |
if entity is None: |
276 |
return val # remove_html_tags() ? |
|
277 |
return entity.sortvalue(rtype) |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
278 |
entity = self.cw_rset.get_entity(row, col) |
0 | 279 |
return entity.sortvalue() |
280 |
||
843 | 281 |
|
0 | 282 |
class EditableTableView(TableView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
283 |
__regid__ = 'editable-table' |
0 | 284 |
finalview = 'editable-final' |
285 |
title = _('editable-table') |
|
286 |
||
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
287 |
|
0 | 288 |
class CellView(EntityView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
289 |
__regid__ = 'cell' |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
290 |
__select__ = nonempty_rset() |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
291 |
|
0 | 292 |
def cell_call(self, row, col, cellvid=None): |
293 |
""" |
|
294 |
:param row, col: indexes locating the cell value in view's result set |
|
295 |
:param cellvid: cell view (defaults to 'outofcontext') |
|
296 |
""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
297 |
etype, val = self.cw_rset.description[row][col], self.cw_rset[row][col] |
4045
f4a52abb6f4f
cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4023
diff
changeset
|
298 |
if val is not None and not self._cw.vreg.schema.eschema(etype).final: |
5504
97ed78b54956
[table view] we should call the cell view using the table rset, not one rebuilded for a specific entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5503
diff
changeset
|
299 |
self.wview(cellvid or 'outofcontext', self.cw_rset, row=row, col=col) |
0 | 300 |
elif val is None: |
301 |
# This is usually caused by a left outer join and in that case, |
|
302 |
# regular views will most certainly fail if they don't have |
|
303 |
# a real eid |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
304 |
self.wview('final', self.cw_rset, row=row, col=col) |
0 | 305 |
else: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
306 |
self.wview(cellvid or 'final', self.cw_rset, 'null', row=row, col=col) |
0 | 307 |
|
308 |
||
309 |
class InitialTableView(TableView): |
|
310 |
"""same display as table view but consider two rql queries : |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
311 |
|
0 | 312 |
* the default query (ie `rql` form parameter), which is only used to select |
313 |
this view and to build the filter form. This query should have the same |
|
314 |
structure as the actual without actual restriction (but link to |
|
315 |
restriction variables) and usually with a limit for efficiency (limit set |
|
316 |
to 2 is advised) |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
317 |
|
0 | 318 |
* the actual query (`actualrql` form parameter) whose results will be |
319 |
displayed with default restrictions set |
|
320 |
""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
321 |
__regid__ = 'initialtable' |
5632
1e7c662bd6f8
[tableview / facets] to work properly with facet, initial table should handle case where actualrql isn't specified
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5622
diff
changeset
|
322 |
__select__ = nonempty_rset() |
0 | 323 |
# should not be displayed in possible view since it expects some specific |
324 |
# parameters |
|
325 |
title = None |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
326 |
|
469 | 327 |
def call(self, title=None, subvid=None, headers=None, divid=None, |
5669
1340f14c38c9
[table] propagate paginate
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5668
diff
changeset
|
328 |
paginate=False, displaycols=None, displayactions=None, mainindex=None): |
0 | 329 |
"""Dumps a table displaying a composite query""" |
5632
1e7c662bd6f8
[tableview / facets] to work properly with facet, initial table should handle case where actualrql isn't specified
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5622
diff
changeset
|
330 |
try: |
1e7c662bd6f8
[tableview / facets] to work properly with facet, initial table should handle case where actualrql isn't specified
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5622
diff
changeset
|
331 |
actrql = self._cw.form['actualrql'] |
1e7c662bd6f8
[tableview / facets] to work properly with facet, initial table should handle case where actualrql isn't specified
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5622
diff
changeset
|
332 |
except KeyError: |
1e7c662bd6f8
[tableview / facets] to work properly with facet, initial table should handle case where actualrql isn't specified
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5622
diff
changeset
|
333 |
actrql = self.cw_rset.printable_rql() |
1e7c662bd6f8
[tableview / facets] to work properly with facet, initial table should handle case where actualrql isn't specified
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5622
diff
changeset
|
334 |
else: |
1e7c662bd6f8
[tableview / facets] to work properly with facet, initial table should handle case where actualrql isn't specified
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5622
diff
changeset
|
335 |
self._cw.ensure_ro_rql(actrql) |
5239
471554b842d2
[schema view] the final touch. Things are getting nicely displayed, and code clean
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5234
diff
changeset
|
336 |
displaycols = self.displaycols(displaycols, headers) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
337 |
if displayactions is None and 'displayactions' in self._cw.form: |
0 | 338 |
displayactions = True |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
339 |
if divid is None and 'divid' in self._cw.form: |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
340 |
divid = self._cw.form['divid'] |
0 | 341 |
self.w(u'<div class="section">') |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
342 |
if not title and 'title' in self._cw.form: |
0 | 343 |
# pop title so it's not displayed by the table view as well |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
344 |
title = self._cw.form.pop('title') |
0 | 345 |
if title: |
346 |
self.w(u'<h2>%s</h2>\n' % title) |
|
2226
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
347 |
if mainindex is None: |
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
348 |
mainindex = self.main_var_index() |
0 | 349 |
if mainindex is not None: |
5669
1340f14c38c9
[table] propagate paginate
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5668
diff
changeset
|
350 |
actions = self.form_filter(divid, displaycols, displayactions, |
1340f14c38c9
[table] propagate paginate
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5668
diff
changeset
|
351 |
paginate, True) |
497
68d4211518c5
refactor table views to share more code and to avoid empty filter table in some case
sylvain.thenault@logilab.fr
parents:
469
diff
changeset
|
352 |
else: |
68d4211518c5
refactor table views to share more code and to avoid empty filter table in some case
sylvain.thenault@logilab.fr
parents:
469
diff
changeset
|
353 |
actions = () |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
354 |
if not subvid and 'subvid' in self._cw.form: |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
355 |
subvid = self._cw.form.pop('subvid') |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
356 |
self._cw.view('table', self._cw.execute(actrql), |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
357 |
'noresult', w=self.w, displayfilter=False, subvid=subvid, |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
358 |
displayactions=displayactions, displaycols=displaycols, |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
359 |
actions=actions, headers=headers, divid=divid) |
0 | 360 |
self.w(u'</div>\n') |
361 |
||
362 |
||
527 | 363 |
class EditableInitialTableTableView(InitialTableView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
364 |
__regid__ = 'editable-initialtable' |
0 | 365 |
finalview = 'editable-final' |
5234
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
366 |
|
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
367 |
|
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
368 |
class EntityAttributesTableView(EntityView): |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
369 |
"""This table displays entity attributes in a table and allow to set a |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
370 |
specific method to help building cell content for each attribute as well as |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
371 |
column header. |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
372 |
|
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
373 |
Table will render entity cell by using the appropriate build_COLNAME_cell |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
374 |
methods if defined otherwise cell content will be entity.COLNAME. |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
375 |
|
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
376 |
Table will render column header using the method header_for_COLNAME if |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
377 |
defined otherwise COLNAME will be used. |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
378 |
""" |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
379 |
__abstract__ = True |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
380 |
columns = () |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
381 |
table_css = "listing" |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
382 |
css_files = () |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
383 |
|
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
384 |
def call(self, columns=None): |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
385 |
if self.css_files: |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
386 |
self._cw.add_css(self.css_files) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
387 |
_ = self._cw._ |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
388 |
self.columns = columns or self.columns |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5545
diff
changeset
|
389 |
sample = self.cw_rset.get_entity(0, 0) |
5234
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
390 |
self.w(u'<table class="%s">' % self.table_css) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5545
diff
changeset
|
391 |
self.table_header(sample) |
5234
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
392 |
self.w(u'<tbody>') |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
393 |
for row in xrange(self.cw_rset.rowcount): |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
394 |
self.cell_call(row=row, col=0) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
395 |
self.w(u'</tbody>') |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
396 |
self.w(u'</table>') |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
397 |
|
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
398 |
def cell_call(self, row, col): |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
399 |
_ = self._cw._ |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
400 |
entity = self.cw_rset.get_entity(row, col) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
401 |
infos = {} |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
402 |
for col in self.columns: |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
403 |
meth = getattr(self, 'build_%s_cell' % col, None) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
404 |
# find the build method or try to find matching attribute |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
405 |
if meth: |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
406 |
content = meth(entity) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
407 |
else: |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
408 |
content = entity.printable_value(col) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
409 |
infos[col] = content |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5679
diff
changeset
|
410 |
self.w(u"""<tr onmouseover="$(this).addClass('highlighted');" |
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5679
diff
changeset
|
411 |
onmouseout="$(this).removeClass('highlighted')">""") |
5234
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
412 |
line = u''.join(u'<td>%%(%s)s</td>' % col for col in self.columns) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
413 |
self.w(line % infos) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
414 |
self.w(u'</tr>\n') |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
415 |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5545
diff
changeset
|
416 |
def table_header(self, sample): |
5234
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
417 |
"""builds the table's header""" |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
418 |
self.w(u'<thead><tr>') |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
419 |
for column in self.columns: |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
420 |
meth = getattr(self, 'header_for_%s' % column, None) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
421 |
if meth: |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5545
diff
changeset
|
422 |
colname = meth(sample) |
5234
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
423 |
else: |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5545
diff
changeset
|
424 |
colname = self._cw._(column) |
5234
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
425 |
self.w(u'<th>%s</th>' % xml_escape(colname)) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
426 |
self.w(u'</tr></thead>\n') |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
427 |
|
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
428 |