--- a/web/views/tableview.py Mon Jun 29 14:12:18 2009 +0200
+++ b/web/views/tableview.py Thu Jul 02 10:35:03 2009 +0200
@@ -93,7 +93,7 @@
def call(self, title=None, subvid=None, displayfilter=None, headers=None,
displaycols=None, displayactions=None, actions=(), divid=None,
- cellvids=None, cellattrs=None):
+ cellvids=None, cellattrs=None, mainindex=None):
"""Dumps a table displaying a composite query
:param title: title added before table
@@ -101,19 +101,18 @@
:param displayfilter: filter that selects rows to display
:param headers: columns' titles
"""
- rset = self.rset
req = self.req
req.add_js('jquery.tablesorter.js')
req.add_css(('cubicweb.tablesorter.css', 'cubicweb.tableview.css'))
- rqlst = rset.syntax_tree()
- # get rql description first since the filter form may remove some
- # necessary information
- rqlstdescr = rqlst.get_description()[0] # XXX missing Union support
- mainindex = self.main_var_index()
+ # compute label first since the filter form may remove some necessary
+ # information from the rql syntax tree
+ if mainindex is None:
+ mainindex = self.main_var_index()
+ computed_labels = self.columns_labels(mainindex)
hidden = True
if not subvid and 'subvid' in req.form:
subvid = req.form.pop('subvid')
- divid = divid or req.form.get('divid') or 'rs%s' % make_uid(id(rset))
+ divid = divid or req.form.get('divid') or 'rs%s' % make_uid(id(self.rset))
actions = list(actions)
if mainindex is None:
displayfilter, displayactions = False, False
@@ -154,8 +153,8 @@
self.render_actions(divid, actions)
# render table
table = TableWidget(self)
- for column in self.get_columns(rqlstdescr, displaycols, headers, subvid,
- cellvids, cellattrs, mainindex):
+ for column in self.get_columns(computed_labels, displaycols, headers,
+ subvid, cellvids, cellattrs, mainindex):
table.append_column(column)
table.render(self.w)
self.w(u'</div>\n')
@@ -188,20 +187,15 @@
box.render(w=self.w)
self.w(u'<div class="clear"/>')
- def get_columns(self, rqlstdescr, displaycols, headers, subvid, cellvids,
- cellattrs, mainindex):
+ def get_columns(self, computed_labels, displaycols, headers, subvid,
+ cellvids, cellattrs, mainindex):
columns = []
- for colindex, attr in enumerate(rqlstdescr):
+ for colindex, label in enumerate(computed_labels):
if colindex not in displaycols:
continue
# compute column header
if headers is not None:
label = headers[displaycols.index(colindex)]
- elif colindex == 0 or attr == 'Any': # find a better label
- label = ','.join(display_name(self.req, et)
- for et in self.rset.column_types(colindex))
- else:
- label = display_name(self.req, attr)
if colindex == mainindex:
label += ' (%s)' % self.rset.rowcount
column = TableColumn(label, colindex)
@@ -214,7 +208,6 @@
column.append_renderer(self.finalview, colindex)
else:
column.append_renderer(subvid or 'incontext', colindex)
-
if cellattrs and colindex in cellattrs:
for name, value in cellattrs[colindex].iteritems():
column.add_attr(name, value)
@@ -297,7 +290,7 @@
title = None
def call(self, title=None, subvid=None, headers=None, divid=None,
- displaycols=None, displayactions=None):
+ displaycols=None, displayactions=None, mainindex=None):
"""Dumps a table displaying a composite query"""
actrql = self.req.form['actualrql']
self.ensure_ro_rql(actrql)
@@ -312,7 +305,8 @@
title = self.req.form.pop('title')
if title:
self.w(u'<h2>%s</h2>\n' % title)
- mainindex = self.main_var_index()
+ if mainindex is None:
+ mainindex = self.main_var_index()
if mainindex is not None:
actions = self.form_filter(divid, displaycols, displayactions, True)
else: