doc/book/en/devweb/views/table.rst
author Pierre-Yves David <pierre-yves.david@logilab.fr>
Tue, 10 Jan 2012 16:33:27 +0100
changeset 8156 f47252e24354
parent 8032 bcb87336c7d2
permissions -rw-r--r--
[tableviews] use ``select_or_none`` instead of ``try: select() except:`` select_or_none is here to avoid multiplying try: except: context in the code.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
     1
Table views
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
     2
-----------
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     3
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
     4
.. automodule:: cubicweb.web.views.tableview
6343
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
     5
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
     6
Example
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
     7
```````
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
     8
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
     9
Let us take an example from the timesheet cube:
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    10
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    11
.. sourcecode:: python
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    12
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    13
    class ActivityResourcesTable(EntityView):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    14
        __regid__ = 'activity.resources.table'
6343
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    15
        __select__ = is_instance('Activity')
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    16
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    17
        def call(self, showresource=True):
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    18
            eids = ','.join(str(row[0]) for row in self.cw_rset)
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    19
            rql = ('Any R,D,DUR,WO,DESCR,S,A, SN,RT,WT ORDERBY D DESC '
6343
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    20
                   'WHERE '
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    21
                   '   A is Activity, A done_by R, R title RT, '
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    22
                   '   A diem D, A duration DUR, '
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    23
                   '   A done_for WO, WO title WT, '
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    24
                   '   A description DESCR, A in_state S, S name SN, '
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    25
                   '   A eid IN (%s)' % eids)
6343
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    26
            rset = self._cw.execute(rql)
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    27
            self.wview('resource.table', rset, 'null')
6343
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    28
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    29
    class ResourcesTable(RsetTableView):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    30
        __regid__ = 'resource.table'
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    31
        # notice you may wish a stricter selector to check rql's shape
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    32
        __select__ = is_instance('Resource')
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    33
        # my table headers
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    34
        headers  = ['Resource', 'diem', 'duration', 'workpackage', 'description', 'state']
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    35
        # I want a table where attributes are editable (reledit inside)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    36
        finalvid = 'editable-final'
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    37
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    38
        cellvids = {3: 'editable-final'}
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    39
        # display facets and actions with a menu
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    40
        layout_args = {'display_filter': 'top',
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    41
                       'add_view_actions': None}
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    42
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    43
To obtain an editable table, you may specify the 'editable-table' view identifier
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    44
using some of `cellvids`, `finalvid` or `nonfinalvid`.
6343
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    45
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    46
The previous example results in:
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    47
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    48
.. image:: ../../images/views-table-shadow.png
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    49
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    50
In order to activate table filter mechanism, the `display_filter` option is given
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    51
as a layout argument. A small arrow will be displayed at the table's top right
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    52
corner. Clicking on `show filter form` action, will display the filter form as
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    53
below:
6343
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    54
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    55
.. image:: ../../images/views-table-filter-shadow.png
4814d44405fc [book] add editable-table in views/table section and add an example to illustrate this view
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5394
diff changeset
    56
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    57
By the same way, you can display additional actions for the selected entities
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    58
by setting `add_view_actions` layout option to `True`. This will add actions
8032
bcb87336c7d2 [doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7992
diff changeset
    59
returned by the view's :meth:`~cubicweb.web.views.tableview.TableMixIn.table_actions`.
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    60
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    61
You can notice that all columns of the result set are not displayed. This is
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    62
because of given `headers`, implying to display only columns from 0 to
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    63
len(headers).
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    64
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    65
Also Notice that the `ResourcesTable` view relies on a particular rql shape
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    66
(which is not ensured by the way, the only checked thing is that the result set
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    67
contains instance of the `Resource` type). That usually implies that you can't
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    68
use this view for user specific queries (e.g. generated by facets or typed
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    69
manually).
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    70
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    71
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    72
So another option would be to write this view using
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    73
:class:`~cubicweb.web.views.tableview.EntityTableView`, as below.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    74
8032
bcb87336c7d2 [doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7992
diff changeset
    75
.. sourcecode:: python
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    76
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    77
    class ResourcesTable(EntityTableView):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    78
        __regid__ = 'resource.table'
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    79
        __select__ = is_instance('Resource')
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    80
        # table columns definition
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    81
        columns  = ['resource', 'diem', 'duration', 'workpackage', 'description', 'in_state']
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    82
        # I want a table where attributes are editable (reledit inside)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    83
        finalvid = 'editable-final'
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    84
        # display facets and actions with a menu
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    85
        layout_args = {'display_filter': 'top',
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    86
                       'add_view_actions': None}
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    87
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    88
        def workpackage_cell(entity):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    89
            activity = entity.reverse_done_in[0]
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    90
            activity.view('reledit', rtype='done_for', role='subject', w=w)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    91
        def workpackage_sortvalue(entity):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    92
            activity = entity.reverse_done_in[0]
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    93
            return activity.done_for[0].sortvalue()
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    94
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    95
        column_renderers = {
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    96
            'resource': MainEntityColRenderer(),
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    97
            'workpackage': EntityTableColRenderer(
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    98
               header='Workpackage',
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
    99
               renderfunc=worpackage_cell,
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   100
               sortfunc=worpackage_sortvalue,),
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   101
            'in_state': EntityTableColRenderer(
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   102
               renderfunc=lambda w,x: w(x.cw_adapt_to('IWorkflowable').printable_state),
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   103
               sortfunc=lambda x: x.cw_adapt_to('IWorkflowable').printable_state),
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   104
         }
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   105
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   106
Notice the following point:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   107
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   108
* `cell_<column>(w, entity)` will be searched for rendering the content of a
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   109
  cell. If not found, `column` is expected to be an attribute of `entity`.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   110
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   111
* `cell_sortvalue_<column>(entity)` should return a typed value to use for
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   112
  javascript sorting or None for not sortable columns (the default).
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   113
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   114
* The :func:`etable_entity_sortvalue` decorator will set a 'sortvalue' function
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   115
  for the column containing the main entity (the one given as argument to all
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   116
  methods), which will call `entity.sortvalue()`.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   117
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   118
* You can set a column header using the :func:`etable_header_title` decorator.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   119
  This header will be translated. If it's not an already existing msgid, think
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   120
  to mark it using `_()` (the example supposes headers are schema defined msgid).
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   121
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   122
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   123
Pro/cons of each approach
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   124
`````````````````````````
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   125
:class:`EntityTableView` and :class:`RsetableView` provides basically the same
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   126
set of features, though they don't share the same properties. Let's try to sum
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   127
up pro and cons of each class.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   128
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   129
* `EntityTableView` view is:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   130
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   131
  - more verbose, but usually easier to understand
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   132
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   133
  - easily extended (easy to add/remove columns for instance)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   134
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   135
  - doesn't rely on a particular rset shape. Simply give it a title and will be
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   136
    listed in the 'possible views' box if any.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   137
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   138
* `RsetTableView` view is:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   139
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   140
  - hard to beat to display barely a result set, or for cases where some of
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   141
    `headers`, `displaycols` or `cellvids` could be defined to enhance the table
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   142
    while you don't care about e.g. pagination or facets.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   143
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   144
  - hardly extensible, as you usually have to change places where the view is
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6343
diff changeset
   145
    called to modify the RQL (hence the view's result set shape).