web/views/tableview.py
author Aurelien Campeas <aurelien.campeas@logilab.fr>
Mon, 17 Dec 2012 14:26:41 +0100
branchstable
changeset 8633 36197bd1d78b
parent 8480 086cff6a306a
child 8535 268b6349baf3
permissions -rw-r--r--
[ldapparser] demote warning level (actually important user info can leak there) (prepares #2542083)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8418
3f87aa655466 [docstrings] typos corrected
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8417
diff changeset
     1
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5377
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5377
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5377
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5377
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5377
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5377
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5377
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5377
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5377
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5377
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5377
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5377
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5377
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5377
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5377
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    18
"""This module contains table views, with the following features that may be
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    19
provided (depending on the used implementation):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    20
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    21
* facets filtering
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    22
* pagination
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    23
* actions menu
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    24
* properly sortable content
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    25
* odd/row/hover line styles
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    26
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    27
The three main implementation are described below. Each implementation is
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    28
suitable for a particular case, but they each attempt to display tables that
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    29
looks similar.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    30
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    31
.. autoclass:: cubicweb.web.views.tableview.RsetTableView
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    32
   :members:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    33
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    34
.. autoclass:: cubicweb.web.views.tableview.EntityTableView
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    35
   :members:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    36
8032
bcb87336c7d2 [doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8028
diff changeset
    37
.. autoclass:: cubicweb.web.views.pyviews.PyValTableView
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    38
   :members:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    39
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    40
All those classes are rendered using a *layout*:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    41
8032
bcb87336c7d2 [doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8028
diff changeset
    42
.. autoclass:: cubicweb.web.views.tableview.TableLayout
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    43
   :members:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    44
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    45
There is by default only on table layout, using the 'table_layout' identifier,
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    46
that is referenced by table views
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    47
:attr:`cubicweb.web.views.tableview.TableMixIn.layout_id`.  If you want to
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    48
customize the look and feel of your table, you can either replace the default
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    49
one by yours, having multiple variants with proper selectors, or change the
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    50
`layout_id` identifier of your table to use your table specific implementation.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    51
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    52
Notice you can gives options to the layout using a `layout_args` dictionary on
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    53
your class.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    54
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    55
If you can still find a view that suit your needs, you should take a look at the
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    56
class below that is the common abstract base class for the three views defined
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    57
above and implements you own class.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    58
8032
bcb87336c7d2 [doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8028
diff changeset
    59
.. autoclass:: cubicweb.web.views.tableview.TableMixIn
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    60
   :members:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    61
"""
5940
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5727
diff changeset
    62
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
__docformat__ = "restructuredtext en"
6582
8eb7883b4223 [pylint] fix a bug of pylint detected errors and i18n pb (calling builtins._ instead of req._)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6254
diff changeset
    64
_ = unicode
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    66
from warnings import warn
8065
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
    67
from copy import copy
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
    68
from types import MethodType
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    69
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2226
diff changeset
    70
from logilab.mtconverter import xml_escape
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    71
from logilab.common.decorators import cachedproperty
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    72
from logilab.common.deprecation import class_deprecated
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8159
diff changeset
    73
from logilab.common.registry import yes
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    74
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7415
diff changeset
    75
from cubicweb import NoSelectableObject, tags
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8159
diff changeset
    76
from cubicweb.predicates import nonempty_rset, match_kwargs, objectify_predicate
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
    77
from cubicweb.schema import display_name
8060
8acfd23578a8 [table] display navigation component both above and below the table
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8058
diff changeset
    78
from cubicweb.utils import make_uid, js_dumps, JSString, UStringIO
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
    79
from cubicweb.uilib import toggle_action, limitsize, htmlescape, sgml_attributes, domid
762
a6f678fe7e44 update some imports
sylvain.thenault@logilab.fr
parents: 742
diff changeset
    80
from cubicweb.view import EntityView, AnyRsetView
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    81
from cubicweb.web import jsonize, component
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
from cubicweb.web.htmlwidgets import (TableWidget, TableColumn, MenuWidget,
6800
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    83
                                      PopupBoxMenu)
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7415
diff changeset
    84
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8159
diff changeset
    86
@objectify_predicate
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    87
def unreloadable_table(cls, req, rset=None,
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    88
                       displaycols=None, headers=None, cellvids=None,
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    89
                       paginate=False, displayactions=False, displayfilter=False,
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    90
                       **kwargs):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    91
    # one may wish to specify one of headers/displaycols/cellvids as long as he
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    92
    # doesn't want pagination nor actions nor facets
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    93
    if not kwargs and (displaycols or headers or cellvids) and not (
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    94
        displayfilter or displayactions or paginate):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    95
        return 1
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    96
    return 0
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    97
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    98
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
    99
class TableLayout(component.Component):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   100
    """The default layout for table. When `render` is called, this will use
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   101
    the API described on :class:`TableMixIn` to feed the generated table.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   102
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   103
    This layout behaviour may be customized using the following attributes /
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   104
    selection arguments:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   105
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   106
    * `cssclass`, a string that should be used as HTML class attribute. Default
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   107
      to "listing".
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   108
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   109
    * `needs_css`, the CSS files that should be used together with this
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   110
      table. Default to ('cubicweb.tablesorter.css', 'cubicweb.tableview.css').
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   111
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   112
    * `needs_js`, the Javascript files that should be used together with this
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   113
      table. Default to ('jquery.tablesorter.js',)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   114
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   115
    * `display_filter`, tells if the facets filter should be displayed when
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   116
      possible. Allowed values are:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   117
      - `None`, don't display it
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   118
      - 'top', display it above the table
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   119
      - 'bottom', display it below the table
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   120
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   121
    * `display_actions`, tells if a menu for available actions should be
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   122
      displayed when possible (see two following options). Allowed values are:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   123
      - `None`, don't display it
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   124
      - 'top', display it above the table
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   125
      - 'bottom', display it below the table
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   126
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   127
    * `hide_filter`, when true (the default), facets filter will be hidden by
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   128
      default, with an action in the actions menu allowing to show / hide it.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   129
8060
8acfd23578a8 [table] display navigation component both above and below the table
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8058
diff changeset
   130
    * `show_all_option`, when true, a *show all results* link will be displayed
8acfd23578a8 [table] display navigation component both above and below the table
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8058
diff changeset
   131
      below the navigation component.
8acfd23578a8 [table] display navigation component both above and below the table
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8058
diff changeset
   132
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   133
    * `add_view_actions`, when true, actions returned by view.table_actions()
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   134
      will be included in the actions menu.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   135
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   136
    * `header_column_idx`, if not `None`, should be a colum index or a set of
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   137
      column index where <th> tags should be generated instead of <td>
8418
3f87aa655466 [docstrings] typos corrected
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8417
diff changeset
   138
    """ #'# make emacs happier
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   139
    __regid__ = 'table_layout'
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   140
    cssclass = "listing"
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   141
    needs_css = ('cubicweb.tableview.css',)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   142
    needs_js = ()
8060
8acfd23578a8 [table] display navigation component both above and below the table
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8058
diff changeset
   143
    display_filter = None    # None / 'top' / 'bottom'
8acfd23578a8 [table] display navigation component both above and below the table
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8058
diff changeset
   144
    display_actions = 'top'  # None / 'top' / 'bottom'
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   145
    hide_filter = True
8060
8acfd23578a8 [table] display navigation component both above and below the table
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8058
diff changeset
   146
    show_all_option = True   # make navcomp generate a 'show all' results link
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   147
    add_view_actions = False
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   148
    header_column_idx = None
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   149
    enable_sorting = True
8006
32d7682991ce [tableview] sortvalue truncation should be somewhat configurable
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8003
diff changeset
   150
    sortvalue_limit = 10
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   151
    tablesorter_settings = {
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   152
        'textExtraction': JSString('cw.sortValueExtraction'),
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   153
        'selectorHeaders': "thead tr:first th[class='sortable']", # only plug on the first row
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   154
        }
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   155
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   156
    def _setup_tablesorter(self, divid):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   157
        self._cw.add_css('cubicweb.tablesorter.css')
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   158
        self._cw.add_js('jquery.tablesorter.js')
8003
7e240c04c69f undo garbage shipped in 9a73d5e762b0
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8000
diff changeset
   159
        self._cw.add_onload('''$(document).ready(function() {
7e240c04c69f undo garbage shipped in 9a73d5e762b0
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8000
diff changeset
   160
    $("#%s table").tablesorter(%s);
7e240c04c69f undo garbage shipped in 9a73d5e762b0
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8000
diff changeset
   161
});''' % (divid, js_dumps(self.tablesorter_settings)))
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   162
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   163
    def __init__(self, req, view, **kwargs):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   164
        super(TableLayout, self).__init__(req, **kwargs)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   165
        for key, val in self.cw_extra_kwargs.items():
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   166
            if hasattr(self.__class__, key) and not key[0] == '_':
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   167
                setattr(self, key, val)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   168
                self.cw_extra_kwargs.pop(key)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   169
        self.view = view
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   170
        if self.header_column_idx is None:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   171
            self.header_column_idx = frozenset()
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   172
        elif isinstance(self.header_column_idx, int):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   173
            self.header_column_idx = frozenset( (self.header_column_idx,) )
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   174
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   175
    @cachedproperty
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   176
    def initial_load(self):
8480
086cff6a306a [book] fix build warnings/errors. Closes #2430042
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8425
diff changeset
   177
        """We detect a bit heuristically if we are built for the first time or
086cff6a306a [book] fix build warnings/errors. Closes #2430042
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8425
diff changeset
   178
        from subsequent calls by the form filter or by the pagination hooks.
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   179
        """
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   180
        form = self._cw.form
8102
619d41a4c770 [navigation] provide a link back from the full view to the paginated one
Julien Cristau <julien.cristau@logilab.fr>
parents: 8094
diff changeset
   181
        return 'fromformfilter' not in form and '__fromnavigation' not in form
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   182
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   183
    def render(self, w, **kwargs):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   184
        assert self.display_filter in (None, 'top', 'bottom'), self.display_filter
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   185
        if self.needs_css:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   186
            self._cw.add_css(self.needs_css)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   187
        if self.needs_js:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   188
            self._cw.add_js(self.needs_js)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   189
        if self.enable_sorting:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   190
            self._setup_tablesorter(self.view.domid)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   191
        # Notice facets form must be rendered **outside** the main div as it
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   192
        # shouldn't be rendered on ajax call subsequent to facet restriction
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   193
        # (hence the 'fromformfilter' parameter added by the form
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   194
        generate_form = self.initial_load
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   195
        if self.display_filter and generate_form:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   196
            facetsform = self.view.facets_form()
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   197
        else:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   198
            facetsform = None
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   199
        if facetsform and self.display_filter == 'top':
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   200
            cssclass = u'hidden' if self.hide_filter else u''
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   201
            facetsform.render(w, vid=self.view.__regid__, cssclass=cssclass,
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   202
                              divid=self.view.domid)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   203
        actions = []
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   204
        if self.add_view_actions:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   205
            actions = self.view.table_actions()
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   206
        if self.display_filter and self.hide_filter and (facetsform or not generate_form):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   207
            actions += self.show_hide_filter_actions(not generate_form)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   208
        self.render_table(w, actions, self.view.paginable)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   209
        if facetsform and self.display_filter == 'bottom':
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   210
            cssclass = u'hidden' if self.hide_filter else u''
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   211
            facetsform.render(w, vid=self.view.__regid__, cssclass=cssclass,
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   212
                              divid=self.view.domid)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   213
8014
6ce4ff44b2cf [tableview] extract two methods from render_table to ease subclassing
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8012
diff changeset
   214
    def render_table_headers(self, w, colrenderers):
6ce4ff44b2cf [tableview] extract two methods from render_table to ease subclassing
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8012
diff changeset
   215
        w(u'<thead><tr>')
6ce4ff44b2cf [tableview] extract two methods from render_table to ease subclassing
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8012
diff changeset
   216
        for colrenderer in colrenderers:
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   217
            if colrenderer.sortable:
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   218
                w(u'<th class="sortable">')
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   219
            else:
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   220
                w(u'<th>')
8014
6ce4ff44b2cf [tableview] extract two methods from render_table to ease subclassing
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8012
diff changeset
   221
            colrenderer.render_header(w)
6ce4ff44b2cf [tableview] extract two methods from render_table to ease subclassing
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8012
diff changeset
   222
            w(u'</th>')
6ce4ff44b2cf [tableview] extract two methods from render_table to ease subclassing
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8012
diff changeset
   223
        w(u'</tr></thead>\n')
6ce4ff44b2cf [tableview] extract two methods from render_table to ease subclassing
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8012
diff changeset
   224
6ce4ff44b2cf [tableview] extract two methods from render_table to ease subclassing
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8012
diff changeset
   225
    def render_table_body(self, w, colrenderers):
6ce4ff44b2cf [tableview] extract two methods from render_table to ease subclassing
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8012
diff changeset
   226
        w(u'<tbody>')
6ce4ff44b2cf [tableview] extract two methods from render_table to ease subclassing
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8012
diff changeset
   227
        for rownum in xrange(self.view.table_size):
6ce4ff44b2cf [tableview] extract two methods from render_table to ease subclassing
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8012
diff changeset
   228
            self.render_row(w, rownum, colrenderers)
6ce4ff44b2cf [tableview] extract two methods from render_table to ease subclassing
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8012
diff changeset
   229
        w(u'</tbody>')
6ce4ff44b2cf [tableview] extract two methods from render_table to ease subclassing
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8012
diff changeset
   230
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   231
    def render_table(self, w, actions, paginate):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   232
        view = self.view
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   233
        divid = view.domid
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   234
        if divid is not None:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   235
            w(u'<div id="%s">' % divid)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   236
        else:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   237
            assert not (actions or paginate)
8060
8acfd23578a8 [table] display navigation component both above and below the table
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8058
diff changeset
   238
        nav_html = UStringIO()
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   239
        if paginate:
8060
8acfd23578a8 [table] display navigation component both above and below the table
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8058
diff changeset
   240
            view.paginate(w=nav_html.write, show_all_option=self.show_all_option)
8acfd23578a8 [table] display navigation component both above and below the table
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8058
diff changeset
   241
        w(nav_html.getvalue())
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   242
        if actions and self.display_actions == 'top':
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   243
            self.render_actions(w, actions)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   244
        colrenderers = view.build_column_renderers()
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   245
        attrs = self.table_attributes()
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   246
        w(u'<table %s>' % sgml_attributes(attrs))
8014
6ce4ff44b2cf [tableview] extract two methods from render_table to ease subclassing
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8012
diff changeset
   247
        if self.view.has_headers:
6ce4ff44b2cf [tableview] extract two methods from render_table to ease subclassing
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8012
diff changeset
   248
            self.render_table_headers(w, colrenderers)
6ce4ff44b2cf [tableview] extract two methods from render_table to ease subclassing
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8012
diff changeset
   249
        self.render_table_body(w, colrenderers)
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   250
        w(u'</table>')
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   251
        if actions and self.display_actions == 'bottom':
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   252
            self.render_actions(w, actions)
8060
8acfd23578a8 [table] display navigation component both above and below the table
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8058
diff changeset
   253
        w(nav_html.getvalue())
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   254
        if divid is not None:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   255
            w(u'</div>')
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   256
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   257
    def table_attributes(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   258
        return {'class': self.cssclass}
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   259
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   260
    def render_row(self, w, rownum, renderers):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   261
        attrs = self.row_attributes(rownum)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   262
        w(u'<tr %s>' % sgml_attributes(attrs))
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   263
        for colnum, renderer in enumerate(renderers):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   264
            self.render_cell(w, rownum, colnum, renderer)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   265
        w(u'</tr>\n')
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   266
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   267
    def row_attributes(self, rownum):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   268
        return {'class': 'odd' if (rownum%2==1) else 'even',
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   269
                'onmouseover': '$(this).addClass("highlighted");',
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   270
                'onmouseout': '$(this).removeClass("highlighted")'}
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   271
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   272
    def render_cell(self, w, rownum, colnum, renderer):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   273
        attrs = self.cell_attributes(rownum, colnum, renderer)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   274
        if colnum in self.header_column_idx:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   275
            tag = u'th'
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   276
        else:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   277
            tag = u'td'
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   278
        w(u'<%s %s>' % (tag, sgml_attributes(attrs)))
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   279
        renderer.render_cell(w, rownum)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   280
        w(u'</%s>' % tag)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   281
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   282
    def cell_attributes(self, rownum, _colnum, renderer):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   283
        attrs = renderer.attributes.copy()
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   284
        if renderer.sortable:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   285
            sortvalue = renderer.sortvalue(rownum)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   286
            if isinstance(sortvalue, basestring):
8006
32d7682991ce [tableview] sortvalue truncation should be somewhat configurable
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8003
diff changeset
   287
                sortvalue = sortvalue[:self.sortvalue_limit]
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   288
            if sortvalue is not None:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   289
                attrs[u'cubicweb:sortvalue'] = js_dumps(sortvalue)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   290
        return attrs
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   291
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   292
    def render_actions(self, w, actions):
8094
bedf36fb17f1 [tableview] fix action menu layout (closes #2099011)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8092
diff changeset
   293
        box = MenuWidget('', '', _class='tableActionsBox', islist=False)
bedf36fb17f1 [tableview] fix action menu layout (closes #2099011)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8092
diff changeset
   294
        label = tags.span(self._cw._('action menu'))
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   295
        menu = PopupBoxMenu(label, isitem=False, link_class='actionsBox',
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   296
                            ident='%sActions' % self.view.domid)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   297
        box.append(menu)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   298
        for action in actions:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   299
            menu.append(action)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   300
        box.render(w=w)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   301
        w(u'<div class="clear"></div>')
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   302
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   303
    def show_hide_filter_actions(self, currentlydisplayed=False):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   304
        divid = self.view.domid
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   305
        showhide = u';'.join(toggle_action('%s%s' % (divid, what))[11:]
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   306
                             for what in ('Form', 'Show', 'Hide', 'Actions'))
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   307
        showhide = 'javascript:' + showhide
8055
368d8902e597 [table view] properly handle show/hide filter actions so we get proper action displayed even when recalled from pagination
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8046
diff changeset
   308
        self._cw.add_onload(u'''\
368d8902e597 [table view] properly handle show/hide filter actions so we get proper action displayed even when recalled from pagination
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8046
diff changeset
   309
$(document).ready(function() {
368d8902e597 [table view] properly handle show/hide filter actions so we get proper action displayed even when recalled from pagination
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8046
diff changeset
   310
  if ($('#%(id)sForm[class=\"hidden\"]').length) {
368d8902e597 [table view] properly handle show/hide filter actions so we get proper action displayed even when recalled from pagination
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8046
diff changeset
   311
    $('#%(id)sHide').attr('class', 'hidden');
368d8902e597 [table view] properly handle show/hide filter actions so we get proper action displayed even when recalled from pagination
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8046
diff changeset
   312
  } else {
368d8902e597 [table view] properly handle show/hide filter actions so we get proper action displayed even when recalled from pagination
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8046
diff changeset
   313
    $('#%(id)sShow').attr('class', 'hidden');
368d8902e597 [table view] properly handle show/hide filter actions so we get proper action displayed even when recalled from pagination
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8046
diff changeset
   314
  }
368d8902e597 [table view] properly handle show/hide filter actions so we get proper action displayed even when recalled from pagination
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8046
diff changeset
   315
});''' % {'id': divid})
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   316
        showlabel = self._cw._('show filter form')
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   317
        hidelabel = self._cw._('hide filter form')
8055
368d8902e597 [table view] properly handle show/hide filter actions so we get proper action displayed even when recalled from pagination
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8046
diff changeset
   318
        return [component.Link(showhide, showlabel, id='%sShow' % divid),
368d8902e597 [table view] properly handle show/hide filter actions so we get proper action displayed even when recalled from pagination
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8046
diff changeset
   319
                component.Link(showhide, hidelabel, id='%sHide' % divid)]
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   320
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   321
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   322
class AbstractColumnRenderer(object):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   323
    """Abstract base class for column renderer. Interface of a column renderer follows:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   324
8032
bcb87336c7d2 [doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8028
diff changeset
   325
    .. automethod:: cubicweb.web.views.tableview.AbstractColumnRenderer.bind
bcb87336c7d2 [doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8028
diff changeset
   326
    .. automethod:: cubicweb.web.views.tableview.AbstractColumnRenderer.render_header
bcb87336c7d2 [doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8028
diff changeset
   327
    .. automethod:: cubicweb.web.views.tableview.AbstractColumnRenderer.render_cell
bcb87336c7d2 [doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8028
diff changeset
   328
    .. automethod:: cubicweb.web.views.tableview.AbstractColumnRenderer.sortvalue
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   329
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   330
    Attributes on this base class are:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   331
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   332
    :attr: `header`, the column header. If None, default to `_(colid)`
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   333
    :attr: `addcount`, if True, add the table size in parenthezis beside the header
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   334
    :attr: `trheader`, should the header be translated
8418
3f87aa655466 [docstrings] typos corrected
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8417
diff changeset
   335
    :attr: `escapeheader`, should the header be xml_escaped
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   336
    :attr: `sortable`, tell if the column is sortable
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   337
    :attr: `view`, the table view
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   338
    :attr: `_cw`, the request object
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   339
    :attr: `colid`, the column identifier
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   340
    :attr: `attributes`, dictionary of attributes to put on the HTML tag when
8032
bcb87336c7d2 [doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8028
diff changeset
   341
            the cell is rendered
8418
3f87aa655466 [docstrings] typos corrected
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8417
diff changeset
   342
    """ #'# make emacs
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   343
    attributes = {}
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   344
    empty_cell_content = u'&#160;'
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   345
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   346
    def __init__(self, header=None, addcount=False, trheader=True,
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   347
                 escapeheader=True, sortable=True):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   348
        self.header = header
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   349
        self.trheader = trheader
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   350
        self.escapeheader = escapeheader
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   351
        self.addcount = addcount
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   352
        self.sortable = sortable
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   353
        self.view = None
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   354
        self._cw = None
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   355
        self.colid = None
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   356
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   357
    def __str__(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   358
        return '<%s.%s (column %s)>' % (self.view.__class__.__name__,
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   359
                                        self.__class__.__name__,
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   360
                                        self.colid)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   361
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   362
    def bind(self, view, colid):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   363
        """Bind the column renderer to its view. This is where `_cw`, `view`,
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   364
        `colid` are set and the method to override if you want to add more
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   365
        view/request depending attributes on your column render.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   366
        """
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   367
        self.view = view
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   368
        self._cw = view._cw
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   369
        self.colid = colid
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   370
8065
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   371
    def copy(self):
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   372
        assert self.view is None
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   373
        return copy(self)
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   374
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   375
    def default_header(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   376
        """Return header for this column if one has not been specified."""
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   377
        return self._cw._(self.colid)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   378
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   379
    def render_header(self, w):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   380
        """Write label for the specified column by calling w()."""
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   381
        header = self.header
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   382
        if header is None:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   383
            header = self.default_header()
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   384
        elif self.trheader and header:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   385
           header = self._cw._(header)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   386
        if self.addcount:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   387
            header = '%s (%s)' % (header, self.view.table_size)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   388
        if header:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   389
            if self.escapeheader:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   390
                header = xml_escape(header)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   391
        else:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   392
            header = self.empty_cell_content
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   393
        if self.sortable:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   394
            header = tags.span(
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   395
                header, escapecontent=False,
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   396
                title=self._cw._('Click to sort on this column'))
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   397
        w(header)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   398
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   399
    def render_cell(self, w, rownum):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   400
        """Write value for the specified cell by calling w().
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   401
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   402
         :param `rownum`: the row number in the table
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   403
         """
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   404
        raise NotImplementedError()
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   405
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   406
    def sortvalue(self, _rownum):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   407
        """Return typed value to be used for sorting on the specified column.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   408
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   409
        :param `rownum`: the row number in the table
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   410
        """
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   411
        return None
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   412
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   413
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   414
class TableMixIn(component.LayoutableMixIn):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   415
    """Abstract mix-in class for layout based tables.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   416
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   417
    This default implementation's call method simply delegate to
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   418
    meth:`layout_render` that will select the renderer whose identifier is given
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   419
    by the :attr:`layout_id` attribute.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   420
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   421
    Then it provides some default implementation for various parts of the API
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   422
    used by that layout.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   423
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   424
    Abstract method you will have to override is:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   425
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   426
    .. automethod:: build_column_renderers
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   427
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   428
    You may also want to overridde:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   429
8032
bcb87336c7d2 [doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8028
diff changeset
   430
    .. autoattribute:: cubicweb.web.views.tableview.TableMixIn.table_size
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   431
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   432
    The :attr:`has_headers` boolean attribute tells if the table has some
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   433
    headers to be displayed. Default to `True`.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   434
    """
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   435
    __abstract__ = True
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   436
    # table layout to use
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   437
    layout_id = 'table_layout'
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   438
    # true if the table has some headers
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   439
    has_headers = True
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   440
    # dictionary {colid : column renderer}
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   441
    column_renderers = {}
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   442
    # default renderer class to use when no renderer specified for the column
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   443
    default_column_renderer_class = None
8009
75638a6ff159 [tableview,basetemplates,pagination] some views internally handle the pagination, in which case the base template should not try to paginate
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8007
diff changeset
   444
    # default layout handles inner pagination
75638a6ff159 [tableview,basetemplates,pagination] some views internally handle the pagination, in which case the base template should not try to paginate
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8007
diff changeset
   445
    handle_pagination = True
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   446
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   447
    def call(self, **kwargs):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   448
        self.layout_render(self.w)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   449
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   450
    def column_renderer(self, colid, *args, **kwargs):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   451
        """Return a column renderer for column of the given id."""
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   452
        try:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   453
            crenderer = self.column_renderers[colid]
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   454
        except KeyError:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   455
            crenderer = self.default_column_renderer_class(*args, **kwargs)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   456
        crenderer.bind(self, colid)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   457
        return crenderer
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   458
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   459
    # layout callbacks #########################################################
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   460
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   461
    def facets_form(self, **kwargs):# XXX extracted from jqplot cube
8156
f47252e24354 [tableviews] use ``select_or_none`` instead of ``try: select() except:``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8102
diff changeset
   462
        return self._cw.vreg['views'].select_or_none(
f47252e24354 [tableviews] use ``select_or_none`` instead of ``try: select() except:``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8102
diff changeset
   463
            'facet.filtertable', self._cw, rset=self.cw_rset, view=self,
f47252e24354 [tableviews] use ``select_or_none`` instead of ``try: select() except:``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8102
diff changeset
   464
            **kwargs)
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   465
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   466
    @cachedproperty
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   467
    def domid(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   468
        return self._cw.form.get('divid') or domid('%s-%s' % (self.__regid__, make_uid()))
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   469
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   470
    @property
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   471
    def table_size(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   472
        """Return the number of rows (header excluded) to be displayed.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   473
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   474
        By default return the number of rows in the view's result set. If your
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   475
        table isn't reult set based, override this method.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   476
        """
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   477
        return self.cw_rset.rowcount
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   478
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   479
    def build_column_renderers(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   480
        """Return a list of column renderers, one for each column to be
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   481
        rendered. Prototype of a column renderer is described below:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   482
8032
bcb87336c7d2 [doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8028
diff changeset
   483
        .. autoclass:: cubicweb.web.views.tableview.AbstractColumnRenderer
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   484
        """
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   485
        raise NotImplementedError()
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   486
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   487
    def table_actions(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   488
        """Return a list of actions (:class:`~cubicweb.web.component.Link`) that
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   489
        match the view's result set, and return those in the 'mainactions'
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   490
        category.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   491
        """
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   492
        req = self._cw
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   493
        actions = []
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   494
        actionsbycat = req.vreg['actions'].possible_actions(req, self.cw_rset)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   495
        for action in actionsbycat.get('mainactions', ()):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   496
            for action in action.actual_actions():
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   497
                actions.append(component.Link(action.url(), req._(action.title),
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   498
                                              klass=action.html_class()) )
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   499
        return actions
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   500
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   501
    # interaction with navigation component ####################################
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   502
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   503
    def page_navigation_url(self, navcomp, _path, params):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   504
        params['divid'] = self.domid
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   505
        params['vid'] = self.__regid__
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   506
        return navcomp.ajax_page_url(**params)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   507
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   508
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   509
class RsetTableColRenderer(AbstractColumnRenderer):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   510
    """Default renderer for :class:`RsetTableView`."""
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   511
8157
098c83a99807 [tableview] drop useless code: cellvid systematically given by RsetTableView, according to its .[non]finalview attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8102
diff changeset
   512
    def __init__(self, cellvid, **kwargs):
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   513
        super(RsetTableColRenderer, self).__init__(**kwargs)
8157
098c83a99807 [tableview] drop useless code: cellvid systematically given by RsetTableView, according to its .[non]finalview attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8102
diff changeset
   514
        self.cellvid = cellvid
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   515
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   516
    def bind(self, view, colid):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   517
        super(RsetTableColRenderer, self).bind(view, colid)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   518
        self.cw_rset = view.cw_rset
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   519
    def render_cell(self, w, rownum):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   520
        self._cw.view(self.cellvid, self.cw_rset, 'empty-cell',
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   521
                      row=rownum, col=self.colid, w=w)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   522
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   523
    # limit value's length as much as possible (e.g. by returning the 10 first
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   524
    # characters of a string)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   525
    def sortvalue(self, rownum):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   526
        colid = self.colid
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   527
        val = self.cw_rset[rownum][colid]
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   528
        if val is None:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   529
            return u''
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   530
        etype = self.cw_rset.description[rownum][colid]
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   531
        if etype is None:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   532
            return u''
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   533
        if self._cw.vreg.schema.eschema(etype).final:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   534
            entity, rtype = self.cw_rset.related_entity(rownum, colid)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   535
            if entity is None:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   536
                return val # remove_html_tags() ?
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   537
            return entity.sortvalue(rtype)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   538
        entity = self.cw_rset.get_entity(rownum, colid)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   539
        return entity.sortvalue()
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   540
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   541
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   542
class RsetTableView(TableMixIn, AnyRsetView):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   543
    """This table view accepts any non-empty rset. It uses introspection on the
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   544
    result set to compute column names and the proper way to display the cells.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   545
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   546
    It is highly configurable and accepts a wealth of options, but take care to
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   547
    check what you're trying to achieve wouldn't be a job for the
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   548
    :class:`EntityTableView`. Basically the question is: does this view should
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   549
    be tied to the result set query's shape or no? If yes, than you're fine. If
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   550
    no, you should take a look at the other table implementation.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   551
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   552
    The following class attributes may be used to control the table:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   553
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   554
    * `finalvid`, a view identifier that should be called on final entities
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   555
      (e.g. attribute values). Default to 'final'.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   556
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   557
    * `nonfinalvid`, a view identifier that should be called on
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   558
      entities. Default to 'incontext'.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   559
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   560
    * `displaycols`, if not `None`, should be a list of rset's columns to be
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   561
      displayed.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   562
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   563
    * `headers`, if not `None`, should be a list of headers for the table's
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   564
      columns.  `None` values in the list will be replaced by computed column
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   565
      names.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   566
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   567
    * `cellvids`, if not `None`, should be a dictionary with table column index
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   568
      as key and a view identifier as value, telling the view that should be
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   569
      used in the given column.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   570
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   571
    Notice `displaycols`, `headers` and `cellvids` may be specified at selection
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   572
    time but then the table won't have pagination and shouldn't be configured to
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   573
    display the facets filter nor actions (as they wouldn't behave as expected).
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   574
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   575
    This table class use the :class:`RsetTableColRenderer` as default column
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   576
    renderer.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   577
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   578
    .. autoclass:: RsetTableColRenderer
8418
3f87aa655466 [docstrings] typos corrected
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8417
diff changeset
   579
    """    #'# make emacs happier
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   580
    __regid__ = 'table'
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   581
    # selector trick for bw compath with the former :class:TableView
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   582
    __select__ = AnyRsetView.__select__ & (~match_kwargs(
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   583
        'title', 'subvid', 'displayfilter', 'headers', 'displaycols',
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   584
        'displayactions', 'actions', 'divid', 'cellvids', 'cellattrs',
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   585
        'mainindex', 'paginate', 'page_size', mode='any')
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   586
                                            | unreloadable_table())
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   587
    title = _('table')
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   588
    # additional configuration parameters
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   589
    finalvid = 'final'
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   590
    nonfinalvid = 'incontext'
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   591
    displaycols = None
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   592
    headers = None
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   593
    cellvids = None
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   594
    default_column_renderer_class = RsetTableColRenderer
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   595
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   596
    def linkable(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   597
        # specific subclasses of this view usually don't want to be linkable
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   598
        # since they depends on a particular shape (being linkable meaning view
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   599
        # may be listed in possible views
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   600
        return self.__regid__ == 'table'
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   601
8417
24409e9c7c66 [views] enable paginate toggle on RsetTableView (closes #2200675)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8344
diff changeset
   602
    def call(self, headers=None, displaycols=None, cellvids=None,
24409e9c7c66 [views] enable paginate toggle on RsetTableView (closes #2200675)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8344
diff changeset
   603
             paginate=None, **kwargs):
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   604
        if self.headers:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   605
            self.headers = [h and self._cw._(h) for h in self.headers]
8417
24409e9c7c66 [views] enable paginate toggle on RsetTableView (closes #2200675)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8344
diff changeset
   606
        if (headers or displaycols or cellvids or paginate):
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   607
            if headers is not None:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   608
                self.headers = headers
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   609
            if displaycols is not None:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   610
                self.displaycols = displaycols
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   611
            if cellvids is not None:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   612
                self.cellvids = cellvids
8417
24409e9c7c66 [views] enable paginate toggle on RsetTableView (closes #2200675)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8344
diff changeset
   613
            if paginate is not None:
24409e9c7c66 [views] enable paginate toggle on RsetTableView (closes #2200675)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8344
diff changeset
   614
                self.paginable = paginate
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   615
        if kwargs:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   616
            # old table view arguments that we can safely ignore thanks to
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   617
            # selectors
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   618
            if len(kwargs) > 1:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   619
                msg = '[3.14] %s arguments are deprecated' % ', '.join(kwargs)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   620
            else:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   621
                msg = '[3.14] %s argument is deprecated' % ', '.join(kwargs)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   622
            warn(msg, DeprecationWarning, stacklevel=2)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   623
        self.layout_render(self.w)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   624
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   625
    def main_var_index(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   626
        """returns the index of the first non-attribute variable among the RQL
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   627
        selected variables
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   628
        """
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   629
        eschema = self._cw.vreg.schema.eschema
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   630
        for i, etype in enumerate(self.cw_rset.description[0]):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   631
            if not eschema(etype).final:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   632
                return i
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   633
        return None
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   634
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   635
    # layout callbacks #########################################################
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   636
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   637
    @property
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   638
    def table_size(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   639
        """return the number of rows (header excluded) to be displayed"""
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   640
        return self.cw_rset.rowcount
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   641
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   642
    def build_column_renderers(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   643
        headers = self.headers
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   644
        # compute displayed columns
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   645
        if self.displaycols is None:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   646
            if headers is not None:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   647
                displaycols = range(len(headers))
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   648
            else:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   649
                rqlst = self.cw_rset.syntax_tree()
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   650
                displaycols = range(len(rqlst.children[0].selection))
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   651
        else:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   652
            displaycols = self.displaycols
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   653
        # compute table headers
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   654
        main_var_index = self.main_var_index()
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   655
        computed_titles = self.columns_labels(main_var_index)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   656
        # compute build renderers
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   657
        cellvids = self.cellvids
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   658
        renderers = []
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   659
        for colnum, colid in enumerate(displaycols):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   660
            addcount = False
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   661
            # compute column header
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   662
            title = None
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   663
            if headers is not None:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   664
                title = headers[colnum]
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   665
            if title is None:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   666
                title = computed_titles[colid]
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   667
            if colid == main_var_index:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   668
                addcount = True
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   669
            # compute cell vid for the column
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   670
            if cellvids is not None and colnum in cellvids:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   671
                cellvid = cellvids[colnum]
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   672
            else:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   673
                coltype = self.cw_rset.description[0][colid]
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   674
                if coltype is not None and self._cw.vreg.schema.eschema(coltype).final:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   675
                    cellvid = self.finalvid
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   676
                else:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   677
                    cellvid = self.nonfinalvid
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   678
            # get renderer
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   679
            renderer = self.column_renderer(colid, header=title, trheader=False,
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   680
                                            addcount=addcount, cellvid=cellvid)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   681
            renderers.append(renderer)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   682
        return renderers
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   683
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   684
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   685
class EntityTableColRenderer(AbstractColumnRenderer):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   686
    """Default column renderer for :class:`EntityTableView`.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   687
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   688
    You may use the :meth:`entity` method to retrieve the main entity for a
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   689
    given row number.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   690
8032
bcb87336c7d2 [doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8028
diff changeset
   691
    .. automethod:: cubicweb.web.views.tableview.EntityTableColRenderer.entity
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   692
    .. automethod:: cubicweb.web.views.tableview.EntityTableColRenderer.render_entity
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   693
    .. automethod:: cubicweb.web.views.tableview.EntityTableColRenderer.entity_sortvalue
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   694
    """
8070
61fb207ad2d8 [tableview] fix __init__ logic of sortfunc/sortable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8066
diff changeset
   695
    def __init__(self, renderfunc=None, sortfunc=None, sortable=None, **kwargs):
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   696
        if renderfunc is None:
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   697
            renderfunc = self.render_entity
8070
61fb207ad2d8 [tableview] fix __init__ logic of sortfunc/sortable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8066
diff changeset
   698
            # if renderfunc nor sortfunc nor sortable specified, column will be
61fb207ad2d8 [tableview] fix __init__ logic of sortfunc/sortable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8066
diff changeset
   699
            # sortable using the default implementation.
61fb207ad2d8 [tableview] fix __init__ logic of sortfunc/sortable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8066
diff changeset
   700
            if sortable is None:
61fb207ad2d8 [tableview] fix __init__ logic of sortfunc/sortable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8066
diff changeset
   701
                sortable = True
61fb207ad2d8 [tableview] fix __init__ logic of sortfunc/sortable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8066
diff changeset
   702
        # no sortfunc given but asked to be sortable: use the default sort
61fb207ad2d8 [tableview] fix __init__ logic of sortfunc/sortable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8066
diff changeset
   703
        # method. Sub-class may set `entity_sortvalue` to None if they don't
61fb207ad2d8 [tableview] fix __init__ logic of sortfunc/sortable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8066
diff changeset
   704
        # support sorting.
61fb207ad2d8 [tableview] fix __init__ logic of sortfunc/sortable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8066
diff changeset
   705
        if sortfunc is None and sortable:
61fb207ad2d8 [tableview] fix __init__ logic of sortfunc/sortable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8066
diff changeset
   706
            sortfunc = self.entity_sortvalue
61fb207ad2d8 [tableview] fix __init__ logic of sortfunc/sortable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8066
diff changeset
   707
        # at this point `sortable` may still be unspecified while `sortfunc` is
61fb207ad2d8 [tableview] fix __init__ logic of sortfunc/sortable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8066
diff changeset
   708
        # sure to be set to someting else than None if the column is sortable.
61fb207ad2d8 [tableview] fix __init__ logic of sortfunc/sortable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8066
diff changeset
   709
        sortable = sortfunc is not None
61fb207ad2d8 [tableview] fix __init__ logic of sortfunc/sortable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8066
diff changeset
   710
        super(EntityTableColRenderer, self).__init__(sortable=sortable, **kwargs)
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   711
        self.renderfunc = renderfunc
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   712
        self.sortfunc = sortfunc
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   713
8065
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   714
    def copy(self):
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   715
        assert self.view is None
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   716
        # copy of attribute referencing a method doesn't work with python < 2.7
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   717
        renderfunc = self.__dict__.pop('renderfunc')
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   718
        sortfunc = self.__dict__.pop('sortfunc')
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   719
        try:
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   720
            acopy =  copy(self)
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   721
            for aname, member in[('renderfunc', renderfunc),
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   722
                                 ('sortfunc', sortfunc)]:
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   723
                if isinstance(member, MethodType):
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   724
                    member = MethodType(member.im_func, acopy, acopy.__class__)
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   725
                setattr(acopy, aname, member)
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   726
            return acopy
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   727
        finally:
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   728
            self.renderfunc = renderfunc
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   729
            self.sortfunc = sortfunc
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   730
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   731
    def render_cell(self, w, rownum):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   732
        entity = self.entity(rownum)
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   733
        if entity is None:
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   734
            w(self.empty_cell_content)
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   735
        else:
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   736
            self.renderfunc(w, entity)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   737
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   738
    def sortvalue(self, rownum):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   739
        entity = self.entity(rownum)
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   740
        if entity is None:
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   741
            return None
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   742
        else:
8028
58e9bc8a1f2c [tableview] .entity method is useful on EntityTableView as well, move it there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8016
diff changeset
   743
            return self.sortfunc(entity)
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   744
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   745
    def entity(self, rownum):
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   746
        """Convenience method returning the table's main entity."""
8028
58e9bc8a1f2c [tableview] .entity method is useful on EntityTableView as well, move it there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8016
diff changeset
   747
        return self.view.entity(rownum)
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   748
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   749
    def render_entity(self, w, entity):
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   750
        """Sort value if `renderfunc` nor `sortfunc` specified at
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   751
        initialization.
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   752
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   753
        This default implementation consider column id is an entity attribute
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   754
        and print its value.
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   755
        """
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   756
        w(entity.printable_value(self.colid))
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   757
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   758
    def entity_sortvalue(self, entity):
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   759
        """Cell rendering implementation if `renderfunc` nor `sortfunc`
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   760
        specified at initialization.
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   761
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   762
        This default implementation consider column id is an entity attribute
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   763
        and return its sort value by calling `entity.sortvalue(colid)`.
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   764
        """
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   765
        return entity.sortvalue(self.colid)
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   766
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   767
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   768
class MainEntityColRenderer(EntityTableColRenderer):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   769
    """Renderer to be used for the column displaying the 'main entity' of a
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   770
    :class:`EntityTableView`.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   771
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   772
    By default display it using the 'incontext' view. You may specify another
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   773
    view identifier using the `vid` argument.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   774
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   775
    If header not specified, it would be built using entity types in the main
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   776
    column.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   777
    """
8046
bdd555df7a91 [entity table view] add count default to true on main entity column
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8042
diff changeset
   778
    def __init__(self, vid='incontext', addcount=True, **kwargs):
bdd555df7a91 [entity table view] add count default to true on main entity column
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8042
diff changeset
   779
        super(MainEntityColRenderer, self).__init__(addcount=addcount, **kwargs)
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   780
        self.vid = vid
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   781
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   782
    def default_header(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   783
        view = self.view
8089
0bce018bc7d7 [EntityTableView] smarter header for MainEntityColRenderer: use plural form only when necessary. Closes #2093182
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8088
diff changeset
   784
        if len(view.cw_rset) > 1:
0bce018bc7d7 [EntityTableView] smarter header for MainEntityColRenderer: use plural form only when necessary. Closes #2093182
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8088
diff changeset
   785
            suffix = '_plural'
0bce018bc7d7 [EntityTableView] smarter header for MainEntityColRenderer: use plural form only when necessary. Closes #2093182
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8088
diff changeset
   786
        else:
0bce018bc7d7 [EntityTableView] smarter header for MainEntityColRenderer: use plural form only when necessary. Closes #2093182
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8088
diff changeset
   787
            suffix = ''
0bce018bc7d7 [EntityTableView] smarter header for MainEntityColRenderer: use plural form only when necessary. Closes #2093182
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8088
diff changeset
   788
        return u', '.join(self._cw.__(et + suffix)
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   789
                          for et in view.cw_rset.column_types(view.cw_col or 0))
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   790
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   791
    def render_entity(self, w, entity):
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   792
        entity.view(self.vid, w=w)
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   793
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   794
    def entity_sortvalue(self, entity):
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   795
        return entity.sortvalue()
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   796
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   797
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   798
class RelatedEntityColRenderer(MainEntityColRenderer):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   799
    """Renderer to be used for column displaying an entity related the 'main
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   800
    entity' of a :class:`EntityTableView`.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   801
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   802
    By default display it using the 'incontext' view. You may specify another
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   803
    view identifier using the `vid` argument.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   804
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   805
    If header not specified, it would be built by translating the column id.
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   806
    """
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   807
    def __init__(self, getrelated, addcount=False, **kwargs):
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   808
        super(RelatedEntityColRenderer, self).__init__(addcount=addcount, **kwargs)
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   809
        self.getrelated = getrelated
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   810
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   811
    def entity(self, rownum):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   812
        entity = super(RelatedEntityColRenderer, self).entity(rownum)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   813
        return self.getrelated(entity)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   814
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   815
    def default_header(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   816
        return self._cw._(self.colid)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   817
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   818
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   819
class RelationColRenderer(EntityTableColRenderer):
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   820
    """Renderer to be used for column displaying a list of entities related the
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   821
    'main entity' of a :class:`EntityTableView`. By default, the main entity is
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   822
    considered as the subject of the relation but you may specify otherwise
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   823
    using the `role` argument.
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   824
8088
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   825
    By default display the related rset using the 'csv' view, using
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   826
    'outofcontext' sub-view for each entity. You may specify another view
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   827
    identifier using respectivly the `vid` and `subvid` arguments.
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   828
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   829
    If you specify a 'rtype view', such as 'reledit', you should add a
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   830
    is_rtype_view=True parameter.
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   831
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   832
    If header not specified, it would be built by translating the column id,
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   833
    properly considering role.
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   834
    """
8088
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   835
    def __init__(self, role='subject', vid='csv', subvid=None,
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   836
                 fallbackvid='empty-cell', is_rtype_view=False, **kwargs):
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   837
        super(RelationColRenderer, self).__init__(**kwargs)
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   838
        self.role = role
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   839
        self.vid = vid
8088
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   840
        if subvid is None and vid in ('csv', 'list'):
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   841
            subvid = 'outofcontext'
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   842
        self.subvid = subvid
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   843
        self.fallbackvid = fallbackvid
8088
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   844
        self.is_rtype_view = is_rtype_view
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   845
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   846
    def render_entity(self, w, entity):
8088
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   847
        kwargs = {'w': w}
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   848
        if self.is_rtype_view:
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   849
            rset = None
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   850
            kwargs['entity'] = entity
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   851
            kwargs['rtype'] = self.colid
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   852
            kwargs['role'] = self.role
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   853
        else:
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   854
            rset = entity.related(self.colid, self.role)
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   855
        if self.subvid is not None:
8092
bc2a7c9fe266 [views/table] fix typo
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8089
diff changeset
   856
            kwargs['subvid'] = self.subvid
8088
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   857
        self._cw.view(self.vid, rset, self.fallbackvid, **kwargs)
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   858
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   859
    def default_header(self):
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   860
        return display_name(self._cw, self.colid, self.role)
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   861
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   862
    entity_sortvalue = None # column not sortable by default
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   863
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   864
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   865
class EntityTableView(TableMixIn, EntityView):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   866
    """This abstract table view is designed to be used with an
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8159
diff changeset
   867
    :class:`is_instance()` or :class:`adaptable` predicate, hence doesn't depend
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   868
    the result set shape as the :class:`TableView` does.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   869
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   870
    It will display columns that should be defined using the `columns` class
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   871
    attribute containing a list of column ids. By default, each column is
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   872
    renderered by :class:`EntityTableColRenderer` which consider that the column
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   873
    id is an attribute of the table's main entity (ie the one for which the view
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   874
    is selected).
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   875
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   876
    You may wish to specify :class:`MainEntityColRenderer` or
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   877
    :class:`RelatedEntityColRenderer` renderer for a column in the
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   878
    :attr:`column_renderers` dictionary.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   879
8032
bcb87336c7d2 [doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8028
diff changeset
   880
    .. autoclass:: cubicweb.web.views.tableview.EntityTableColRenderer
bcb87336c7d2 [doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8028
diff changeset
   881
    .. autoclass:: cubicweb.web.views.tableview.MainEntityColRenderer
bcb87336c7d2 [doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8028
diff changeset
   882
    .. autoclass:: cubicweb.web.views.tableview.RelatedEntityColRenderer
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   883
    .. autoclass:: cubicweb.web.views.tableview.RelationColRenderer
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   884
    """
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   885
    __abstract__ = True
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   886
    default_column_renderer_class = EntityTableColRenderer
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   887
    columns = None # to be defined in concret class
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   888
8344
9eda40a9ec08 [table view] EntityTableView should accept **kwargs as RsetTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8157
diff changeset
   889
    def call(self, columns=None, **kwargs):
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   890
        if columns is not None:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   891
            self.columns = columns
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   892
        self.layout_render(self.w)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   893
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   894
    @property
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   895
    def table_size(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   896
        return self.cw_rset.rowcount
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   897
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   898
    def build_column_renderers(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   899
        return [self.column_renderer(colid) for colid in self.columns]
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   900
8028
58e9bc8a1f2c [tableview] .entity method is useful on EntityTableView as well, move it there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8016
diff changeset
   901
    def entity(self, rownum):
58e9bc8a1f2c [tableview] .entity method is useful on EntityTableView as well, move it there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8016
diff changeset
   902
        """Return the table's main entity"""
58e9bc8a1f2c [tableview] .entity method is useful on EntityTableView as well, move it there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8016
diff changeset
   903
        return self.cw_rset.get_entity(rownum, self.cw_col or 0)
58e9bc8a1f2c [tableview] .entity method is useful on EntityTableView as well, move it there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8016
diff changeset
   904
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   905
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   906
class EmptyCellView(AnyRsetView):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   907
    __regid__ = 'empty-cell'
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   908
    __select__ = yes()
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   909
    def call(self, **kwargs):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   910
        self.w(u'&#160;')
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   911
    cell_call = call
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   912
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   913
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   914
################################################################################
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   915
# DEPRECATED tables ############################################################
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   916
################################################################################
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   917
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   918
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   919
class TableView(AnyRsetView):
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7415
diff changeset
   920
    """The table view accepts any non-empty rset. It uses introspection on the
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7415
diff changeset
   921
    result set to compute column names and the proper way to display the cells.
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7415
diff changeset
   922
5312
d2dbba898a96 [doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4618
diff changeset
   923
    It is however highly configurable and accepts a wealth of options.
d2dbba898a96 [doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4618
diff changeset
   924
    """
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   925
    __metaclass__ = class_deprecated
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   926
    __deprecation_warning__ = '[3.14] %(cls)s is deprecated'
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3230
diff changeset
   927
    __regid__ = 'table'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   928
    title = _('table')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   929
    finalview = 'final'
497
68d4211518c5 refactor table views to share more code and to avoid empty filter table in some case
sylvain.thenault@logilab.fr
parents: 469
diff changeset
   930
7830
37d23a1d3547 [views/table] parametrize table view co-classes (closes #1947472)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7814
diff changeset
   931
    table_widget_class = TableWidget
37d23a1d3547 [views/table] parametrize table view co-classes (closes #1947472)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7814
diff changeset
   932
    table_column_class = TableColumn
37d23a1d3547 [views/table] parametrize table view co-classes (closes #1947472)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7814
diff changeset
   933
7952
48330faf4cd7 [table] use explicit add_onload() to setup table sorting (closes #2013493)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7900
diff changeset
   934
    tablesorter_settings = {
7953
a37531c8a4a6 merge and fix cubicwebSortValueExtraction pb which disappeared when tablesorter.js has been updated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7946 7952
diff changeset
   935
        'textExtraction': JSString('cw.sortValueExtraction'),
7958
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7953
diff changeset
   936
        'selectorHeaders': 'thead tr:first th', # only plug on the first row
7952
48330faf4cd7 [table] use explicit add_onload() to setup table sorting (closes #2013493)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7900
diff changeset
   937
        }
8016
1a1b23c37013 [tableview,jsoncontroller] the json controller must check view.handle_pagination as well & the old table view also handles pagination internally
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8014
diff changeset
   938
    handle_pagination = True
7952
48330faf4cd7 [table] use explicit add_onload() to setup table sorting (closes #2013493)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7900
diff changeset
   939
497
68d4211518c5 refactor table views to share more code and to avoid empty filter table in some case
sylvain.thenault@logilab.fr
parents: 469
diff changeset
   940
    def form_filter(self, divid, displaycols, displayactions, displayfilter,
5669
1340f14c38c9 [table] propagate paginate
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5668
diff changeset
   941
                    paginate, hidden=True):
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7415
diff changeset
   942
        try:
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7415
diff changeset
   943
            filterform = self._cw.vreg['views'].select(
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7415
diff changeset
   944
                'facet.filtertable', self._cw, rset=self.cw_rset)
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7415
diff changeset
   945
        except NoSelectableObject:
497
68d4211518c5 refactor table views to share more code and to avoid empty filter table in some case
sylvain.thenault@logilab.fr
parents: 469
diff changeset
   946
            return ()
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7415
diff changeset
   947
        vidargs = {'paginate': paginate,
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7415
diff changeset
   948
                   'displaycols': displaycols,
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7415
diff changeset
   949
                   'displayactions': displayactions,
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7415
diff changeset
   950
                   'displayfilter': displayfilter}
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7415
diff changeset
   951
        cssclass = hidden and 'hidden' or ''
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7415
diff changeset
   952
        filterform.render(self.w, vid=self.__regid__, divid=divid,
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7415
diff changeset
   953
                          vidargs=vidargs, cssclass=cssclass)
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7415
diff changeset
   954
        return self.show_hide_actions(divid, not hidden)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   955
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   956
    def main_var_index(self):
8012
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
   957
        """Returns the index of the first non final variable of the rset.
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
   958
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
   959
        Used to select the main etype to help generate accurate column headers.
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
   960
        XXX explain the concept
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
   961
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
   962
        May return None if none is found.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   963
        """
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   964
        eschema = self._cw.vreg.schema.eschema
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   965
        for i, etype in enumerate(self.cw_rset.description[0]):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   966
            try:
3689
deb13e88e037 follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3228
diff changeset
   967
                if not eschema(etype).final:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   968
                    return i
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   969
            except KeyError: # XXX possible?
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   970
                continue
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   971
        return None
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   972
5239
471554b842d2 [schema view] the final touch. Things are getting nicely displayed, and code clean
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5234
diff changeset
   973
    def displaycols(self, displaycols, headers):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   974
        if displaycols is None:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   975
            if 'displaycols' in self._cw.form:
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   976
                displaycols = [int(idx) for idx in self._cw.form['displaycols']]
5239
471554b842d2 [schema view] the final touch. Things are getting nicely displayed, and code clean
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5234
diff changeset
   977
            elif headers is not None:
471554b842d2 [schema view] the final touch. Things are getting nicely displayed, and code clean
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5234
diff changeset
   978
                displaycols = range(len(headers))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   979
            else:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   980
                displaycols = range(len(self.cw_rset.syntax_tree().children[0].selection))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   981
        return displaycols
1635
866563e2d0fc don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents: 1370
diff changeset
   982
7952
48330faf4cd7 [table] use explicit add_onload() to setup table sorting (closes #2013493)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7900
diff changeset
   983
    def _setup_tablesorter(self, divid):
48330faf4cd7 [table] use explicit add_onload() to setup table sorting (closes #2013493)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7900
diff changeset
   984
        req = self._cw
48330faf4cd7 [table] use explicit add_onload() to setup table sorting (closes #2013493)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7900
diff changeset
   985
        req.add_js('jquery.tablesorter.js')
48330faf4cd7 [table] use explicit add_onload() to setup table sorting (closes #2013493)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7900
diff changeset
   986
        req.add_onload('''$(document).ready(function() {
48330faf4cd7 [table] use explicit add_onload() to setup table sorting (closes #2013493)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7900
diff changeset
   987
    $("#%s table.listing").tablesorter(%s);
48330faf4cd7 [table] use explicit add_onload() to setup table sorting (closes #2013493)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7900
diff changeset
   988
});''' % (divid, js_dumps(self.tablesorter_settings)))
48330faf4cd7 [table] use explicit add_onload() to setup table sorting (closes #2013493)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7900
diff changeset
   989
        req.add_css(('cubicweb.tablesorter.css', 'cubicweb.tableview.css'))
48330faf4cd7 [table] use explicit add_onload() to setup table sorting (closes #2013493)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7900
diff changeset
   990
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   991
    @cachedproperty
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   992
    def initial_load(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   993
        """We detect a bit heuristically if we are built for the first time of
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   994
        from subsequent calls by the form filter or by the pagination hooks
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   995
        """
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   996
        form = self._cw.form
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   997
        return 'fromformfilter' not in form and '__start' not in form
7952
48330faf4cd7 [table] use explicit add_onload() to setup table sorting (closes #2013493)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7900
diff changeset
   998
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   999
    def call(self, title=None, subvid=None, displayfilter=None, headers=None,
469
365826a58664 allow divid as argument
sylvain.thenault@logilab.fr
parents: 431
diff changeset
  1000
             displaycols=None, displayactions=None, actions=(), divid=None,
5617
f0bc8f5ddee2 [tableview] support for json-paginated table if paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5529
diff changeset
  1001
             cellvids=None, cellattrs=None, mainindex=None,
f0bc8f5ddee2 [tableview] support for json-paginated table if paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5529
diff changeset
  1002
             paginate=False, page_size=None):
5312
d2dbba898a96 [doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4618
diff changeset
  1003
        """Produces a table displaying a composite query
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1004
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1005
        :param title: title added before table
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1006
        :param subvid: cell view
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1007
        :param displayfilter: filter that selects rows to display
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1008
        :param headers: columns' titles
7883
cd98785b4a84 [views] fix docstring of tableview
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7830
diff changeset
  1009
        :param displaycols: indexes of columns to display (first column is 0)
cd98785b4a84 [views] fix docstring of tableview
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7830
diff changeset
  1010
        :param displayactions: if True, display action menu
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1011
        """
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1012
        req = self._cw
7952
48330faf4cd7 [table] use explicit add_onload() to setup table sorting (closes #2013493)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7900
diff changeset
  1013
        divid = divid or req.form.get('divid') or 'rs%s' % make_uid(id(self.cw_rset))
48330faf4cd7 [table] use explicit add_onload() to setup table sorting (closes #2013493)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7900
diff changeset
  1014
        self._setup_tablesorter(divid)
2226
f5216e540168 allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2206
diff changeset
  1015
        # compute label first  since the filter form may remove some necessary
f5216e540168 allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2206
diff changeset
  1016
        # information from the rql syntax tree
f5216e540168 allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2206
diff changeset
  1017
        if mainindex is None:
f5216e540168 allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2206
diff changeset
  1018
            mainindex = self.main_var_index()
2206
009e2856afcb columns_labels is an AnyRsetView method...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2204
diff changeset
  1019
        computed_labels = self.columns_labels(mainindex)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1020
        if not subvid and 'subvid' in req.form:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1021
            subvid = req.form.pop('subvid')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1022
        actions = list(actions)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1023
        if mainindex is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1024
            displayfilter, displayactions = False, False
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1025
        else:
6254
936e98213598 [table view] use get instead of has_key so one can specify he doesn't want actions or filter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6249
diff changeset
  1026
            if displayfilter is None and req.form.get('displayfilter'):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1027
                displayfilter = True
6254
936e98213598 [table view] use get instead of has_key so one can specify he doesn't want actions or filter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6249
diff changeset
  1028
            if displayactions is None and req.form.get('displayactions'):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1029
                displayactions = True
5239
471554b842d2 [schema view] the final touch. Things are getting nicely displayed, and code clean
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5234
diff changeset
  1030
        displaycols = self.displaycols(displaycols, headers)
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
  1031
        if self.initial_load:
3009
3deb0fa95761 no comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3006
diff changeset
  1032
            self.w(u'<div class="section">')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1033
            if not title and 'title' in req.form:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1034
                title = req.form['title']
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1035
            if title:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1036
                self.w(u'<h2 class="tableTitle">%s</h2>\n' % title)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1037
            if displayfilter:
497
68d4211518c5 refactor table views to share more code and to avoid empty filter table in some case
sylvain.thenault@logilab.fr
parents: 469
diff changeset
  1038
                actions += self.form_filter(divid, displaycols, displayfilter,
5669
1340f14c38c9 [table] propagate paginate
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5668
diff changeset
  1039
                                            displayactions, paginate)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1040
        elif displayfilter:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1041
            actions += self.show_hide_actions(divid, True)
5668
7bd6a8a126b8 no more need for specific handling of table view's displayaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5632
diff changeset
  1042
        self.w(u'<div id="%s">' % divid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1043
        if displayactions:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1044
            actionsbycat = self._cw.vreg['actions'].possible_actions(req, self.cw_rset)
3228
7b05b2709439 [actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3129
diff changeset
  1045
            for action in actionsbycat.get('mainactions', ()):
7b05b2709439 [actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3129
diff changeset
  1046
                for action in action.actual_actions():
7b05b2709439 [actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3129
diff changeset
  1047
                    actions.append( (action.url(), req._(action.title),
7b05b2709439 [actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3129
diff changeset
  1048
                                     action.html_class(), None) )
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1049
        # render actions menu
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1050
        if actions:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1051
            self.render_actions(divid, actions)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1052
        # render table
5617
f0bc8f5ddee2 [tableview] support for json-paginated table if paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5529
diff changeset
  1053
        if paginate:
f0bc8f5ddee2 [tableview] support for json-paginated table if paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5529
diff changeset
  1054
            self.divid = divid # XXX iirk (see usage in page_navigation_url)
f0bc8f5ddee2 [tableview] support for json-paginated table if paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5529
diff changeset
  1055
            self.paginate(page_size=page_size, show_all_option=False)
7830
37d23a1d3547 [views/table] parametrize table view co-classes (closes #1947472)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7814
diff changeset
  1056
        table = self.table_widget_class(self)
2204
3472c5498478 use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2115
diff changeset
  1057
        for column in self.get_columns(computed_labels, displaycols, headers,
3472c5498478 use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2115
diff changeset
  1058
                                       subvid, cellvids, cellattrs, mainindex):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1059
            table.append_column(column)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1060
        table.render(self.w)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1061
        self.w(u'</div>\n')
7999
ea012d90825d [table view] fix regression in old table view leading to malformed html
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7992
diff changeset
  1062
        if self.initial_load:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1063
            self.w(u'</div>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1064
5617
f0bc8f5ddee2 [tableview] support for json-paginated table if paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5529
diff changeset
  1065
    def page_navigation_url(self, navcomp, path, params):
8042
27ab1649bd71 [old table view] drop duplicated method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8032
diff changeset
  1066
        """Build an url to the current view using the <navcomp> attributes
27ab1649bd71 [old table view] drop duplicated method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8032
diff changeset
  1067
27ab1649bd71 [old table view] drop duplicated method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8032
diff changeset
  1068
        :param navcomp: a NavigationComponent to call an url method on.
27ab1649bd71 [old table view] drop duplicated method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8032
diff changeset
  1069
        :param path:    expected to be json here ?
27ab1649bd71 [old table view] drop duplicated method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8032
diff changeset
  1070
        :param params: params to give to build_url method
27ab1649bd71 [old table view] drop duplicated method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8032
diff changeset
  1071
27ab1649bd71 [old table view] drop duplicated method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8032
diff changeset
  1072
        this is called by :class:`cubiweb.web.component.NavigationComponent`
27ab1649bd71 [old table view] drop duplicated method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8032
diff changeset
  1073
        """
5619
a2c9a55b5a9d [tableview] don't fail with AttributeError when paginated as main content view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5617
diff changeset
  1074
        if hasattr(self, 'divid'):
8042
27ab1649bd71 [old table view] drop duplicated method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8032
diff changeset
  1075
            # XXX this assert a single call
6249
1729f53b3e42 fix regretion introduced by changeset "pagination/ ajaxes fixes" (2f5ebeb7665d)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6240
diff changeset
  1076
            params['divid'] = self.divid
1729f53b3e42 fix regretion introduced by changeset "pagination/ ajaxes fixes" (2f5ebeb7665d)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6240
diff changeset
  1077
        params['vid'] = self.__regid__
1729f53b3e42 fix regretion introduced by changeset "pagination/ ajaxes fixes" (2f5ebeb7665d)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6240
diff changeset
  1078
        return navcomp.ajax_page_url(**params)
5617
f0bc8f5ddee2 [tableview] support for json-paginated table if paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5529
diff changeset
  1079
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1080
    def show_hide_actions(self, divid, currentlydisplayed=False):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1081
        showhide = u';'.join(toggle_action('%s%s' % (divid, what))[11:]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1082
                             for what in ('Form', 'Show', 'Hide', 'Actions'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1083
        showhide = 'javascript:' + showhide
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1084
        showlabel = self._cw._('show filter form')
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1085
        hidelabel = self._cw._('hide filter form')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1086
        if currentlydisplayed:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1087
            return [(showhide, showlabel, 'hidden', '%sShow' % divid),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1088
                    (showhide, hidelabel, None, '%sHide' % divid)]
1635
866563e2d0fc don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents: 1370
diff changeset
  1089
        return [(showhide, showlabel, None, '%sShow' % divid),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1090
                (showhide, hidelabel, 'hidden', '%sHide' % divid)]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1091
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1092
    def render_actions(self, divid, actions):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1093
        box = MenuWidget('', 'tableActionsBox', _class='', islist=False)
5467
57372dbfd114 [https] fix resource urls in https version of a site: should use the https version as well to avoid warnings from the nrowser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5444
diff changeset
  1094
        label = tags.img(src=self._cw.uiprops['PUCE_DOWN'],
3890
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3729 3842
diff changeset
  1095
                         alt=xml_escape(self._cw._('action(s) on this selection')))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1096
        menu = PopupBoxMenu(label, isitem=False, link_class='actionsBox',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1097
                            ident='%sActions' % divid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1098
        box.append(menu)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1099
        for url, label, klass, ident in actions:
7600
75d208ab8444 [facets] factorize table filter form / facets box generation, moving out filter form from the table view so it's usable from other views. Closes #1794009
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7415
diff changeset
  1100
            menu.append(component.Link(url, label, klass=klass, id=ident))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1101
        box.render(w=self.w)
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
  1102
        self.w(u'<div class="clear"></div>')
1635
866563e2d0fc don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents: 1370
diff changeset
  1103
2204
3472c5498478 use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2115
diff changeset
  1104
    def get_columns(self, computed_labels, displaycols, headers, subvid,
3472c5498478 use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2115
diff changeset
  1105
                    cellvids, cellattrs, mainindex):
8012
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
  1106
        """build columns description from various parameters
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
  1107
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
  1108
        : computed_labels: columns headers computed from rset to be used if there is no headers entry
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
  1109
        : displaycols: see :meth:`call`
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
  1110
        : headers: explicitly define columns headers
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
  1111
        : subvid: see :meth:`call`
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
  1112
        : cellvids: see :meth:`call`
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
  1113
        : cellattrs: see :meth:`call`
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
  1114
        : mainindex: see :meth:`call`
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
  1115
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
  1116
        return a list of columns description to be used by
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
  1117
               :class:`~cubicweb.web.htmlwidgets.TableWidget`
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
  1118
        """
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1119
        columns = []
3729
e4f20b74af51 remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3720
diff changeset
  1120
        eschema = self._cw.vreg.schema.eschema
2204
3472c5498478 use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2115
diff changeset
  1121
        for colindex, label in enumerate(computed_labels):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1122
            if colindex not in displaycols:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1123
                continue
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1124
            # compute column header
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1125
            if headers is not None:
7801
67f9677c1253 [table view] allow to set None in 'headers', meaning the label should be fetched from the result set as done by default (closes #1931533)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
  1126
                _label = headers[displaycols.index(colindex)]
67f9677c1253 [table view] allow to set None in 'headers', meaning the label should be fetched from the result set as done by default (closes #1931533)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
  1127
                if _label is not None:
67f9677c1253 [table view] allow to set None in 'headers', meaning the label should be fetched from the result set as done by default (closes #1931533)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
  1128
                    label = _label
5503
5b7eb0839da3 [table view] take care to None label
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
  1129
            if colindex == mainindex and label is not None:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1130
                label += ' (%s)' % self.cw_rset.rowcount
7830
37d23a1d3547 [views/table] parametrize table view co-classes (closes #1947472)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7814
diff changeset
  1131
            column = self.table_column_class(label, colindex)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1132
            coltype = self.cw_rset.description[0][colindex]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1133
            # compute column cell view (if coltype is None, it's a left outer
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1134
            # join, use the default non final subvid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1135
            if cellvids and colindex in cellvids:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1136
                column.append_renderer(cellvids[colindex], colindex)
3729
e4f20b74af51 remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3720
diff changeset
  1137
            elif coltype is not None and eschema(coltype).final:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1138
                column.append_renderer(self.finalview, colindex)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1139
            else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1140
                column.append_renderer(subvid or 'incontext', colindex)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1141
            if cellattrs and colindex in cellattrs:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1142
                for name, value in cellattrs[colindex].iteritems():
1138
22f634977c95 make pylint happy, fix some bugs on the way
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
  1143
                    column.add_attr(name, value)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1144
            # add column
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1145
            columns.append(column)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1146
        return columns
1635
866563e2d0fc don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents: 1370
diff changeset
  1147
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1148
1730
cec526a96535 fix 'render' method name conflict
sylvain.thenault@logilab.fr
parents: 1635
diff changeset
  1149
    def render_cell(self, cellvid, row, col, w):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1150
        self._cw.view('cell', self.cw_rset, row=row, col=col, cellvid=cellvid, w=w)
1635
866563e2d0fc don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents: 1370
diff changeset
  1151
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1152
    def get_rows(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1153
        return self.cw_rset
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1154
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1155
    @htmlescape
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1156
    @jsonize
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1157
    @limitsize(10)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1158
    def sortvalue(self, row, col):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1159
        # XXX it might be interesting to try to limit value's
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1160
        #     length as much as possible (e.g. by returning the 10
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1161
        #     first characters of a string)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1162
        val = self.cw_rset[row][col]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1163
        if val is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1164
            return u''
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1165
        etype = self.cw_rset.description[row][col]
6104
a57db3faa913 [tableview] take care, description may include None (try Any NULL)
Alexandre Richardson <alexandre.richardson@logilab.fr>
parents: 5997
diff changeset
  1166
        if etype is None:
a57db3faa913 [tableview] take care, description may include None (try Any NULL)
Alexandre Richardson <alexandre.richardson@logilab.fr>
parents: 5997
diff changeset
  1167
            return u''
3729
e4f20b74af51 remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3720
diff changeset
  1168
        if self._cw.vreg.schema.eschema(etype).final:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1169
            entity, rtype = self.cw_rset.related_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1170
            if entity is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1171
                return val # remove_html_tags() ?
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1172
            return entity.sortvalue(rtype)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1173
        entity = self.cw_rset.get_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1174
        return entity.sortvalue()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1175
843
5676811ef760 cleanup
sylvain.thenault@logilab.fr
parents: 762
diff changeset
  1176
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1177
class EditableTableView(TableView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3230
diff changeset
  1178
    __regid__ = 'editable-table'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1179
    finalview = 'editable-final'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1180
    title = _('editable-table')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1181
1635
866563e2d0fc don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents: 1370
diff changeset
  1182
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1183
class CellView(EntityView):
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
  1184
    __metaclass__ = class_deprecated
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
  1185
    __deprecation_warning__ = '[3.14] %(cls)s is deprecated'
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3230
diff changeset
  1186
    __regid__ = 'cell'
742
99115e029dca replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 692
diff changeset
  1187
    __select__ = nonempty_rset()
1635
866563e2d0fc don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents: 1370
diff changeset
  1188
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1189
    def cell_call(self, row, col, cellvid=None):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1190
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1191
        :param row, col: indexes locating the cell value in view's result set
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1192
        :param cellvid: cell view (defaults to 'outofcontext')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1193
        """
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1194
        etype, val = self.cw_rset.description[row][col], self.cw_rset[row][col]
7814
1ec9fe1dfba9 [tableview] fix view selection when value is None (closes #1936781)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
  1195
        if etype is None or not self._cw.vreg.schema.eschema(etype).final:
1ec9fe1dfba9 [tableview] fix view selection when value is None (closes #1936781)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
  1196
            if val is None:
1ec9fe1dfba9 [tableview] fix view selection when value is None (closes #1936781)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
  1197
                # This is usually caused by a left outer join and in that case,
1ec9fe1dfba9 [tableview] fix view selection when value is None (closes #1936781)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
  1198
                # regular views will most certainly fail if they don't have
1ec9fe1dfba9 [tableview] fix view selection when value is None (closes #1936781)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
  1199
                # a real eid
1ec9fe1dfba9 [tableview] fix view selection when value is None (closes #1936781)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
  1200
                # XXX if cellvid is e.g. reledit, we may wanna call it anyway
1ec9fe1dfba9 [tableview] fix view selection when value is None (closes #1936781)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
  1201
                self.w(u'&#160;')
1ec9fe1dfba9 [tableview] fix view selection when value is None (closes #1936781)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
  1202
            else:
1ec9fe1dfba9 [tableview] fix view selection when value is None (closes #1936781)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
  1203
                self.wview(cellvid or 'outofcontext', self.cw_rset, row=row, col=col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1204
        else:
7814
1ec9fe1dfba9 [tableview] fix view selection when value is None (closes #1936781)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
  1205
            # XXX why do we need a fallback view here?
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1206
            self.wview(cellvid or 'final', self.cw_rset, 'null', row=row, col=col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1207
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1208
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1209
class InitialTableView(TableView):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1210
    """same display as  table view but consider two rql queries :
1635
866563e2d0fc don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents: 1370
diff changeset
  1211
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1212
    * the default query (ie `rql` form parameter), which is only used to select
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1213
      this view and to build the filter form. This query should have the same
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1214
      structure as the actual without actual restriction (but link to
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1215
      restriction variables) and usually with a limit for efficiency (limit set
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1216
      to 2 is advised)
1635
866563e2d0fc don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents: 1370
diff changeset
  1217
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1218
    * the actual query (`actualrql` form parameter) whose results will be
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1219
      displayed with default restrictions set
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1220
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3230
diff changeset
  1221
    __regid__ = 'initialtable'
5632
1e7c662bd6f8 [tableview / facets] to work properly with facet, initial table should handle case where actualrql isn't specified
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5622
diff changeset
  1222
    __select__ = nonempty_rset()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1223
    # should not be displayed in possible view since it expects some specific
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1224
    # parameters
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1225
    title = None
1635
866563e2d0fc don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents: 1370
diff changeset
  1226
469
365826a58664 allow divid as argument
sylvain.thenault@logilab.fr
parents: 431
diff changeset
  1227
    def call(self, title=None, subvid=None, headers=None, divid=None,
6240
fd0cbb801007 cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6104
diff changeset
  1228
             paginate=False, displaycols=None, displayactions=None,
fd0cbb801007 cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6104
diff changeset
  1229
             mainindex=None):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1230
        """Dumps a table displaying a composite query"""
5632
1e7c662bd6f8 [tableview / facets] to work properly with facet, initial table should handle case where actualrql isn't specified
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5622
diff changeset
  1231
        try:
1e7c662bd6f8 [tableview / facets] to work properly with facet, initial table should handle case where actualrql isn't specified
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5622
diff changeset
  1232
            actrql = self._cw.form['actualrql']
1e7c662bd6f8 [tableview / facets] to work properly with facet, initial table should handle case where actualrql isn't specified
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5622
diff changeset
  1233
        except KeyError:
1e7c662bd6f8 [tableview / facets] to work properly with facet, initial table should handle case where actualrql isn't specified
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5622
diff changeset
  1234
            actrql = self.cw_rset.printable_rql()
1e7c662bd6f8 [tableview / facets] to work properly with facet, initial table should handle case where actualrql isn't specified
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5622
diff changeset
  1235
        else:
1e7c662bd6f8 [tableview / facets] to work properly with facet, initial table should handle case where actualrql isn't specified
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5622
diff changeset
  1236
            self._cw.ensure_ro_rql(actrql)
5239
471554b842d2 [schema view] the final touch. Things are getting nicely displayed, and code clean
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5234
diff changeset
  1237
        displaycols = self.displaycols(displaycols, headers)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1238
        if displayactions is None and 'displayactions' in self._cw.form:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1239
            displayactions = True
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1240
        if divid is None and 'divid' in self._cw.form:
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1241
            divid = self._cw.form['divid']
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1242
        self.w(u'<div class="section">')
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1243
        if not title and 'title' in self._cw.form:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1244
            # pop title so it's not displayed by the table view as well
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1245
            title = self._cw.form.pop('title')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1246
        if title:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1247
            self.w(u'<h2>%s</h2>\n' % title)
2226
f5216e540168 allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2206
diff changeset
  1248
        if mainindex is None:
f5216e540168 allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2206
diff changeset
  1249
            mainindex = self.main_var_index()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1250
        if mainindex is not None:
5669
1340f14c38c9 [table] propagate paginate
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5668
diff changeset
  1251
            actions = self.form_filter(divid, displaycols, displayactions,
6240
fd0cbb801007 cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6104
diff changeset
  1252
                                       displayfilter=True, paginate=paginate,
fd0cbb801007 cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6104
diff changeset
  1253
                                       hidden=True)
497
68d4211518c5 refactor table views to share more code and to avoid empty filter table in some case
sylvain.thenault@logilab.fr
parents: 469
diff changeset
  1254
        else:
68d4211518c5 refactor table views to share more code and to avoid empty filter table in some case
sylvain.thenault@logilab.fr
parents: 469
diff changeset
  1255
            actions = ()
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1256
        if not subvid and 'subvid' in self._cw.form:
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1257
            subvid = self._cw.form.pop('subvid')
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1258
        self._cw.view('table', self._cw.execute(actrql),
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1259
                      'noresult', w=self.w, displayfilter=False, subvid=subvid,
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1260
                      displayactions=displayactions, displaycols=displaycols,
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1261
                      actions=actions, headers=headers, divid=divid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1262
        self.w(u'</div>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1263
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1264
527
sylvain.thenault@logilab.fr
parents: 521
diff changeset
  1265
class EditableInitialTableTableView(InitialTableView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3230
diff changeset
  1266
    __regid__ = 'editable-initialtable'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1267
    finalview = 'editable-final'
5234
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1268
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1269
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1270
class EntityAttributesTableView(EntityView):
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1271
    """This table displays entity attributes in a table and allow to set a
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1272
    specific method to help building cell content for each attribute as well as
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1273
    column header.
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1274
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1275
    Table will render entity cell by using the appropriate build_COLNAME_cell
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1276
    methods if defined otherwise cell content will be entity.COLNAME.
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1277
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1278
    Table will render column header using the method header_for_COLNAME if
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1279
    defined otherwise COLNAME will be used.
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1280
    """
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
  1281
    __metaclass__ = class_deprecated
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
  1282
    __deprecation_warning__ = '[3.14] %(cls)s is deprecated'
5234
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1283
    __abstract__ = True
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1284
    columns = ()
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1285
    table_css = "listing"
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1286
    css_files = ()
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1287
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1288
    def call(self, columns=None):
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1289
        if self.css_files:
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1290
            self._cw.add_css(self.css_files)
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1291
        _ = self._cw._
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1292
        self.columns = columns or self.columns
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5545
diff changeset
  1293
        sample = self.cw_rset.get_entity(0, 0)
5234
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1294
        self.w(u'<table class="%s">' % self.table_css)
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5545
diff changeset
  1295
        self.table_header(sample)
5234
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1296
        self.w(u'<tbody>')
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1297
        for row in xrange(self.cw_rset.rowcount):
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1298
            self.cell_call(row=row, col=0)
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1299
        self.w(u'</tbody>')
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1300
        self.w(u'</table>')
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1301
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1302
    def cell_call(self, row, col):
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1303
        _ = self._cw._
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1304
        entity = self.cw_rset.get_entity(row, col)
7900
e9b79f5c3571 improve EntityAttributesTableView perfs by adding a call to complete()
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7883
diff changeset
  1305
        entity.complete()
5234
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1306
        infos = {}
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1307
        for col in self.columns:
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1308
            meth = getattr(self, 'build_%s_cell' % col, None)
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1309
            # find the build method or try to find matching attribute
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1310
            if meth:
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1311
                content = meth(entity)
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1312
            else:
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1313
                content = entity.printable_value(col)
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1314
            infos[col] = content
5727
29afb9e715bb [3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5679
diff changeset
  1315
        self.w(u"""<tr onmouseover="$(this).addClass('highlighted');"
29afb9e715bb [3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5679
diff changeset
  1316
            onmouseout="$(this).removeClass('highlighted')">""")
5234
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1317
        line = u''.join(u'<td>%%(%s)s</td>' % col for col in self.columns)
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1318
        self.w(line % infos)
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1319
        self.w(u'</tr>\n')
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1320
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5545
diff changeset
  1321
    def table_header(self, sample):
5234
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1322
        """builds the table's header"""
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1323
        self.w(u'<thead><tr>')
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1324
        for column in self.columns:
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1325
            meth = getattr(self, 'header_for_%s' % column, None)
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1326
            if meth:
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5545
diff changeset
  1327
                colname = meth(sample)
5234
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1328
            else:
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5545
diff changeset
  1329
                colname = self._cw._(column)
5234
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1330
            self.w(u'<th>%s</th>' % xml_escape(colname))
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1331
        self.w(u'</tr></thead>\n')
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1332