author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 18 Aug 2009 09:25:26 +0200 | |
changeset 2901 | 8f4d495c94c2 |
parent 2813 | 0cf6c8005bf6 |
child 3023 | 7864fee8b4ec |
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): |
|
25 |
id = 'table' |
|
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 |
""" |
|
54 |
self.req.add_js( ('cubicweb.ajax.js', 'cubicweb.formfilter.js')) |
|
55 |
# drop False / None values from vidargs |
|
56 |
vidargs = dict((k, v) for k, v in vidargs.iteritems() if v) |
|
57 |
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
|
58 |
xml_escape(dumps([divid, 'table', False, vidargs]))) |
0 | 59 |
self.w(u'<fieldset id="%sForm" class="%s">' % (divid, hidden and 'hidden' or '')) |
60 |
self.w(u'<input type="hidden" name="divid" value="%s" />' % divid) |
|
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
|
61 |
filter_hiddens(self.w, facets=','.join(wdg.facet.id for wdg in fwidgets), baserql=baserql) |
0 | 62 |
self.w(u'<table class="filter">\n') |
63 |
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
|
64 |
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
|
65 |
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
|
66 |
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
|
67 |
self.w(u'</td>\n') |
0 | 68 |
self.w(u'</tr>\n') |
69 |
self.w(u'</table>\n') |
|
70 |
self.w(u'</fieldset>\n') |
|
71 |
self.w(u'</form>\n') |
|
72 |
||
73 |
def main_var_index(self): |
|
74 |
"""returns the index of the first non-attribute variable among the RQL |
|
75 |
selected variables |
|
76 |
""" |
|
77 |
eschema = self.vreg.schema.eschema |
|
78 |
for i, etype in enumerate(self.rset.description[0]): |
|
79 |
try: |
|
80 |
if not eschema(etype).is_final(): |
|
81 |
return i |
|
82 |
except KeyError: # XXX possible? |
|
83 |
continue |
|
84 |
return None |
|
85 |
||
86 |
def displaycols(self, displaycols): |
|
87 |
if displaycols is None: |
|
88 |
if 'displaycols' in self.req.form: |
|
89 |
displaycols = [int(idx) for idx in self.req.form['displaycols']] |
|
90 |
else: |
|
91 |
displaycols = range(len(self.rset.syntax_tree().children[0].selection)) |
|
92 |
return displaycols |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
93 |
|
0 | 94 |
def call(self, title=None, subvid=None, displayfilter=None, headers=None, |
469 | 95 |
displaycols=None, displayactions=None, actions=(), divid=None, |
2226
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
96 |
cellvids=None, cellattrs=None, mainindex=None): |
0 | 97 |
"""Dumps a table displaying a composite query |
98 |
||
99 |
:param title: title added before table |
|
100 |
:param subvid: cell view |
|
101 |
:param displayfilter: filter that selects rows to display |
|
102 |
:param headers: columns' titles |
|
103 |
""" |
|
104 |
req = self.req |
|
105 |
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
|
106 |
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
|
107 |
# 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
|
108 |
# information from the rql syntax tree |
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
109 |
if mainindex is None: |
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
110 |
mainindex = self.main_var_index() |
2206
009e2856afcb
columns_labels is an AnyRsetView method...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2204
diff
changeset
|
111 |
computed_labels = self.columns_labels(mainindex) |
0 | 112 |
hidden = True |
113 |
if not subvid and 'subvid' in req.form: |
|
114 |
subvid = req.form.pop('subvid') |
|
2226
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
115 |
divid = divid or req.form.get('divid') or 'rs%s' % make_uid(id(self.rset)) |
0 | 116 |
actions = list(actions) |
117 |
if mainindex is None: |
|
118 |
displayfilter, displayactions = False, False |
|
119 |
else: |
|
120 |
if displayfilter is None and 'displayfilter' in req.form: |
|
121 |
displayfilter = True |
|
122 |
if req.form['displayfilter'] == 'shown': |
|
123 |
hidden = False |
|
124 |
if displayactions is None and 'displayactions' in req.form: |
|
125 |
displayactions = True |
|
126 |
displaycols = self.displaycols(displaycols) |
|
127 |
fromformfilter = 'fromformfilter' in req.form |
|
128 |
# if fromformfilter is true, this is an ajax call and we only want to |
|
129 |
# replace the inner div, so don't regenerate everything under the if |
|
130 |
# below |
|
131 |
if not fromformfilter: |
|
132 |
div_class = 'section' |
|
133 |
self.w(u'<div class="%s">' % div_class) |
|
134 |
if not title and 'title' in req.form: |
|
135 |
title = req.form['title'] |
|
136 |
if title: |
|
137 |
self.w(u'<h2 class="tableTitle">%s</h2>\n' % title) |
|
138 |
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
|
139 |
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
|
140 |
displayactions) |
0 | 141 |
elif displayfilter: |
2115
c48ff1d0acc4
add facets.css when form filter is there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
142 |
req.add_css('cubicweb.facets.css') |
0 | 143 |
actions += self.show_hide_actions(divid, True) |
144 |
self.w(u'<div id="%s"' % divid) |
|
145 |
if displayactions: |
|
2677
8df54acd6613
[table view]Â vreg api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
146 |
for action in self.vreg['actions'].possible_actions(req, self.rset).get('mainactions', ()): |
0 | 147 |
actions.append( (action.url(), req._(action.title), action.html_class(), None) ) |
148 |
self.w(u' cubicweb:displayactions="1">') # close <div tag |
|
149 |
else: |
|
150 |
self.w(u'>') # close <div tag |
|
151 |
# render actions menu |
|
152 |
if actions: |
|
153 |
self.render_actions(divid, actions) |
|
154 |
# render table |
|
155 |
table = TableWidget(self) |
|
2204
3472c5498478
use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2115
diff
changeset
|
156 |
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
|
157 |
subvid, cellvids, cellattrs, mainindex): |
0 | 158 |
table.append_column(column) |
159 |
table.render(self.w) |
|
160 |
self.w(u'</div>\n') |
|
161 |
if not fromformfilter: |
|
162 |
self.w(u'</div>\n') |
|
163 |
||
164 |
||
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 |
|
169 |
showlabel = self.req._('show filter form') |
|
170 |
hidelabel = self.req._('hide filter form') |
|
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) |
|
179 |
label = '<img src="%s" alt="%s"/>' % ( |
|
180 |
self.req.datadir_url + 'liveclipboard-icon.png', |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2226
diff
changeset
|
181 |
xml_escape(self.req._('action(s) on this selection'))) |
0 | 182 |
menu = PopupBoxMenu(label, isitem=False, link_class='actionsBox', |
183 |
ident='%sActions' % divid) |
|
184 |
box.append(menu) |
|
185 |
for url, label, klass, ident in actions: |
|
186 |
menu.append(BoxLink(url, label, klass, ident=ident, escape=True)) |
|
187 |
box.render(w=self.w) |
|
188 |
self.w(u'<div class="clear"/>') |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
189 |
|
2204
3472c5498478
use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2115
diff
changeset
|
190 |
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
|
191 |
cellvids, cellattrs, mainindex): |
0 | 192 |
columns = [] |
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)] |
|
199 |
if colindex == mainindex: |
|
200 |
label += ' (%s)' % self.rset.rowcount |
|
201 |
column = TableColumn(label, colindex) |
|
202 |
coltype = self.rset.description[0][colindex] |
|
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) |
|
207 |
elif coltype is not None and self.schema.eschema(coltype).is_final(): |
|
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): |
0 | 220 |
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
|
221 |
|
0 | 222 |
def get_rows(self): |
223 |
return self.rset |
|
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) |
|
232 |
val = self.rset[row][col] |
|
233 |
if val is None: |
|
234 |
return u'' |
|
235 |
etype = self.rset.description[row][col] |
|
236 |
if self.schema.eschema(etype).is_final(): |
|
237 |
entity, rtype = self.rset.related_entity(row, col) |
|
238 |
if entity is None: |
|
239 |
return val # remove_html_tags() ? |
|
240 |
return entity.sortvalue(rtype) |
|
241 |
entity = self.rset.get_entity(row, col) |
|
242 |
return entity.sortvalue() |
|
243 |
||
843 | 244 |
|
0 | 245 |
class EditableTableView(TableView): |
246 |
id = 'editable-table' |
|
247 |
finalview = 'editable-final' |
|
248 |
title = _('editable-table') |
|
249 |
||
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
250 |
|
0 | 251 |
class CellView(EntityView): |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
252 |
__select__ = nonempty_rset() |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
253 |
|
0 | 254 |
id = 'cell' |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
255 |
|
0 | 256 |
def cell_call(self, row, col, cellvid=None): |
257 |
""" |
|
258 |
:param row, col: indexes locating the cell value in view's result set |
|
259 |
:param cellvid: cell view (defaults to 'outofcontext') |
|
260 |
""" |
|
261 |
etype, val = self.rset.description[row][col], self.rset[row][col] |
|
262 |
if val is not None and not self.schema.eschema(etype).is_final(): |
|
263 |
e = self.rset.get_entity(row, col) |
|
264 |
e.view(cellvid or 'outofcontext', w=self.w) |
|
265 |
elif val is None: |
|
266 |
# This is usually caused by a left outer join and in that case, |
|
267 |
# regular views will most certainly fail if they don't have |
|
268 |
# a real eid |
|
269 |
self.wview('final', self.rset, row=row, col=col) |
|
270 |
else: |
|
271 |
self.wview(cellvid or 'final', self.rset, 'null', row=row, col=col) |
|
272 |
||
273 |
||
274 |
class InitialTableView(TableView): |
|
275 |
"""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
|
276 |
|
0 | 277 |
* the default query (ie `rql` form parameter), which is only used to select |
278 |
this view and to build the filter form. This query should have the same |
|
279 |
structure as the actual without actual restriction (but link to |
|
280 |
restriction variables) and usually with a limit for efficiency (limit set |
|
281 |
to 2 is advised) |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
282 |
|
0 | 283 |
* the actual query (`actualrql` form parameter) whose results will be |
284 |
displayed with default restrictions set |
|
285 |
""" |
|
286 |
id = 'initialtable' |
|
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
287 |
__select__ = nonempty_rset() & match_form_params('actualrql') |
0 | 288 |
# should not be displayed in possible view since it expects some specific |
289 |
# parameters |
|
290 |
title = None |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1370
diff
changeset
|
291 |
|
469 | 292 |
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
|
293 |
displaycols=None, displayactions=None, mainindex=None): |
0 | 294 |
"""Dumps a table displaying a composite query""" |
295 |
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
|
296 |
self.req.ensure_ro_rql(actrql) |
0 | 297 |
displaycols = self.displaycols(displaycols) |
298 |
if displayactions is None and 'displayactions' in self.req.form: |
|
299 |
displayactions = True |
|
469 | 300 |
if divid is None and 'divid' in self.req.form: |
301 |
divid = self.req.form['divid'] |
|
0 | 302 |
self.w(u'<div class="section">') |
303 |
if not title and 'title' in self.req.form: |
|
304 |
# pop title so it's not displayed by the table view as well |
|
305 |
title = self.req.form.pop('title') |
|
306 |
if title: |
|
307 |
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
|
308 |
if mainindex is None: |
f5216e540168
allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2206
diff
changeset
|
309 |
mainindex = self.main_var_index() |
0 | 310 |
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
|
311 |
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
|
312 |
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
|
313 |
actions = () |
0 | 314 |
if not subvid and 'subvid' in self.req.form: |
315 |
subvid = self.req.form.pop('subvid') |
|
316 |
self.view('table', self.req.execute(actrql), |
|
317 |
'noresult', w=self.w, displayfilter=False, subvid=subvid, |
|
318 |
displayactions=displayactions, displaycols=displaycols, |
|
469 | 319 |
actions=actions, headers=headers, divid=divid) |
0 | 320 |
self.w(u'</div>\n') |
321 |
||
322 |
||
527 | 323 |
class EditableInitialTableTableView(InitialTableView): |
0 | 324 |
id = 'editable-initialtable' |
325 |
finalview = 'editable-final' |