web/views/tableview.py
changeset 8032 bcb87336c7d2
parent 8028 58e9bc8a1f2c
child 8042 27ab1649bd71
equal deleted inserted replaced
8030:552d85fcb587 8032:bcb87336c7d2
    32    :members:
    32    :members:
    33 
    33 
    34 .. autoclass:: cubicweb.web.views.tableview.EntityTableView
    34 .. autoclass:: cubicweb.web.views.tableview.EntityTableView
    35    :members:
    35    :members:
    36 
    36 
    37 .. autoclass:: cubicweb.web.views.pyview.PyValTableView
    37 .. autoclass:: cubicweb.web.views.pyviews.PyValTableView
    38    :members:
    38    :members:
    39 
    39 
    40 All those classes are rendered using a *layout*:
    40 All those classes are rendered using a *layout*:
    41 
    41 
    42 .. autoclass:: cubicweb.web.views.pyview.TableLayout
    42 .. autoclass:: cubicweb.web.views.tableview.TableLayout
    43    :members:
    43    :members:
    44 
    44 
    45 There is by default only on table layout, using the 'table_layout' identifier,
    45 There is by default only on table layout, using the 'table_layout' identifier,
    46 that is referenced by table views
    46 that is referenced by table views
    47 :attr:`cubicweb.web.views.tableview.TableMixIn.layout_id`.  If you want to
    47 :attr:`cubicweb.web.views.tableview.TableMixIn.layout_id`.  If you want to
    54 
    54 
    55 If you can still find a view that suit your needs, you should take a look at the
    55 If you can still find a view that suit your needs, you should take a look at the
    56 class below that is the common abstract base class for the three views defined
    56 class below that is the common abstract base class for the three views defined
    57 above and implements you own class.
    57 above and implements you own class.
    58 
    58 
    59 .. autoclass:: cubicweb.web.views.pyview.TableMixIn
    59 .. autoclass:: cubicweb.web.views.tableview.TableMixIn
    60    :members:
    60    :members:
    61 """
    61 """
    62 
    62 
    63 __docformat__ = "restructuredtext en"
    63 __docformat__ = "restructuredtext en"
    64 _ = unicode
    64 _ = unicode
   164         elif isinstance(self.header_column_idx, int):
   164         elif isinstance(self.header_column_idx, int):
   165             self.header_column_idx = frozenset( (self.header_column_idx,) )
   165             self.header_column_idx = frozenset( (self.header_column_idx,) )
   166 
   166 
   167     @cachedproperty
   167     @cachedproperty
   168     def initial_load(self):
   168     def initial_load(self):
   169         """We detect a bit heuristically if we are built for the first time of
   169         """We detect a bit heuristically if we are built for the first time.
   170         from subsequent calls by the form filter or by the pagination hooks
   170         or from subsequent calls by the form filter or by the pagination hooks.
   171         """
   171         """
   172         form = self._cw.form
   172         form = self._cw.form
   173         return 'fromformfilter' not in form and '__start' not in form
   173         return 'fromformfilter' not in form and '__start' not in form
   174 
   174 
   175     def render(self, w, **kwargs):
   175     def render(self, w, **kwargs):
   305 
   305 
   306 
   306 
   307 class AbstractColumnRenderer(object):
   307 class AbstractColumnRenderer(object):
   308     """Abstract base class for column renderer. Interface of a column renderer follows:
   308     """Abstract base class for column renderer. Interface of a column renderer follows:
   309 
   309 
   310     .. automethod:: bind
   310     .. automethod:: cubicweb.web.views.tableview.AbstractColumnRenderer.bind
   311     .. automethod:: render_header
   311     .. automethod:: cubicweb.web.views.tableview.AbstractColumnRenderer.render_header
   312     .. automethod:: render_cell
   312     .. automethod:: cubicweb.web.views.tableview.AbstractColumnRenderer.render_cell
   313     .. automethod:: sortvalue
   313     .. automethod:: cubicweb.web.views.tableview.AbstractColumnRenderer.sortvalue
   314 
   314 
   315     Attributes on this base class are:
   315     Attributes on this base class are:
   316 
   316 
   317     :attr: `header`, the column header. If None, default to `_(colid)`
   317     :attr: `header`, the column header. If None, default to `_(colid)`
   318     :attr: `addcount`, if True, add the table size in parenthezis beside the header
   318     :attr: `addcount`, if True, add the table size in parenthezis beside the header
   321     :attr: `sortable`, tell if the column is sortable
   321     :attr: `sortable`, tell if the column is sortable
   322     :attr: `view`, the table view
   322     :attr: `view`, the table view
   323     :attr: `_cw`, the request object
   323     :attr: `_cw`, the request object
   324     :attr: `colid`, the column identifier
   324     :attr: `colid`, the column identifier
   325     :attr: `attributes`, dictionary of attributes to put on the HTML tag when
   325     :attr: `attributes`, dictionary of attributes to put on the HTML tag when
   326     the cell is rendered
   326             the cell is rendered
   327     """
   327     """
   328     attributes = {}
   328     attributes = {}
   329     empty_cell_content = u' '
   329     empty_cell_content = u' '
   330 
   330 
   331     def __init__(self, header=None, addcount=False, trheader=True,
   331     def __init__(self, header=None, addcount=False, trheader=True,
   406 
   406 
   407     .. automethod:: build_column_renderers
   407     .. automethod:: build_column_renderers
   408 
   408 
   409     You may also want to overridde:
   409     You may also want to overridde:
   410 
   410 
   411     .. automethod:: table_size
   411     .. autoattribute:: cubicweb.web.views.tableview.TableMixIn.table_size
   412 
   412 
   413     The :attr:`has_headers` boolean attribute tells if the table has some
   413     The :attr:`has_headers` boolean attribute tells if the table has some
   414     headers to be displayed. Default to `True`.
   414     headers to be displayed. Default to `True`.
   415     """
   415     """
   416     __abstract__ = True
   416     __abstract__ = True
   462 
   462 
   463     def build_column_renderers(self):
   463     def build_column_renderers(self):
   464         """Return a list of column renderers, one for each column to be
   464         """Return a list of column renderers, one for each column to be
   465         rendered. Prototype of a column renderer is described below:
   465         rendered. Prototype of a column renderer is described below:
   466 
   466 
   467         .. autoclass:: AbstractColumnRenderer
   467         .. autoclass:: cubicweb.web.views.tableview.AbstractColumnRenderer
   468         """
   468         """
   469         raise NotImplementedError()
   469         raise NotImplementedError()
   470 
   470 
   471     def table_actions(self):
   471     def table_actions(self):
   472         """Return a list of actions (:class:`~cubicweb.web.component.Link`) that
   472         """Return a list of actions (:class:`~cubicweb.web.component.Link`) that
   669     """Default column renderer for :class:`EntityTableView`.
   669     """Default column renderer for :class:`EntityTableView`.
   670 
   670 
   671     You may use the :meth:`entity` method to retrieve the main entity for a
   671     You may use the :meth:`entity` method to retrieve the main entity for a
   672     given row number.
   672     given row number.
   673 
   673 
   674     .. automethod:: entity
   674     .. automethod:: cubicweb.web.views.tableview.EntityTableColRenderer.entity
   675     """
   675     """
   676     def __init__(self, renderfunc=None, sortfunc=None, **kwargs):
   676     def __init__(self, renderfunc=None, sortfunc=None, **kwargs):
   677         if renderfunc is None:
   677         if renderfunc is None:
   678             renderfunc = lambda w,x: w(x.printable_value(self.colid))
   678             renderfunc = lambda w,x: w(x.printable_value(self.colid))
   679             if sortfunc is None:
   679             if sortfunc is None:
   757 
   757 
   758     You may wish to specify :class:`MainEntityColRenderer` or
   758     You may wish to specify :class:`MainEntityColRenderer` or
   759     :class:`RelatedEntityColRenderer` renderer for a column in the
   759     :class:`RelatedEntityColRenderer` renderer for a column in the
   760     :attr:`column_renderers` dictionary.
   760     :attr:`column_renderers` dictionary.
   761 
   761 
   762     .. autoclass:: EntityTableColRenderer
   762     .. autoclass:: cubicweb.web.views.tableview.EntityTableColRenderer
   763     .. autoclass:: MainEntityColRenderer
   763     .. autoclass:: cubicweb.web.views.tableview.MainEntityColRenderer
   764     .. autoclass:: RelatedEntityColRenderer
   764     .. autoclass:: cubicweb.web.views.tableview.RelatedEntityColRenderer
   765     """
   765     """
   766     __abstract__ = True
   766     __abstract__ = True
   767     default_column_renderer_class = EntityTableColRenderer
   767     default_column_renderer_class = EntityTableColRenderer
   768     columns = None # to be defined in concret class
   768     columns = None # to be defined in concret class
   769 
   769