web/views/pyviews.py
branchstable
changeset 7903 ac658ab4c7b7
parent 6802 ff9059e144f9
child 7992 4ff9f25cb06e
--- a/web/views/pyviews.py	Tue Oct 04 10:15:45 2011 +0200
+++ b/web/views/pyviews.py	Tue Oct 04 10:15:46 2011 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -24,18 +24,29 @@
 
 
 class PyValTableView(View):
-    """display a list of list of values into an html table.
+    """display a list of list of values into an HTML table.
 
     Take care, content is NOT xml-escaped.
+
+    If `headers` is specfied, it is expected to be a list of headers to be
+    inserted as first row (in <thead>).
+
+    If `colheaders` is True, the first column will be considered as an headers
+    column an its values will be inserted inside <th> instead of <td>.
+
+    `cssclass` is the CSS class used on the <table> tag, and default to
+    'listing' (so that the table will look similar to those generated by the
+    table view).
     """
     __regid__ = 'pyvaltable'
     __select__ = match_kwargs('pyvalue')
 
-    def call(self, pyvalue, headers=None):
+    def call(self, pyvalue, headers=None, colheaders=False,
+             cssclass='listing'):
         if headers is None:
             headers = self._cw.form.get('headers')
         w = self.w
-        w(u'<table class="listing">\n')
+        w(u'<table class="%s">\n' % cssclass)
         if headers:
             w(u'<thead>')
             w(u'<tr>')
@@ -46,6 +57,9 @@
         w(u'<tbody>')
         for row in pyvalue:
             w(u'<tr>')
+            if colheaders:
+                w(u'<th>%s</th>' % row[0])
+                row = row[1:]
             for cell in row:
                 w(u'<td>%s</td>' % cell)
             w(u'</tr>\n')