use column_labels instead of rqlst.get_description stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 30 Jun 2009 15:19:17 +0200
branchstable
changeset 2204 3472c5498478
parent 2203 efdd3a9f9028
child 2205 fc1447fe94df
use column_labels instead of rqlst.get_description
web/test/unittest_views_baseviews.py
web/views/tableview.py
--- a/web/test/unittest_views_baseviews.py	Tue Jun 30 15:18:07 2009 +0200
+++ b/web/test/unittest_views_baseviews.py	Tue Jun 30 15:19:17 2009 +0200
@@ -103,9 +103,9 @@
 
     def test_sortvalue_with_display_col(self):
         e, rset, view = self._prepare_entity()
-        rqlstdescr = rset.syntax_tree().get_description()[0] # XXX missing Union support
+        labels = rset.column_labels()
         table = TableWidget(view)
-        table.columns = view.get_columns(rqlstdescr, [1, 2], None, None, None, None, 0)
+        table.columns = view.get_columns(labels, [1, 2], None, None, None, None, 0)
         expected = ['loo"ong blabla'[:10], e.creation_date.strftime('%Y-%m-%d %H:%M')]
         got = [loadjson(value) for _, value in table.itercols(0)]
         self.assertListEqual(got, expected)
--- a/web/views/tableview.py	Tue Jun 30 15:18:07 2009 +0200
+++ b/web/views/tableview.py	Tue Jun 30 15:19:17 2009 +0200
@@ -105,11 +105,10 @@
         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()
+        computed_labels = rset.columns_labels(mainindex)
         hidden = True
         if not subvid and 'subvid' in req.form:
             subvid = req.form.pop('subvid')
@@ -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)