author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 14 Apr 2010 10:29:38 +0200 | |
changeset 5244 | 5467674ad101 |
parent 5239 | 471554b842d2 |
child 5328 | c51e8f62652a |
permissions | -rw-r--r-- |
0 | 1 |
"""generic table view, including filtering abilities |
2 |
||
3 |
||
4 |
:organization: Logilab |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3842
diff
changeset
|
5 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1730
diff
changeset
|
7 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 8 |
""" |
9 |
__docformat__ = "restructuredtext en" |
|
10 |
||
11 |
from simplejson import dumps |
|
12 |
||
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2226
diff
changeset
|
13 |
from logilab.mtconverter import xml_escape |
0 | 14 |
|
1132 | 15 |
from cubicweb.selectors import nonempty_rset, match_form_params |
762 | 16 |
from cubicweb.utils import make_uid |
17 |
from cubicweb.view import EntityView, AnyRsetView |
|
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
18 |
from cubicweb import tags |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
19 |
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
|
20 |
from cubicweb.web import jsonize |
0 | 21 |
from cubicweb.web.htmlwidgets import (TableWidget, TableColumn, MenuWidget, |
762 | 22 |
PopupBoxMenu, BoxLink) |
0 | 23 |
from cubicweb.web.facet import prepare_facets_rqlst, filter_hiddens |
24 |
||
25 |
class TableView(AnyRsetView): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
26 |
__regid__ = 'table' |
0 | 27 |
title = _('table') |
28 |
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
|
29 |
|
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
|
30 |
def form_filter(self, divid, displaycols, displayactions, 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
|
31 |
hidden=True): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
32 |
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
|
33 |
# 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
|
34 |
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
|
35 |
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
|
36 |
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
|
37 |
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
|
38 |
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
|
39 |
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
|
40 |
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
|
41 |
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
|
42 |
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
|
43 |
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
|
44 |
self._generate_form(divid, baserql, wdgs, hidden, |
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
|
45 |
vidargs={'displaycols': displaycols, |
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
|
46 |
'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
|
47 |
'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
|
48 |
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
|
49 |
return () |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
50 |
|
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
|
51 |
def _generate_form(self, divid, baserql, fwidgets, hidden=True, vidargs={}): |
0 | 52 |
"""display a form to filter table's content. This should only |
53 |
occurs when a context eid is given |
|
54 |
""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
55 |
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
|
56 |
self._cw.add_js( ('cubicweb.ajax.js', 'cubicweb.facets.js')) |
0 | 57 |
# drop False / None values from vidargs |
58 |
vidargs = dict((k, v) for k, v in vidargs.iteritems() if v) |
|
59 |
self.w(u'<form method="post" cubicweb:facetargs="%s" action="">' % |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2226
diff
changeset
|
60 |
xml_escape(dumps([divid, 'table', False, vidargs]))) |
0 | 61 |
self.w(u'<fieldset id="%sForm" class="%s">' % (divid, hidden and 'hidden' or '')) |
62 |
self.w(u'<input type="hidden" name="divid" value="%s" />' % divid) |
|
3129
fab471bee6c1
[facets] duhh, necessary fromformfilter hidden was missing
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3128
diff
changeset
|
63 |
self.w(u'<input type="hidden" name="fromformfilter" value="1" />') |
3457
0924d0d08d60
[api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
64 |
filter_hiddens(self.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
|
65 |
baserql=baserql) |
0 | 66 |
self.w(u'<table class="filter">\n') |
67 |
self.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
|
68 |
for wdg in fwidgets: |
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
|
69 |
self.w(u'<td>') |
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 |
wdg.render(w=self.w) |
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
|
71 |
self.w(u'</td>\n') |
0 | 72 |
self.w(u'</tr>\n') |
73 |
self.w(u'</table>\n') |
|
74 |
self.w(u'</fieldset>\n') |
|
75 |
self.w(u'</form>\n') |
|
76 |
||
77 |
def main_var_index(self): |
|
78 |
"""returns the index of the first non-attribute variable among the RQL |
|
79 |
selected variables |
|
80 |
""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
81 |
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
|
82 |
for i, etype in enumerate(self.cw_rset.description[0]): |
0 | 83 |
try: |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3228
diff
changeset
|
84 |
if not eschema(etype).final: |
0 | 85 |
return i |
86 |
except KeyError: # XXX possible? |
|
87 |
continue |
|
88 |
return None |
|
89 |
||
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
|
90 |
def displaycols(self, displaycols, headers): |
0 | 91 |
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
|
92 |
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
|
93 |
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
|
94 |
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
|
95 |
displaycols = range(len(headers)) |
0 | 96 |
else: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
97 |
displaycols = range(len(self.cw_rset.syntax_tree().children[0].selection)) |
0 | 98 |
return displaycols |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
99 |
|
0 | 100 |
def call(self, title=None, subvid=None, displayfilter=None, headers=None, |
469 | 101 |
displaycols=None, displayactions=None, actions=(), divid=None, |
2226
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
102 |
cellvids=None, cellattrs=None, mainindex=None): |
0 | 103 |
"""Dumps a table displaying a composite query |
104 |
||
105 |
:param title: title added before table |
|
106 |
:param subvid: cell view |
|
107 |
:param displayfilter: filter that selects rows to display |
|
108 |
:param headers: columns' titles |
|
109 |
""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
110 |
req = self._cw |
0 | 111 |
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
|
112 |
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
|
113 |
# 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
|
114 |
# information from the rql syntax tree |
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
115 |
if mainindex is None: |
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
116 |
mainindex = self.main_var_index() |
2206
009e2856afcb
columns_labels is an AnyRsetView method...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2204
diff
changeset
|
117 |
computed_labels = self.columns_labels(mainindex) |
0 | 118 |
hidden = True |
119 |
if not subvid and 'subvid' in req.form: |
|
120 |
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
|
121 |
divid = divid or req.form.get('divid') or 'rs%s' % make_uid(id(self.cw_rset)) |
0 | 122 |
actions = list(actions) |
123 |
if mainindex is None: |
|
124 |
displayfilter, displayactions = False, False |
|
125 |
else: |
|
126 |
if displayfilter is None and 'displayfilter' in req.form: |
|
127 |
displayfilter = True |
|
128 |
if req.form['displayfilter'] == 'shown': |
|
129 |
hidden = False |
|
130 |
if displayactions is None and 'displayactions' in req.form: |
|
131 |
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
|
132 |
displaycols = self.displaycols(displaycols, headers) |
0 | 133 |
fromformfilter = 'fromformfilter' in req.form |
134 |
# if fromformfilter is true, this is an ajax call and we only want to |
|
135 |
# replace the inner div, so don't regenerate everything under the if |
|
136 |
# below |
|
137 |
if not fromformfilter: |
|
3009 | 138 |
self.w(u'<div class="section">') |
0 | 139 |
if not title and 'title' in req.form: |
140 |
title = req.form['title'] |
|
141 |
if title: |
|
142 |
self.w(u'<h2 class="tableTitle">%s</h2>\n' % title) |
|
143 |
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
|
144 |
actions += self.form_filter(divid, displaycols, 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
|
145 |
displayactions) |
0 | 146 |
elif displayfilter: |
147 |
actions += self.show_hide_actions(divid, True) |
|
148 |
self.w(u'<div id="%s"' % divid) |
|
149 |
if displayactions: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
150 |
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
|
151 |
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
|
152 |
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
|
153 |
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
|
154 |
action.html_class(), None) ) |
0 | 155 |
self.w(u' cubicweb:displayactions="1">') # close <div tag |
156 |
else: |
|
157 |
self.w(u'>') # close <div tag |
|
158 |
# render actions menu |
|
159 |
if actions: |
|
160 |
self.render_actions(divid, actions) |
|
161 |
# render table |
|
162 |
table = TableWidget(self) |
|
2204
3472c5498478
use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2115
diff
changeset
|
163 |
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
|
164 |
subvid, cellvids, cellattrs, mainindex): |
0 | 165 |
table.append_column(column) |
166 |
table.render(self.w) |
|
167 |
self.w(u'</div>\n') |
|
168 |
if not fromformfilter: |
|
169 |
self.w(u'</div>\n') |
|
170 |
||
171 |
def show_hide_actions(self, divid, currentlydisplayed=False): |
|
172 |
showhide = u';'.join(toggle_action('%s%s' % (divid, what))[11:] |
|
173 |
for what in ('Form', 'Show', 'Hide', 'Actions')) |
|
174 |
showhide = 'javascript:' + showhide |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
175 |
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
|
176 |
hidelabel = self._cw._('hide filter form') |
0 | 177 |
if currentlydisplayed: |
178 |
return [(showhide, showlabel, 'hidden', '%sShow' % divid), |
|
179 |
(showhide, hidelabel, None, '%sHide' % divid)] |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
180 |
return [(showhide, showlabel, None, '%sShow' % divid), |
0 | 181 |
(showhide, hidelabel, 'hidden', '%sHide' % divid)] |
182 |
||
183 |
def render_actions(self, divid, actions): |
|
184 |
box = MenuWidget('', 'tableActionsBox', _class='', islist=False) |
|
3890
d7a270f50f54
backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
185 |
label = tags.img(src=self._cw.external_resource('PUCE_DOWN'), |
d7a270f50f54
backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
186 |
alt=xml_escape(self._cw._('action(s) on this selection'))) |
0 | 187 |
menu = PopupBoxMenu(label, isitem=False, link_class='actionsBox', |
188 |
ident='%sActions' % divid) |
|
189 |
box.append(menu) |
|
190 |
for url, label, klass, ident in actions: |
|
191 |
menu.append(BoxLink(url, label, klass, ident=ident, escape=True)) |
|
192 |
box.render(w=self.w) |
|
193 |
self.w(u'<div class="clear"/>') |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
194 |
|
2204
3472c5498478
use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2115
diff
changeset
|
195 |
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
|
196 |
cellvids, cellattrs, mainindex): |
0 | 197 |
columns = [] |
3729
e4f20b74af51
remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3720
diff
changeset
|
198 |
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
|
199 |
for colindex, label in enumerate(computed_labels): |
0 | 200 |
if colindex not in displaycols: |
201 |
continue |
|
202 |
# compute column header |
|
203 |
if headers is not None: |
|
204 |
label = headers[displaycols.index(colindex)] |
|
205 |
if colindex == mainindex: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
206 |
label += ' (%s)' % self.cw_rset.rowcount |
0 | 207 |
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
|
208 |
coltype = self.cw_rset.description[0][colindex] |
0 | 209 |
# compute column cell view (if coltype is None, it's a left outer |
210 |
# join, use the default non final subvid) |
|
211 |
if cellvids and colindex in cellvids: |
|
212 |
column.append_renderer(cellvids[colindex], colindex) |
|
3729
e4f20b74af51
remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3720
diff
changeset
|
213 |
elif coltype is not None and eschema(coltype).final: |
0 | 214 |
column.append_renderer(self.finalview, colindex) |
215 |
else: |
|
216 |
column.append_renderer(subvid or 'incontext', colindex) |
|
217 |
if cellattrs and colindex in cellattrs: |
|
218 |
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
|
219 |
column.add_attr(name, value) |
0 | 220 |
# add column |
221 |
columns.append(column) |
|
222 |
return columns |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
223 |
|
0 | 224 |
|
1730
cec526a96535
fix 'render' method name conflict
sylvain.thenault@logilab.fr
parents:
1635
diff
changeset
|
225 |
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
|
226 |
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
|
227 |
|
0 | 228 |
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
|
229 |
return self.cw_rset |
0 | 230 |
|
231 |
@htmlescape |
|
232 |
@jsonize |
|
233 |
@limitsize(10) |
|
234 |
def sortvalue(self, row, col): |
|
235 |
# XXX it might be interesting to try to limit value's |
|
236 |
# length as much as possible (e.g. by returning the 10 |
|
237 |
# 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
|
238 |
val = self.cw_rset[row][col] |
0 | 239 |
if val is None: |
240 |
return u'' |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
241 |
etype = self.cw_rset.description[row][col] |
3729
e4f20b74af51
remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3720
diff
changeset
|
242 |
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
|
243 |
entity, rtype = self.cw_rset.related_entity(row, col) |
0 | 244 |
if entity is None: |
245 |
return val # remove_html_tags() ? |
|
246 |
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
|
247 |
entity = self.cw_rset.get_entity(row, col) |
0 | 248 |
return entity.sortvalue() |
249 |
||
843 | 250 |
|
0 | 251 |
class EditableTableView(TableView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
252 |
__regid__ = 'editable-table' |
0 | 253 |
finalview = 'editable-final' |
254 |
title = _('editable-table') |
|
255 |
||
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
256 |
|
0 | 257 |
class CellView(EntityView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
258 |
__regid__ = 'cell' |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
259 |
__select__ = nonempty_rset() |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
260 |
|
0 | 261 |
def cell_call(self, row, col, cellvid=None): |
262 |
""" |
|
263 |
:param row, col: indexes locating the cell value in view's result set |
|
264 |
:param cellvid: cell view (defaults to 'outofcontext') |
|
265 |
""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
266 |
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
|
267 |
if val is not None and not 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
|
268 |
e = self.cw_rset.get_entity(row, col) |
0 | 269 |
e.view(cellvid or 'outofcontext', w=self.w) |
270 |
elif val is None: |
|
271 |
# This is usually caused by a left outer join and in that case, |
|
272 |
# regular views will most certainly fail if they don't have |
|
273 |
# a real eid |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
274 |
self.wview('final', self.cw_rset, row=row, col=col) |
0 | 275 |
else: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
276 |
self.wview(cellvid or 'final', self.cw_rset, 'null', row=row, col=col) |
0 | 277 |
|
278 |
||
279 |
class InitialTableView(TableView): |
|
280 |
"""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
|
281 |
|
0 | 282 |
* the default query (ie `rql` form parameter), which is only used to select |
283 |
this view and to build the filter form. This query should have the same |
|
284 |
structure as the actual without actual restriction (but link to |
|
285 |
restriction variables) and usually with a limit for efficiency (limit set |
|
286 |
to 2 is advised) |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
287 |
|
0 | 288 |
* the actual query (`actualrql` form parameter) whose results will be |
289 |
displayed with default restrictions set |
|
290 |
""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
291 |
__regid__ = 'initialtable' |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
292 |
__select__ = nonempty_rset() & match_form_params('actualrql') |
0 | 293 |
# should not be displayed in possible view since it expects some specific |
294 |
# parameters |
|
295 |
title = None |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
296 |
|
469 | 297 |
def call(self, title=None, subvid=None, headers=None, divid=None, |
2226
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
298 |
displaycols=None, displayactions=None, mainindex=None): |
0 | 299 |
"""Dumps a table displaying a composite query""" |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
300 |
actrql = self._cw.form['actualrql'] |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
301 |
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
|
302 |
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
|
303 |
if displayactions is None and 'displayactions' in self._cw.form: |
0 | 304 |
displayactions = True |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
305 |
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
|
306 |
divid = self._cw.form['divid'] |
0 | 307 |
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
|
308 |
if not title and 'title' in self._cw.form: |
0 | 309 |
# 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
|
310 |
title = self._cw.form.pop('title') |
0 | 311 |
if title: |
312 |
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
|
313 |
if mainindex is None: |
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
314 |
mainindex = self.main_var_index() |
0 | 315 |
if mainindex is not None: |
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
|
316 |
actions = self.form_filter(divid, displaycols, displayactions, True) |
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
|
317 |
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
|
318 |
actions = () |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
319 |
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
|
320 |
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
|
321 |
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
|
322 |
'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
|
323 |
displayactions=displayactions, displaycols=displaycols, |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
324 |
actions=actions, headers=headers, divid=divid) |
0 | 325 |
self.w(u'</div>\n') |
326 |
||
327 |
||
527 | 328 |
class EditableInitialTableTableView(InitialTableView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
329 |
__regid__ = 'editable-initialtable' |
0 | 330 |
finalview = 'editable-final' |
5234
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
331 |
|
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
332 |
|
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
333 |
class EntityAttributesTableView(EntityView): |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
334 |
"""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
|
335 |
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
|
336 |
column header. |
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 |
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
|
339 |
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
|
340 |
|
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
341 |
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
|
342 |
defined otherwise COLNAME will be used. |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
343 |
""" |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
344 |
__abstract__ = True |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
345 |
columns = () |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
346 |
table_css = "listing" |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
347 |
css_files = () |
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 |
def call(self, columns=None): |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
350 |
if self.css_files: |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
351 |
self._cw.add_css(self.css_files) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
352 |
_ = self._cw._ |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
353 |
self.columns = columns or self.columns |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
354 |
ecls = self._cw.vreg['etypes'].etype_class(self.cw_rset.description[0][0]) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
355 |
self.w(u'<table class="%s">' % self.table_css) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
356 |
self.table_header(ecls) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
357 |
self.w(u'<tbody>') |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
358 |
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
|
359 |
self.cell_call(row=row, col=0) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
360 |
self.w(u'</tbody>') |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
361 |
self.w(u'</table>') |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
362 |
|
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
363 |
def cell_call(self, row, col): |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
364 |
_ = self._cw._ |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
365 |
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
|
366 |
infos = {} |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
367 |
for col in self.columns: |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
368 |
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
|
369 |
# 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
|
370 |
if meth: |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
371 |
content = meth(entity) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
372 |
else: |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
373 |
content = entity.printable_value(col) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
374 |
infos[col] = content |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
375 |
self.w(u"""<tr onmouseover="addElementClass(this, 'highlighted');" |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
376 |
onmouseout="removeElementClass(this, 'highlighted')">""") |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
377 |
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
|
378 |
self.w(line % infos) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
379 |
self.w(u'</tr>\n') |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
380 |
|
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
381 |
def table_header(self, ecls): |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
382 |
"""builds the table's header""" |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
383 |
self.w(u'<thead><tr>') |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
384 |
_ = self._cw._ |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
385 |
for column in self.columns: |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
386 |
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
|
387 |
if meth: |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
388 |
colname = meth(ecls) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
389 |
else: |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
390 |
colname = _(column) |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
391 |
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
|
392 |
self.w(u'</tr></thead>\n') |
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
393 |
|
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4618
diff
changeset
|
394 |