author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 27 Sep 2011 14:57:41 +0200 | |
branch | stable |
changeset 7873 | 975d6f51cfab |
parent 7830 | 37d23a1d3547 |
child 7845 | 2172978be237 |
child 7883 | cd98785b4a84 |
permissions | -rw-r--r-- |
7402
826e5663a686
[facets/table] vertically group facets by two when possible in order to have a more compact horizontal layout in table filter form
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6800
diff
changeset
|
1 |
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
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/>. |
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7415
diff
changeset
|
18 |
"""generic table view, including filtering abilities using facets""" |
5940
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
19 |
|
0 | 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:
6254
diff
changeset
|
21 |
_ = unicode |
0 | 22 |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2226
diff
changeset
|
23 |
from logilab.mtconverter import xml_escape |
0 | 24 |
|
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7415
diff
changeset
|
25 |
from cubicweb import NoSelectableObject, tags |
7402
826e5663a686
[facets/table] vertically group facets by two when possible in order to have a more compact horizontal layout in table filter form
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6800
diff
changeset
|
26 |
from cubicweb.selectors import nonempty_rset |
5940
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5727
diff
changeset
|
27 |
from cubicweb.utils import make_uid, json_dumps |
762 | 28 |
from cubicweb.view import EntityView, AnyRsetView |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
29 |
from cubicweb.uilib import toggle_action, limitsize, htmlescape |
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7415
diff
changeset
|
30 |
from cubicweb.web import jsonize, component, facet |
0 | 31 |
from cubicweb.web.htmlwidgets import (TableWidget, TableColumn, MenuWidget, |
6800
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
32 |
PopupBoxMenu) |
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7415
diff
changeset
|
33 |
|
0 | 34 |
|
35 |
class TableView(AnyRsetView): |
|
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7415
diff
changeset
|
36 |
"""The table view accepts any non-empty rset. It uses introspection on the |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7415
diff
changeset
|
37 |
result set to compute column names and the proper way to display the cells. |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7415
diff
changeset
|
38 |
|
5312
d2dbba898a96
[doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4618
diff
changeset
|
39 |
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
|
40 |
""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
41 |
__regid__ = 'table' |
0 | 42 |
title = _('table') |
43 |
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
|
44 |
|
7830
37d23a1d3547
[views/table] parametrize table view co-classes (closes #1947472)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7814
diff
changeset
|
45 |
table_widget_class = TableWidget |
37d23a1d3547
[views/table] parametrize table view co-classes (closes #1947472)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7814
diff
changeset
|
46 |
table_column_class = TableColumn |
37d23a1d3547
[views/table] parametrize table view co-classes (closes #1947472)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7814
diff
changeset
|
47 |
|
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
|
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): |
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7415
diff
changeset
|
50 |
try: |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7415
diff
changeset
|
51 |
filterform = self._cw.vreg['views'].select( |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7415
diff
changeset
|
52 |
'facet.filtertable', self._cw, rset=self.cw_rset) |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7415
diff
changeset
|
53 |
except NoSelectableObject: |
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
|
54 |
return () |
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7415
diff
changeset
|
55 |
vidargs = {'paginate': paginate, |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7415
diff
changeset
|
56 |
'displaycols': displaycols, |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7415
diff
changeset
|
57 |
'displayactions': displayactions, |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7415
diff
changeset
|
58 |
'displayfilter': displayfilter} |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7415
diff
changeset
|
59 |
cssclass = hidden and 'hidden' or '' |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7415
diff
changeset
|
60 |
filterform.render(self.w, vid=self.__regid__, divid=divid, |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7415
diff
changeset
|
61 |
vidargs=vidargs, cssclass=cssclass) |
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7415
diff
changeset
|
62 |
return self.show_hide_actions(divid, not hidden) |
0 | 63 |
|
64 |
def main_var_index(self): |
|
65 |
"""returns the index of the first non-attribute variable among the RQL |
|
66 |
selected variables |
|
67 |
""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
68 |
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
|
69 |
for i, etype in enumerate(self.cw_rset.description[0]): |
0 | 70 |
try: |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3228
diff
changeset
|
71 |
if not eschema(etype).final: |
0 | 72 |
return i |
73 |
except KeyError: # XXX possible? |
|
74 |
continue |
|
75 |
return None |
|
76 |
||
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
|
77 |
def displaycols(self, displaycols, headers): |
0 | 78 |
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
|
79 |
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
|
80 |
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
|
81 |
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
|
82 |
displaycols = range(len(headers)) |
0 | 83 |
else: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
84 |
displaycols = range(len(self.cw_rset.syntax_tree().children[0].selection)) |
0 | 85 |
return displaycols |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
86 |
|
0 | 87 |
def call(self, title=None, subvid=None, displayfilter=None, headers=None, |
469 | 88 |
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
|
89 |
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
|
90 |
paginate=False, page_size=None): |
5312
d2dbba898a96
[doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4618
diff
changeset
|
91 |
"""Produces a table displaying a composite query |
0 | 92 |
|
93 |
:param title: title added before table |
|
94 |
:param subvid: cell view |
|
95 |
:param displayfilter: filter that selects rows to display |
|
96 |
:param headers: columns' titles |
|
97 |
""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
98 |
req = self._cw |
0 | 99 |
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
|
100 |
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
|
101 |
# 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
|
102 |
# information from the rql syntax tree |
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
103 |
if mainindex is None: |
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
104 |
mainindex = self.main_var_index() |
2206
009e2856afcb
columns_labels is an AnyRsetView method...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2204
diff
changeset
|
105 |
computed_labels = self.columns_labels(mainindex) |
0 | 106 |
hidden = True |
107 |
if not subvid and 'subvid' in req.form: |
|
108 |
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
|
109 |
divid = divid or req.form.get('divid') or 'rs%s' % make_uid(id(self.cw_rset)) |
0 | 110 |
actions = list(actions) |
111 |
if mainindex is None: |
|
112 |
displayfilter, displayactions = False, False |
|
113 |
else: |
|
6254
936e98213598
[table view] use get instead of has_key so one can specify he doesn't want actions or filter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6249
diff
changeset
|
114 |
if displayfilter is None and req.form.get('displayfilter'): |
0 | 115 |
displayfilter = True |
116 |
if req.form['displayfilter'] == 'shown': |
|
117 |
hidden = False |
|
6254
936e98213598
[table view] use get instead of has_key so one can specify he doesn't want actions or filter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6249
diff
changeset
|
118 |
if displayactions is None and req.form.get('displayactions'): |
0 | 119 |
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
|
120 |
displaycols = self.displaycols(displaycols, headers) |
0 | 121 |
fromformfilter = 'fromformfilter' in req.form |
122 |
# if fromformfilter is true, this is an ajax call and we only want to |
|
123 |
# replace the inner div, so don't regenerate everything under the if |
|
124 |
# below |
|
125 |
if not fromformfilter: |
|
3009 | 126 |
self.w(u'<div class="section">') |
0 | 127 |
if not title and 'title' in req.form: |
128 |
title = req.form['title'] |
|
129 |
if title: |
|
130 |
self.w(u'<h2 class="tableTitle">%s</h2>\n' % title) |
|
131 |
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
|
132 |
actions += self.form_filter(divid, displaycols, displayfilter, |
5669
1340f14c38c9
[table] propagate paginate
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5668
diff
changeset
|
133 |
displayactions, paginate) |
0 | 134 |
elif displayfilter: |
135 |
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
|
136 |
self.w(u'<div id="%s">' % divid) |
0 | 137 |
if displayactions: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
138 |
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
|
139 |
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
|
140 |
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
|
141 |
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
|
142 |
action.html_class(), None) ) |
0 | 143 |
# render actions menu |
144 |
if actions: |
|
145 |
self.render_actions(divid, actions) |
|
146 |
# render table |
|
5617
f0bc8f5ddee2
[tableview] support for json-paginated table if paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5529
diff
changeset
|
147 |
if paginate: |
f0bc8f5ddee2
[tableview] support for json-paginated table if paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5529
diff
changeset
|
148 |
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
|
149 |
self.paginate(page_size=page_size, show_all_option=False) |
7830
37d23a1d3547
[views/table] parametrize table view co-classes (closes #1947472)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7814
diff
changeset
|
150 |
table = self.table_widget_class(self) |
2204
3472c5498478
use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2115
diff
changeset
|
151 |
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
|
152 |
subvid, cellvids, cellattrs, mainindex): |
0 | 153 |
table.append_column(column) |
154 |
table.render(self.w) |
|
155 |
self.w(u'</div>\n') |
|
156 |
if not fromformfilter: |
|
157 |
self.w(u'</div>\n') |
|
158 |
||
5617
f0bc8f5ddee2
[tableview] support for json-paginated table if paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5529
diff
changeset
|
159 |
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
|
160 |
if hasattr(self, 'divid'): |
6249
1729f53b3e42
fix regretion introduced by changeset "pagination/ ajaxes fixes" (2f5ebeb7665d)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6240
diff
changeset
|
161 |
params['divid'] = self.divid |
1729f53b3e42
fix regretion introduced by changeset "pagination/ ajaxes fixes" (2f5ebeb7665d)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6240
diff
changeset
|
162 |
params['vid'] = self.__regid__ |
1729f53b3e42
fix regretion introduced by changeset "pagination/ ajaxes fixes" (2f5ebeb7665d)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6240
diff
changeset
|
163 |
return navcomp.ajax_page_url(**params) |
5617
f0bc8f5ddee2
[tableview] support for json-paginated table if paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5529
diff
changeset
|
164 |
|
0 | 165 |
def show_hide_actions(self, divid, currentlydisplayed=False): |
166 |
showhide = u';'.join(toggle_action('%s%s' % (divid, what))[11:] |
|
167 |
for what in ('Form', 'Show', 'Hide', 'Actions')) |
|
168 |
showhide = 'javascript:' + showhide |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
169 |
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
|
170 |
hidelabel = self._cw._('hide filter form') |
0 | 171 |
if currentlydisplayed: |
172 |
return [(showhide, showlabel, 'hidden', '%sShow' % divid), |
|
173 |
(showhide, hidelabel, None, '%sHide' % divid)] |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
174 |
return [(showhide, showlabel, None, '%sShow' % divid), |
0 | 175 |
(showhide, hidelabel, 'hidden', '%sHide' % divid)] |
176 |
||
177 |
def render_actions(self, divid, actions): |
|
178 |
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
|
179 |
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
|
180 |
alt=xml_escape(self._cw._('action(s) on this selection'))) |
0 | 181 |
menu = PopupBoxMenu(label, isitem=False, link_class='actionsBox', |
182 |
ident='%sActions' % divid) |
|
183 |
box.append(menu) |
|
184 |
for url, label, klass, ident in actions: |
|
7600
75d208ab8444
[facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7415
diff
changeset
|
185 |
menu.append(component.Link(url, label, klass=klass, id=ident)) |
0 | 186 |
box.render(w=self.w) |
187 |
self.w(u'<div class="clear"/>') |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
188 |
|
2204
3472c5498478
use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2115
diff
changeset
|
189 |
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
|
190 |
cellvids, cellattrs, mainindex): |
0 | 191 |
columns = [] |
3729
e4f20b74af51
remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3720
diff
changeset
|
192 |
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
|
193 |
for colindex, label in enumerate(computed_labels): |
0 | 194 |
if colindex not in displaycols: |
195 |
continue |
|
196 |
# compute column header |
|
197 |
if headers is not None: |
|
198 |
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
|
199 |
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
|
200 |
label += ' (%s)' % self.cw_rset.rowcount |
7830
37d23a1d3547
[views/table] parametrize table view co-classes (closes #1947472)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7814
diff
changeset
|
201 |
column = self.table_column_class(label, colindex) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
202 |
coltype = self.cw_rset.description[0][colindex] |
0 | 203 |
# compute column cell view (if coltype is None, it's a left outer |
204 |
# join, use the default non final subvid) |
|
205 |
if cellvids and colindex in cellvids: |
|
206 |
column.append_renderer(cellvids[colindex], colindex) |
|
3729
e4f20b74af51
remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3720
diff
changeset
|
207 |
elif coltype is not None and eschema(coltype).final: |
0 | 208 |
column.append_renderer(self.finalview, colindex) |
209 |
else: |
|
210 |
column.append_renderer(subvid or 'incontext', colindex) |
|
211 |
if cellattrs and colindex in cellattrs: |
|
212 |
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
|
213 |
column.add_attr(name, value) |
0 | 214 |
# add column |
215 |
columns.append(column) |
|
216 |
return columns |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
217 |
|
0 | 218 |
|
1730
cec526a96535
fix 'render' method name conflict
sylvain.thenault@logilab.fr
parents:
1635
diff
changeset
|
219 |
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
|
220 |
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
|
221 |
|
0 | 222 |
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
|
223 |
return self.cw_rset |
0 | 224 |
|
225 |
@htmlescape |
|
226 |
@jsonize |
|
227 |
@limitsize(10) |
|
228 |
def sortvalue(self, row, col): |
|
229 |
# XXX it might be interesting to try to limit value's |
|
230 |
# length as much as possible (e.g. by returning the 10 |
|
231 |
# 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
|
232 |
val = self.cw_rset[row][col] |
0 | 233 |
if val is None: |
234 |
return u'' |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
235 |
etype = self.cw_rset.description[row][col] |
6104
a57db3faa913
[tableview] take care, description may include None (try Any NULL)
Alexandre Richardson <alexandre.richardson@logilab.fr>
parents:
5997
diff
changeset
|
236 |
if etype is None: |
a57db3faa913
[tableview] take care, description may include None (try Any NULL)
Alexandre Richardson <alexandre.richardson@logilab.fr>
parents:
5997
diff
changeset
|
237 |
return u'' |
3729
e4f20b74af51
remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3720
diff
changeset
|
238 |
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
|
239 |
entity, rtype = self.cw_rset.related_entity(row, col) |
0 | 240 |
if entity is None: |
241 |
return val # remove_html_tags() ? |
|
242 |
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
|
243 |
entity = self.cw_rset.get_entity(row, col) |
0 | 244 |
return entity.sortvalue() |
245 |
||
843 | 246 |
|
0 | 247 |
class EditableTableView(TableView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
248 |
__regid__ = 'editable-table' |
0 | 249 |
finalview = 'editable-final' |
250 |
title = _('editable-table') |
|
251 |
||
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
252 |
|
0 | 253 |
class CellView(EntityView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
254 |
__regid__ = 'cell' |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
255 |
__select__ = nonempty_rset() |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
256 |
|
0 | 257 |
def cell_call(self, row, col, cellvid=None): |
258 |
""" |
|
259 |
:param row, col: indexes locating the cell value in view's result set |
|
260 |
:param cellvid: cell view (defaults to 'outofcontext') |
|
261 |
""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
262 |
etype, val = self.cw_rset.description[row][col], self.cw_rset[row][col] |
7814
1ec9fe1dfba9
[tableview] fix view selection when value is None (closes #1936781)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7600
diff
changeset
|
263 |
if etype is None or not self._cw.vreg.schema.eschema(etype).final: |
1ec9fe1dfba9
[tableview] fix view selection when value is None (closes #1936781)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7600
diff
changeset
|
264 |
if val is None: |
1ec9fe1dfba9
[tableview] fix view selection when value is None (closes #1936781)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7600
diff
changeset
|
265 |
# This is usually caused by a left outer join and in that case, |
1ec9fe1dfba9
[tableview] fix view selection when value is None (closes #1936781)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7600
diff
changeset
|
266 |
# regular views will most certainly fail if they don't have |
1ec9fe1dfba9
[tableview] fix view selection when value is None (closes #1936781)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7600
diff
changeset
|
267 |
# a real eid |
1ec9fe1dfba9
[tableview] fix view selection when value is None (closes #1936781)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7600
diff
changeset
|
268 |
# XXX if cellvid is e.g. reledit, we may wanna call it anyway |
1ec9fe1dfba9
[tableview] fix view selection when value is None (closes #1936781)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7600
diff
changeset
|
269 |
self.w(u' ') |
1ec9fe1dfba9
[tableview] fix view selection when value is None (closes #1936781)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7600
diff
changeset
|
270 |
else: |
1ec9fe1dfba9
[tableview] fix view selection when value is None (closes #1936781)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7600
diff
changeset
|
271 |
self.wview(cellvid or 'outofcontext', self.cw_rset, row=row, col=col) |
0 | 272 |
else: |
7814
1ec9fe1dfba9
[tableview] fix view selection when value is None (closes #1936781)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7600
diff
changeset
|
273 |
# XXX why do we need a fallback view here? |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
274 |
self.wview(cellvid or 'final', self.cw_rset, 'null', row=row, col=col) |
0 | 275 |
|
276 |
||
277 |
class InitialTableView(TableView): |
|
278 |
"""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
|
279 |
|
0 | 280 |
* the default query (ie `rql` form parameter), which is only used to select |
281 |
this view and to build the filter form. This query should have the same |
|
282 |
structure as the actual without actual restriction (but link to |
|
283 |
restriction variables) and usually with a limit for efficiency (limit set |
|
284 |
to 2 is advised) |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
285 |
|
0 | 286 |
* the actual query (`actualrql` form parameter) whose results will be |
287 |
displayed with default restrictions set |
|
288 |
""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
289 |
__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
|
290 |
__select__ = nonempty_rset() |
0 | 291 |
# should not be displayed in possible view since it expects some specific |
292 |
# parameters |
|
293 |
title = None |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
294 |
|
469 | 295 |
def call(self, title=None, subvid=None, headers=None, divid=None, |
6240 | 296 |
paginate=False, displaycols=None, displayactions=None, |
297 |
mainindex=None): |
|
0 | 298 |
"""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
|
299 |
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
|
300 |
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
|
301 |
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
|
302 |
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
|
303 |
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
|
304 |
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
|
305 |
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
|
306 |
if displayactions is None and 'displayactions' in self._cw.form: |
0 | 307 |
displayactions = True |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
308 |
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
|
309 |
divid = self._cw.form['divid'] |
0 | 310 |
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
|
311 |
if not title and 'title' in self._cw.form: |
0 | 312 |
# 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
|
313 |
title = self._cw.form.pop('title') |
0 | 314 |
if title: |
315 |
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
|
316 |
if mainindex is None: |
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
317 |
mainindex = self.main_var_index() |
0 | 318 |
if mainindex is not None: |
5669
1340f14c38c9
[table] propagate paginate
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5668
diff
changeset
|
319 |
actions = self.form_filter(divid, displaycols, displayactions, |
6240 | 320 |
displayfilter=True, paginate=paginate, |
321 |
hidden=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
|
322 |
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
|
323 |
actions = () |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
324 |
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
|
325 |
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
|
326 |
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
|
327 |
'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
|
328 |
displayactions=displayactions, displaycols=displaycols, |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
329 |
actions=actions, headers=headers, divid=divid) |
0 | 330 |
self.w(u'</div>\n') |
331 |
||
332 |
||
527 | 333 |
class EditableInitialTableTableView(InitialTableView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
334 |
__regid__ = 'editable-initialtable' |
0 | 335 |
finalview = 'editable-final' |
5234
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
336 |
|
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
337 |
|
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
338 |
class EntityAttributesTableView(EntityView): |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
339 |
"""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
|
340 |
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
|
341 |
column header. |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
342 |
|
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
343 |
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
|
344 |
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
|
345 |
|
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
346 |
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
|
347 |
defined otherwise COLNAME will be used. |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
348 |
""" |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
349 |
__abstract__ = True |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
350 |
columns = () |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
351 |
table_css = "listing" |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
352 |
css_files = () |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
353 |
|
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
354 |
def call(self, columns=None): |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
355 |
if self.css_files: |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
356 |
self._cw.add_css(self.css_files) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
357 |
_ = self._cw._ |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
358 |
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
|
359 |
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
|
360 |
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
|
361 |
self.table_header(sample) |
5234
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
362 |
self.w(u'<tbody>') |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
363 |
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
|
364 |
self.cell_call(row=row, col=0) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
365 |
self.w(u'</tbody>') |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
366 |
self.w(u'</table>') |
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 |
def cell_call(self, row, col): |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
369 |
_ = self._cw._ |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
370 |
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
|
371 |
infos = {} |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
372 |
for col in self.columns: |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
373 |
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
|
374 |
# 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
|
375 |
if meth: |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
376 |
content = meth(entity) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
377 |
else: |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
378 |
content = entity.printable_value(col) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
379 |
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
|
380 |
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
|
381 |
onmouseout="$(this).removeClass('highlighted')">""") |
5234
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
382 |
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
|
383 |
self.w(line % infos) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
384 |
self.w(u'</tr>\n') |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
385 |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5545
diff
changeset
|
386 |
def table_header(self, sample): |
5234
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
387 |
"""builds the table's header""" |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
388 |
self.w(u'<thead><tr>') |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
389 |
for column in self.columns: |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
390 |
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
|
391 |
if meth: |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5545
diff
changeset
|
392 |
colname = meth(sample) |
5234
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
393 |
else: |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5545
diff
changeset
|
394 |
colname = self._cw._(column) |
5234
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
395 |
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
|
396 |
self.w(u'</tr></thead>\n') |
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 |