web/views/tableview.py
changeset 5328 c51e8f62652a
parent 5239 471554b842d2
parent 5312 d2dbba898a96
child 5385 b6e250dd7a7d
equal deleted inserted replaced
5327:34a298eca917 5328:c51e8f62652a
    21 from cubicweb.web.htmlwidgets import (TableWidget, TableColumn, MenuWidget,
    21 from cubicweb.web.htmlwidgets import (TableWidget, TableColumn, MenuWidget,
    22                                       PopupBoxMenu, BoxLink)
    22                                       PopupBoxMenu, BoxLink)
    23 from cubicweb.web.facet import prepare_facets_rqlst, filter_hiddens
    23 from cubicweb.web.facet import prepare_facets_rqlst, filter_hiddens
    24 
    24 
    25 class TableView(AnyRsetView):
    25 class TableView(AnyRsetView):
       
    26     """The table view accepts any non-empty rset. It uses
       
    27     introspection on the result set to compute column names and the
       
    28     proper way to display the cells.
       
    29     It is however highly configurable and accepts a wealth of options.
       
    30     """
    26     __regid__ = 'table'
    31     __regid__ = 'table'
    27     title = _('table')
    32     title = _('table')
    28     finalview = 'final'
    33     finalview = 'final'
    29 
    34 
    30     def form_filter(self, divid, displaycols, displayactions, displayfilter,
    35     def form_filter(self, divid, displaycols, displayactions, displayfilter,
    48             return self.show_hide_actions(divid, not hidden)
    53             return self.show_hide_actions(divid, not hidden)
    49         return ()
    54         return ()
    50 
    55 
    51     def _generate_form(self, divid, baserql, fwidgets, hidden=True, vidargs={}):
    56     def _generate_form(self, divid, baserql, fwidgets, hidden=True, vidargs={}):
    52         """display a form to filter table's content. This should only
    57         """display a form to filter table's content. This should only
    53         occurs when a context eid is given
    58         occur when a context eid is given
    54         """
    59         """
       
    60         w = self.w
    55         self._cw.add_css('cubicweb.facets.css')
    61         self._cw.add_css('cubicweb.facets.css')
    56         self._cw.add_js( ('cubicweb.ajax.js', 'cubicweb.facets.js'))
    62         self._cw.add_js( ('cubicweb.ajax.js', 'cubicweb.facets.js'))
    57         # drop False / None values from vidargs
    63         # drop False / None values from vidargs
    58         vidargs = dict((k, v) for k, v in vidargs.iteritems() if v)
    64         vidargs = dict((k, v) for k, v in vidargs.iteritems() if v)
    59         self.w(u'<form method="post" cubicweb:facetargs="%s" action="">' %
    65         w(u'<form method="post" cubicweb:facetargs="%s" action="">' %
    60                xml_escape(dumps([divid, 'table', False, vidargs])))
    66           xml_escape(dumps([divid, 'table', False, vidargs])))
    61         self.w(u'<fieldset id="%sForm" class="%s">' % (divid, hidden and 'hidden' or ''))
    67         w(u'<fieldset id="%sForm" class="%s">' % (divid, hidden and 'hidden' or ''))
    62         self.w(u'<input type="hidden" name="divid" value="%s" />' % divid)
    68         w(u'<input type="hidden" name="divid" value="%s" />' % divid)
    63         self.w(u'<input type="hidden" name="fromformfilter" value="1" />')
    69         w(u'<input type="hidden" name="fromformfilter" value="1" />')
    64         filter_hiddens(self.w, facets=','.join(wdg.facet.__regid__ for wdg in fwidgets),
    70         filter_hiddens(w, facets=','.join(wdg.facet.__regid__ for wdg in fwidgets),
    65                        baserql=baserql)
    71                        baserql=baserql)
    66         self.w(u'<table class="filter">\n')
    72         w(u'<table class="filter">\n')
    67         self.w(u'<tr>\n')
    73         w(u'<tr>\n')
    68         for wdg in fwidgets:
    74         for wdg in fwidgets:
    69             self.w(u'<td>')
    75             w(u'<td>')
    70             wdg.render(w=self.w)
    76             wdg.render(w=w)
    71             self.w(u'</td>\n')
    77             w(u'</td>\n')
    72         self.w(u'</tr>\n')
    78         w(u'</tr>\n')
    73         self.w(u'</table>\n')
    79         w(u'</table>\n')
    74         self.w(u'</fieldset>\n')
    80         w(u'</fieldset>\n')
    75         self.w(u'</form>\n')
    81         w(u'</form>\n')
    76 
    82 
    77     def main_var_index(self):
    83     def main_var_index(self):
    78         """returns the index of the first non-attribute variable among the RQL
    84         """returns the index of the first non-attribute variable among the RQL
    79         selected variables
    85         selected variables
    80         """
    86         """
    98         return displaycols
   104         return displaycols
    99 
   105 
   100     def call(self, title=None, subvid=None, displayfilter=None, headers=None,
   106     def call(self, title=None, subvid=None, displayfilter=None, headers=None,
   101              displaycols=None, displayactions=None, actions=(), divid=None,
   107              displaycols=None, displayactions=None, actions=(), divid=None,
   102              cellvids=None, cellattrs=None, mainindex=None):
   108              cellvids=None, cellattrs=None, mainindex=None):
   103         """Dumps a table displaying a composite query
   109         """Produces a table displaying a composite query
   104 
   110 
   105         :param title: title added before table
   111         :param title: title added before table
   106         :param subvid: cell view
   112         :param subvid: cell view
   107         :param displayfilter: filter that selects rows to display
   113         :param displayfilter: filter that selects rows to display
   108         :param headers: columns' titles
   114         :param headers: columns' titles