author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 23 Sep 2009 19:16:44 +0200 | |
changeset 3445 | 32492e9e734b |
parent 3377 | dd9d292b6a6d |
child 3451 | 6b46d73823f5 |
permissions | -rw-r--r-- |
0 | 1 |
"""generic table view, including filtering abilities |
2 |
||
3 |
||
4 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1730
diff
changeset
|
5 |
:copyright: 2001-2009 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 |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
18 |
from cubicweb.common.uilib import toggle_action, limitsize, htmlescape |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
19 |
from cubicweb.web import jsonize |
0 | 20 |
from cubicweb.web.htmlwidgets import (TableWidget, TableColumn, MenuWidget, |
762 | 21 |
PopupBoxMenu, BoxLink) |
0 | 22 |
from cubicweb.web.facet import prepare_facets_rqlst, filter_hiddens |
23 |
||
24 |
class TableView(AnyRsetView): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
25 |
__regid__ = 'table' |
0 | 26 |
title = _('table') |
27 |
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
|
28 |
|
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 |
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
|
30 |
hidden=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
|
31 |
rqlst = self.rset.syntax_tree() |
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
|
32 |
# 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
|
33 |
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
|
34 |
return () |
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 |
rqlst.save_state() |
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
|
36 |
mainvar, baserql = prepare_facets_rqlst(rqlst, self.rset.args) |
2813
0cf6c8005bf6
R propagate deprecation of CWRegistry.possible_vobjects
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2792
diff
changeset
|
37 |
wdgs = [facet.get_widget() for facet in self.vreg['facets'].poss_visible_objects( |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
38 |
self.req, rset=self.rset, 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
|
39 |
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
|
40 |
wdgs = [wdg for wdg in wdgs if wdg 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
|
41 |
rqlst.recover() |
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
|
42 |
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
|
43 |
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
|
44 |
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
|
45 |
'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
|
46 |
'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
|
47 |
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
|
48 |
return () |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
49 |
|
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
|
50 |
def _generate_form(self, divid, baserql, fwidgets, hidden=True, vidargs={}): |
0 | 51 |
"""display a form to filter table's content. This should only |
52 |
occurs when a context eid is given |
|
53 |
""" |
|
3128
37c310ca6506
include facets.css so we're sure it's there when needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3009
diff
changeset
|
54 |
self.req.add_css('cubicweb.facets.css') |
3006
4d85386b06a5
rename cubicweb.formfilter.js into cubicweb.facets.js
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2677
diff
changeset
|
55 |
self.req.add_js( ('cubicweb.ajax.js', 'cubicweb.facets.js')) |
0 | 56 |
# drop False / None values from vidargs |
57 |
vidargs = dict((k, v) for k, v in vidargs.iteritems() if v) |
|
58 |
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
|
59 |
xml_escape(dumps([divid, 'table', False, vidargs]))) |
0 | 60 |
self.w(u'<fieldset id="%sForm" class="%s">' % (divid, hidden and 'hidden' or '')) |
61 |
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
|
62 |
self.w(u'<input type="hidden" name="fromformfilter" value="1" />') |
fab471bee6c1
[facets] duhh, necessary fromformfilter hidden was missing
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3128
diff
changeset
|
63 |
filter_hiddens(self.w, facets=','.join(wdg.facet.id for wdg in fwidgets), |
fab471bee6c1
[facets] duhh, necessary fromformfilter hidden was missing
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3128
diff
changeset
|
64 |
baserql=baserql) |
0 | 65 |
self.w(u'<table class="filter">\n') |
66 |
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
|
67 |
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
|
68 |
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
|
69 |
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
|
70 |
self.w(u'</td>\n') |
0 | 71 |
self.w(u'</tr>\n') |
72 |
self.w(u'</table>\n') |
|
73 |
self.w(u'</fieldset>\n') |
|
74 |
self.w(u'</form>\n') |
|
75 |
||
76 |
def main_var_index(self): |
|
77 |
"""returns the index of the first non-attribute variable among the RQL |
|
78 |
selected variables |
|
79 |
""" |
|
80 |
eschema = self.vreg.schema.eschema |
|
81 |
for i, etype in enumerate(self.rset.description[0]): |
|
82 |
try: |
|
83 |
if not eschema(etype).is_final(): |
|
84 |
return i |
|
85 |
except KeyError: # XXX possible? |
|
86 |
continue |
|
87 |
return None |
|
88 |
||
89 |
def displaycols(self, displaycols): |
|
90 |
if displaycols is None: |
|
91 |
if 'displaycols' in self.req.form: |
|
92 |
displaycols = [int(idx) for idx in self.req.form['displaycols']] |
|
93 |
else: |
|
94 |
displaycols = range(len(self.rset.syntax_tree().children[0].selection)) |
|
95 |
return displaycols |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
96 |
|
0 | 97 |
def call(self, title=None, subvid=None, displayfilter=None, headers=None, |
469 | 98 |
displaycols=None, displayactions=None, actions=(), divid=None, |
2226
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
99 |
cellvids=None, cellattrs=None, mainindex=None): |
0 | 100 |
"""Dumps a table displaying a composite query |
101 |
||
102 |
:param title: title added before table |
|
103 |
:param subvid: cell view |
|
104 |
:param displayfilter: filter that selects rows to display |
|
105 |
:param headers: columns' titles |
|
106 |
""" |
|
107 |
req = self.req |
|
108 |
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
|
109 |
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
|
110 |
# 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
|
111 |
# information from the rql syntax tree |
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
112 |
if mainindex is None: |
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
113 |
mainindex = self.main_var_index() |
2206
009e2856afcb
columns_labels is an AnyRsetView method...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2204
diff
changeset
|
114 |
computed_labels = self.columns_labels(mainindex) |
0 | 115 |
hidden = True |
116 |
if not subvid and 'subvid' in req.form: |
|
117 |
subvid = req.form.pop('subvid') |
|
2226
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
118 |
divid = divid or req.form.get('divid') or 'rs%s' % make_uid(id(self.rset)) |
0 | 119 |
actions = list(actions) |
120 |
if mainindex is None: |
|
121 |
displayfilter, displayactions = False, False |
|
122 |
else: |
|
123 |
if displayfilter is None and 'displayfilter' in req.form: |
|
124 |
displayfilter = True |
|
125 |
if req.form['displayfilter'] == 'shown': |
|
126 |
hidden = False |
|
127 |
if displayactions is None and 'displayactions' in req.form: |
|
128 |
displayactions = True |
|
129 |
displaycols = self.displaycols(displaycols) |
|
130 |
fromformfilter = 'fromformfilter' in req.form |
|
131 |
# if fromformfilter is true, this is an ajax call and we only want to |
|
132 |
# replace the inner div, so don't regenerate everything under the if |
|
133 |
# below |
|
134 |
if not fromformfilter: |
|
3009 | 135 |
self.w(u'<div class="section">') |
0 | 136 |
if not title and 'title' in req.form: |
137 |
title = req.form['title'] |
|
138 |
if title: |
|
139 |
self.w(u'<h2 class="tableTitle">%s</h2>\n' % title) |
|
140 |
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
|
141 |
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
|
142 |
displayactions) |
0 | 143 |
elif displayfilter: |
144 |
actions += self.show_hide_actions(divid, True) |
|
145 |
self.w(u'<div id="%s"' % divid) |
|
146 |
if displayactions: |
|
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
|
147 |
actionsbycat = self.vreg['actions'].possible_actions(req, self.rset) |
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
|
148 |
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
|
149 |
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
|
150 |
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
|
151 |
action.html_class(), None) ) |
0 | 152 |
self.w(u' cubicweb:displayactions="1">') # close <div tag |
153 |
else: |
|
154 |
self.w(u'>') # close <div tag |
|
155 |
# render actions menu |
|
156 |
if actions: |
|
157 |
self.render_actions(divid, actions) |
|
158 |
# render table |
|
159 |
table = TableWidget(self) |
|
2204
3472c5498478
use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2115
diff
changeset
|
160 |
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
|
161 |
subvid, cellvids, cellattrs, mainindex): |
0 | 162 |
table.append_column(column) |
163 |
table.render(self.w) |
|
164 |
self.w(u'</div>\n') |
|
165 |
if not fromformfilter: |
|
166 |
self.w(u'</div>\n') |
|
167 |
||
168 |
||
169 |
def show_hide_actions(self, divid, currentlydisplayed=False): |
|
170 |
showhide = u';'.join(toggle_action('%s%s' % (divid, what))[11:] |
|
171 |
for what in ('Form', 'Show', 'Hide', 'Actions')) |
|
172 |
showhide = 'javascript:' + showhide |
|
173 |
showlabel = self.req._('show filter form') |
|
174 |
hidelabel = self.req._('hide filter form') |
|
175 |
if currentlydisplayed: |
|
176 |
return [(showhide, showlabel, 'hidden', '%sShow' % divid), |
|
177 |
(showhide, hidelabel, None, '%sHide' % divid)] |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
178 |
return [(showhide, showlabel, None, '%sShow' % divid), |
0 | 179 |
(showhide, hidelabel, 'hidden', '%sHide' % divid)] |
180 |
||
181 |
def render_actions(self, divid, actions): |
|
182 |
box = MenuWidget('', 'tableActionsBox', _class='', islist=False) |
|
183 |
label = '<img src="%s" alt="%s"/>' % ( |
|
184 |
self.req.datadir_url + 'liveclipboard-icon.png', |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2226
diff
changeset
|
185 |
xml_escape(self.req._('action(s) on this selection'))) |
0 | 186 |
menu = PopupBoxMenu(label, isitem=False, link_class='actionsBox', |
187 |
ident='%sActions' % divid) |
|
188 |
box.append(menu) |
|
189 |
for url, label, klass, ident in actions: |
|
190 |
menu.append(BoxLink(url, label, klass, ident=ident, escape=True)) |
|
191 |
box.render(w=self.w) |
|
192 |
self.w(u'<div class="clear"/>') |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
193 |
|
2204
3472c5498478
use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2115
diff
changeset
|
194 |
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
|
195 |
cellvids, cellattrs, mainindex): |
0 | 196 |
columns = [] |
2204
3472c5498478
use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2115
diff
changeset
|
197 |
for colindex, label in enumerate(computed_labels): |
0 | 198 |
if colindex not in displaycols: |
199 |
continue |
|
200 |
# compute column header |
|
201 |
if headers is not None: |
|
202 |
label = headers[displaycols.index(colindex)] |
|
203 |
if colindex == mainindex: |
|
204 |
label += ' (%s)' % self.rset.rowcount |
|
205 |
column = TableColumn(label, colindex) |
|
206 |
coltype = self.rset.description[0][colindex] |
|
207 |
# compute column cell view (if coltype is None, it's a left outer |
|
208 |
# join, use the default non final subvid) |
|
209 |
if cellvids and colindex in cellvids: |
|
210 |
column.append_renderer(cellvids[colindex], colindex) |
|
211 |
elif coltype is not None and self.schema.eschema(coltype).is_final(): |
|
212 |
column.append_renderer(self.finalview, colindex) |
|
213 |
else: |
|
214 |
column.append_renderer(subvid or 'incontext', colindex) |
|
215 |
if cellattrs and colindex in cellattrs: |
|
216 |
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
|
217 |
column.add_attr(name, value) |
0 | 218 |
# add column |
219 |
columns.append(column) |
|
220 |
return columns |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
221 |
|
0 | 222 |
|
1730
cec526a96535
fix 'render' method name conflict
sylvain.thenault@logilab.fr
parents:
1635
diff
changeset
|
223 |
def render_cell(self, cellvid, row, col, w): |
0 | 224 |
self.view('cell', self.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
|
225 |
|
0 | 226 |
def get_rows(self): |
227 |
return self.rset |
|
228 |
||
229 |
@htmlescape |
|
230 |
@jsonize |
|
231 |
@limitsize(10) |
|
232 |
def sortvalue(self, row, col): |
|
233 |
# XXX it might be interesting to try to limit value's |
|
234 |
# length as much as possible (e.g. by returning the 10 |
|
235 |
# first characters of a string) |
|
236 |
val = self.rset[row][col] |
|
237 |
if val is None: |
|
238 |
return u'' |
|
239 |
etype = self.rset.description[row][col] |
|
240 |
if self.schema.eschema(etype).is_final(): |
|
241 |
entity, rtype = self.rset.related_entity(row, col) |
|
242 |
if entity is None: |
|
243 |
return val # remove_html_tags() ? |
|
244 |
return entity.sortvalue(rtype) |
|
245 |
entity = self.rset.get_entity(row, col) |
|
246 |
return entity.sortvalue() |
|
247 |
||
843 | 248 |
|
0 | 249 |
class EditableTableView(TableView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
250 |
__regid__ = 'editable-table' |
0 | 251 |
finalview = 'editable-final' |
252 |
title = _('editable-table') |
|
253 |
||
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
254 |
|
0 | 255 |
class CellView(EntityView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
256 |
__regid__ = 'cell' |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
257 |
__select__ = nonempty_rset() |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
258 |
|
0 | 259 |
def cell_call(self, row, col, cellvid=None): |
260 |
""" |
|
261 |
:param row, col: indexes locating the cell value in view's result set |
|
262 |
:param cellvid: cell view (defaults to 'outofcontext') |
|
263 |
""" |
|
264 |
etype, val = self.rset.description[row][col], self.rset[row][col] |
|
265 |
if val is not None and not self.schema.eschema(etype).is_final(): |
|
266 |
e = self.rset.get_entity(row, col) |
|
267 |
e.view(cellvid or 'outofcontext', w=self.w) |
|
268 |
elif val is None: |
|
269 |
# This is usually caused by a left outer join and in that case, |
|
270 |
# regular views will most certainly fail if they don't have |
|
271 |
# a real eid |
|
272 |
self.wview('final', self.rset, row=row, col=col) |
|
273 |
else: |
|
274 |
self.wview(cellvid or 'final', self.rset, 'null', row=row, col=col) |
|
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' |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
290 |
__select__ = nonempty_rset() & match_form_params('actualrql') |
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, |
2226
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
296 |
displaycols=None, displayactions=None, mainindex=None): |
0 | 297 |
"""Dumps a table displaying a composite query""" |
298 |
actrql = self.req.form['actualrql'] |
|
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2677
diff
changeset
|
299 |
self.req.ensure_ro_rql(actrql) |
0 | 300 |
displaycols = self.displaycols(displaycols) |
301 |
if displayactions is None and 'displayactions' in self.req.form: |
|
302 |
displayactions = True |
|
469 | 303 |
if divid is None and 'divid' in self.req.form: |
304 |
divid = self.req.form['divid'] |
|
0 | 305 |
self.w(u'<div class="section">') |
306 |
if not title and 'title' in self.req.form: |
|
307 |
# pop title so it's not displayed by the table view as well |
|
308 |
title = self.req.form.pop('title') |
|
309 |
if title: |
|
310 |
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
|
311 |
if mainindex is None: |
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
312 |
mainindex = self.main_var_index() |
0 | 313 |
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
|
314 |
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
|
315 |
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
|
316 |
actions = () |
0 | 317 |
if not subvid and 'subvid' in self.req.form: |
318 |
subvid = self.req.form.pop('subvid') |
|
319 |
self.view('table', self.req.execute(actrql), |
|
320 |
'noresult', w=self.w, displayfilter=False, subvid=subvid, |
|
321 |
displayactions=displayactions, displaycols=displaycols, |
|
469 | 322 |
actions=actions, headers=headers, divid=divid) |
0 | 323 |
self.w(u'</div>\n') |
324 |
||
325 |
||
527 | 326 |
class EditableInitialTableTableView(InitialTableView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
327 |
__regid__ = 'editable-initialtable' |
0 | 328 |
finalview = 'editable-final' |