web/views/tableview.py
author Aurelien Campeas <aurelien.campeas@logilab.fr>
Wed, 13 Jun 2012 12:38:06 +0200
changeset 8464 895e34d9ae0d
parent 8425 b86bdc343c18
child 8535 268b6349baf3
permissions -rw-r--r--
[views/tables|css] show actions in small tabs instead of menu indirection (closes #2004109)
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):
8032
bcb87336c7d2 [doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8028
diff changeset
   177
        """We detect a bit heuristically if we are built for the first time.
bcb87336c7d2 [doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8028
diff changeset
   178
        or 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):
8464
895e34d9ae0d [views/tables|css] show actions in small tabs instead of menu indirection (closes #2004109)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8425
diff changeset
   293
        w(u'<div class="tableactions">')
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   294
        for action in actions:
8464
895e34d9ae0d [views/tables|css] show actions in small tabs instead of menu indirection (closes #2004109)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8425
diff changeset
   295
            w(u'<span>')
895e34d9ae0d [views/tables|css] show actions in small tabs instead of menu indirection (closes #2004109)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8425
diff changeset
   296
            action.render(w)
895e34d9ae0d [views/tables|css] show actions in small tabs instead of menu indirection (closes #2004109)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8425
diff changeset
   297
            w(u'</span>')
895e34d9ae0d [views/tables|css] show actions in small tabs instead of menu indirection (closes #2004109)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8425
diff changeset
   298
        w(u'</div>')
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   299
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   300
    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
   301
        divid = self.view.domid
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   302
        showhide = u';'.join(toggle_action('%s%s' % (divid, what))[11:]
8464
895e34d9ae0d [views/tables|css] show actions in small tabs instead of menu indirection (closes #2004109)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8425
diff changeset
   303
                             for what in ('Form', 'Actions'))
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   304
        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
   305
        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
   306
$(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
   307
  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
   308
    $('#%(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
   309
  } 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
   310
    $('#%(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
   311
  }
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
});''' % {'id': divid})
8464
895e34d9ae0d [views/tables|css] show actions in small tabs instead of menu indirection (closes #2004109)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8425
diff changeset
   313
        showlabel = self._cw._('toggle filter')
895e34d9ae0d [views/tables|css] show actions in small tabs instead of menu indirection (closes #2004109)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8425
diff changeset
   314
        return [component.Link(showhide, showlabel, id='%sToggle' % divid)]
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   315
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   316
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   317
class AbstractColumnRenderer(object):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   318
    """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
   319
8032
bcb87336c7d2 [doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8028
diff changeset
   320
    .. 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
   321
    .. 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
   322
    .. 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
   323
    .. 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
   324
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   325
    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
   326
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   327
    :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
   328
    :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
   329
    :attr: `trheader`, should the header be translated
8418
3f87aa655466 [docstrings] typos corrected
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8417
diff changeset
   330
    :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
   331
    :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
   332
    :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
   333
    :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
   334
    :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
   335
    :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
   336
            the cell is rendered
8418
3f87aa655466 [docstrings] typos corrected
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8417
diff changeset
   337
    """ #'# make emacs
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   338
    attributes = {}
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   339
    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
   340
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   341
    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
   342
                 escapeheader=True, sortable=True):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   343
        self.header = header
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   344
        self.trheader = trheader
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   345
        self.escapeheader = escapeheader
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   346
        self.addcount = addcount
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   347
        self.sortable = sortable
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   348
        self.view = None
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   349
        self._cw = None
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   350
        self.colid = None
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   351
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   352
    def __str__(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   353
        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
   354
                                        self.__class__.__name__,
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   355
                                        self.colid)
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 bind(self, view, colid):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   358
        """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
   359
        `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
   360
        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
   361
        """
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   362
        self.view = view
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   363
        self._cw = view._cw
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   364
        self.colid = colid
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   365
8065
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   366
    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
   367
        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
   368
        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
   369
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   370
    def default_header(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   371
        """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
   372
        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
   373
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   374
    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
   375
        """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
   376
        header = self.header
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   377
        if header is None:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   378
            header = self.default_header()
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   379
        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
   380
           header = self._cw._(header)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   381
        if self.addcount:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   382
            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
   383
        if header:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   384
            if self.escapeheader:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   385
                header = xml_escape(header)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   386
        else:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   387
            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
   388
        if self.sortable:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   389
            header = tags.span(
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   390
                header, escapecontent=False,
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   391
                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
   392
        w(header)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   393
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   394
    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
   395
        """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
   396
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   397
         :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
   398
         """
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   399
        raise NotImplementedError()
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   400
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   401
    def sortvalue(self, _rownum):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   402
        """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
   403
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   404
        :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
   405
        """
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   406
        return None
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   407
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
class TableMixIn(component.LayoutableMixIn):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   410
    """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
   411
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   412
    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
   413
    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
   414
    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
   415
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   416
    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
   417
    used by that layout.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   418
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   419
    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
   420
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   421
    .. automethod:: build_column_renderers
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   422
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   423
    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
   424
8032
bcb87336c7d2 [doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8028
diff changeset
   425
    .. 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
   426
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   427
    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
   428
    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
   429
    """
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   430
    __abstract__ = True
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   431
    # table layout to use
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   432
    layout_id = 'table_layout'
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   433
    # 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
   434
    has_headers = True
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   435
    # dictionary {colid : column renderer}
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   436
    column_renderers = {}
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   437
    # 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
   438
    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
   439
    # 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
   440
    handle_pagination = True
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   441
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   442
    def call(self, **kwargs):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   443
        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
   444
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   445
    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
   446
        """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
   447
        try:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   448
            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
   449
        except KeyError:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   450
            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
   451
        crenderer.bind(self, colid)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   452
        return crenderer
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   453
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   454
    # layout callbacks #########################################################
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   455
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   456
    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
   457
        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
   458
            '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
   459
            **kwargs)
7992
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
    @cachedproperty
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   462
    def domid(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   463
        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
   464
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   465
    @property
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   466
    def table_size(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   467
        """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
   468
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   469
        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
   470
        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
   471
        """
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   472
        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
   473
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   474
    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
   475
        """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
   476
        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
   477
8032
bcb87336c7d2 [doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8028
diff changeset
   478
        .. 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
   479
        """
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   480
        raise NotImplementedError()
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   481
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   482
    def table_actions(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   483
        """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
   484
        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
   485
        category.
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
        req = self._cw
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   488
        actions = []
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   489
        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
   490
        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
   491
            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
   492
                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
   493
                                              klass=action.html_class()) )
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   494
        return actions
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   495
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   496
    # interaction with navigation component ####################################
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   497
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   498
    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
   499
        params['divid'] = self.domid
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   500
        params['vid'] = self.__regid__
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   501
        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
   502
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   503
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   504
class RsetTableColRenderer(AbstractColumnRenderer):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   505
    """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
   506
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
   507
    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
   508
        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
   509
        self.cellvid = cellvid
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   510
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   511
    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
   512
        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
   513
        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
   514
    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
   515
        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
   516
                      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
   517
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   518
    # 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
   519
    # characters of a string)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   520
    def sortvalue(self, rownum):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   521
        colid = self.colid
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   522
        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
   523
        if val is None:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   524
            return u''
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   525
        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
   526
        if etype is None:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   527
            return u''
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   528
        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
   529
            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
   530
            if entity is None:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   531
                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
   532
            return entity.sortvalue(rtype)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   533
        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
   534
        return entity.sortvalue()
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   535
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   536
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   537
class RsetTableView(TableMixIn, AnyRsetView):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   538
    """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
   539
    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
   540
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   541
    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
   542
    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
   543
    :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
   544
    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
   545
    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
   546
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   547
    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
   548
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   549
    * `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
   550
      (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
   551
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   552
    * `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
   553
      entities. Default to 'incontext'.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   554
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   555
    * `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
   556
      displayed.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   557
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   558
    * `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
   559
      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
   560
      names.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   561
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   562
    * `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
   563
      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
   564
      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
   565
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   566
    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
   567
    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
   568
    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
   569
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   570
    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
   571
    renderer.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   572
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   573
    .. autoclass:: RsetTableColRenderer
8418
3f87aa655466 [docstrings] typos corrected
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8417
diff changeset
   574
    """    #'# make emacs happier
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   575
    __regid__ = 'table'
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   576
    # 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
   577
    __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
   578
        '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
   579
        '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
   580
        '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
   581
                                            | unreloadable_table())
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   582
    title = _('table')
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   583
    # additional configuration parameters
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   584
    finalvid = 'final'
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   585
    nonfinalvid = 'incontext'
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   586
    displaycols = None
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   587
    headers = None
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   588
    cellvids = None
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   589
    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
   590
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   591
    def linkable(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   592
        # 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
   593
        # 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
   594
        # 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
   595
        return self.__regid__ == 'table'
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   596
8417
24409e9c7c66 [views] enable paginate toggle on RsetTableView (closes #2200675)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8344
diff changeset
   597
    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
   598
             paginate=None, **kwargs):
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   599
        if self.headers:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   600
            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
   601
        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
   602
            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
   603
                self.headers = headers
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   604
            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
   605
                self.displaycols = displaycols
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   606
            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
   607
                self.cellvids = cellvids
8417
24409e9c7c66 [views] enable paginate toggle on RsetTableView (closes #2200675)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8344
diff changeset
   608
            if paginate is not None:
24409e9c7c66 [views] enable paginate toggle on RsetTableView (closes #2200675)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8344
diff changeset
   609
                self.paginable = paginate
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   610
        if kwargs:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   611
            # 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
   612
            # selectors
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   613
            if len(kwargs) > 1:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   614
                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
   615
            else:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   616
                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
   617
            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
   618
        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
   619
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   620
    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
   621
        """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
   622
        selected variables
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   623
        """
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   624
        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
   625
        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
   626
            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
   627
                return i
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   628
        return None
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   629
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   630
    # layout callbacks #########################################################
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   631
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   632
    @property
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   633
    def table_size(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   634
        """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
   635
        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
   636
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   637
    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
   638
        headers = self.headers
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   639
        # compute displayed columns
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   640
        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
   641
            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
   642
                displaycols = range(len(headers))
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   643
            else:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   644
                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
   645
                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
   646
        else:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   647
            displaycols = self.displaycols
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   648
        # compute table headers
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   649
        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
   650
        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
   651
        # compute build renderers
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   652
        cellvids = self.cellvids
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   653
        renderers = []
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   654
        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
   655
            addcount = False
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   656
            # compute column header
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   657
            title = None
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   658
            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
   659
                title = headers[colnum]
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   660
            if title is None:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   661
                title = computed_titles[colid]
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   662
            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
   663
                addcount = True
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   664
            # 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
   665
            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
   666
                cellvid = cellvids[colnum]
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   667
            else:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   668
                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
   669
                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
   670
                    cellvid = self.finalvid
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   671
                else:
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   672
                    cellvid = self.nonfinalvid
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   673
            # get renderer
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   674
            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
   675
                                            addcount=addcount, cellvid=cellvid)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   676
            renderers.append(renderer)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   677
        return renderers
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   678
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   679
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   680
class EntityTableColRenderer(AbstractColumnRenderer):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   681
    """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
   682
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   683
    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
   684
    given row number.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   685
8032
bcb87336c7d2 [doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8028
diff changeset
   686
    .. 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
   687
    .. 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
   688
    .. 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
   689
    """
8070
61fb207ad2d8 [tableview] fix __init__ logic of sortfunc/sortable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8066
diff changeset
   690
    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
   691
        if renderfunc is None:
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   692
            renderfunc = self.render_entity
8070
61fb207ad2d8 [tableview] fix __init__ logic of sortfunc/sortable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8066
diff changeset
   693
            # 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
   694
            # sortable using the default implementation.
61fb207ad2d8 [tableview] fix __init__ logic of sortfunc/sortable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8066
diff changeset
   695
            if sortable is None:
61fb207ad2d8 [tableview] fix __init__ logic of sortfunc/sortable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8066
diff changeset
   696
                sortable = True
61fb207ad2d8 [tableview] fix __init__ logic of sortfunc/sortable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8066
diff changeset
   697
        # 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
   698
        # 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
   699
        # support sorting.
61fb207ad2d8 [tableview] fix __init__ logic of sortfunc/sortable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8066
diff changeset
   700
        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
   701
            sortfunc = self.entity_sortvalue
61fb207ad2d8 [tableview] fix __init__ logic of sortfunc/sortable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8066
diff changeset
   702
        # 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
   703
        # 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
   704
        sortable = sortfunc is not None
61fb207ad2d8 [tableview] fix __init__ logic of sortfunc/sortable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8066
diff changeset
   705
        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
   706
        self.renderfunc = renderfunc
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   707
        self.sortfunc = sortfunc
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   708
8065
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   709
    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
   710
        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
   711
        # 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
   712
        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
   713
        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
   714
        try:
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   715
            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
   716
            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
   717
                                 ('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
   718
                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
   719
                    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
   720
                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
   721
            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
   722
        finally:
8a933961938e [tableview] deepcopy of colrenderer was actually broken with py < 2.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8060
diff changeset
   723
            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
   724
            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
   725
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   726
    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
   727
        entity = self.entity(rownum)
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   728
        if entity is None:
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   729
            w(self.empty_cell_content)
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   730
        else:
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   731
            self.renderfunc(w, entity)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   732
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   733
    def sortvalue(self, rownum):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   734
        entity = self.entity(rownum)
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   735
        if entity is None:
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   736
            return None
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   737
        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
   738
            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
   739
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   740
    def entity(self, rownum):
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   741
        """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
   742
        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
   743
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   744
    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
   745
        """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
   746
        initialization.
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   747
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   748
        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
   749
        and print its value.
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   750
        """
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   751
        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
   752
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   753
    def entity_sortvalue(self, entity):
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   754
        """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
   755
        specified at initialization.
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   756
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   757
        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
   758
        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
   759
        """
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   760
        return entity.sortvalue(self.colid)
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   761
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   762
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   763
class MainEntityColRenderer(EntityTableColRenderer):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   764
    """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
   765
    :class:`EntityTableView`.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   766
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   767
    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
   768
    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
   769
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   770
    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
   771
    column.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   772
    """
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
   773
    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
   774
        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
   775
        self.vid = vid
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   776
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   777
    def default_header(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   778
        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
   779
        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
   780
            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
   781
        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
   782
            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
   783
        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
   784
                          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
   785
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   786
    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
   787
        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
   788
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   789
    def entity_sortvalue(self, entity):
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   790
        return entity.sortvalue()
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   791
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   792
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   793
class RelatedEntityColRenderer(MainEntityColRenderer):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   794
    """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
   795
    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
   796
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   797
    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
   798
    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
   799
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   800
    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
   801
    """
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   802
    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
   803
        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
   804
        self.getrelated = getrelated
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   805
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   806
    def entity(self, rownum):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   807
        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
   808
        return self.getrelated(entity)
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   809
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   810
    def default_header(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   811
        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
   812
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   813
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   814
class RelationColRenderer(EntityTableColRenderer):
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   815
    """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
   816
    '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
   817
    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
   818
    using the `role` argument.
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   819
8088
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   820
    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
   821
    '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
   822
    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
   823
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   824
    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
   825
    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
   826
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   827
    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
   828
    properly considering role.
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   829
    """
8088
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   830
    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
   831
                 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
   832
        super(RelationColRenderer, self).__init__(**kwargs)
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   833
        self.role = role
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   834
        self.vid = vid
8088
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   835
        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
   836
            subvid = 'outofcontext'
8058
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   837
        self.subvid = subvid
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   838
        self.fallbackvid = fallbackvid
8088
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   839
        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
   840
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   841
    def render_entity(self, w, entity):
8088
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   842
        kwargs = {'w': w}
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   843
        if self.is_rtype_view:
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   844
            rset = None
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   845
            kwargs['entity'] = entity
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   846
            kwargs['rtype'] = self.colid
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   847
            kwargs['role'] = self.role
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   848
        else:
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   849
            rset = entity.related(self.colid, self.role)
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   850
        if self.subvid is not None:
8092
bc2a7c9fe266 [views/table] fix typo
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8089
diff changeset
   851
            kwargs['subvid'] = self.subvid
8088
145c0701bac6 [tableview] enhance RelationColRenderer. Closes #2093184
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8070
diff changeset
   852
        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
   853
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   854
    def default_header(self):
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   855
        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
   856
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   857
    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
   858
a536053b0588 [table view] some new table view enhancements
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8055
diff changeset
   859
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   860
class EntityTableView(TableMixIn, EntityView):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   861
    """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
   862
    :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
   863
    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
   864
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   865
    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
   866
    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
   867
    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
   868
    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
   869
    is selected).
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   870
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   871
    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
   872
    :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
   873
    :attr:`column_renderers` dictionary.
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   874
8032
bcb87336c7d2 [doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8028
diff changeset
   875
    .. 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
   876
    .. 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
   877
    .. 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
   878
    .. 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
   879
    """
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   880
    __abstract__ = True
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   881
    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
   882
    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
   883
8344
9eda40a9ec08 [table view] EntityTableView should accept **kwargs as RsetTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8157
diff changeset
   884
    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
   885
        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
   886
            self.columns = columns
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   887
        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
   888
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   889
    @property
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   890
    def table_size(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   891
        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
   892
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   893
    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
   894
        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
   895
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
   896
    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
   897
        """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
   898
        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
   899
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   900
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   901
class EmptyCellView(AnyRsetView):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   902
    __regid__ = 'empty-cell'
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   903
    __select__ = yes()
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   904
    def call(self, **kwargs):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   905
        self.w(u'&#160;')
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   906
    cell_call = call
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   907
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   908
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   909
################################################################################
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   910
# DEPRECATED tables ############################################################
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   911
################################################################################
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
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   914
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
   915
    """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
   916
    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
   917
5312
d2dbba898a96 [doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4618
diff changeset
   918
    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
   919
    """
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   920
    __metaclass__ = class_deprecated
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   921
    __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
   922
    __regid__ = 'table'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   923
    title = _('table')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   924
    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
   925
7830
37d23a1d3547 [views/table] parametrize table view co-classes (closes #1947472)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7814
diff changeset
   926
    table_widget_class = TableWidget
37d23a1d3547 [views/table] parametrize table view co-classes (closes #1947472)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7814
diff changeset
   927
    table_column_class = TableColumn
37d23a1d3547 [views/table] parametrize table view co-classes (closes #1947472)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7814
diff changeset
   928
7952
48330faf4cd7 [table] use explicit add_onload() to setup table sorting (closes #2013493)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7900
diff changeset
   929
    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
   930
        'textExtraction': JSString('cw.sortValueExtraction'),
7958
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7953
diff changeset
   931
        '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
   932
        }
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
   933
    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
   934
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
   935
    def form_filter(self, divid, displaycols, displayactions, displayfilter,
5669
1340f14c38c9 [table] propagate paginate
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5668
diff changeset
   936
                    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
   937
        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
   938
            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
   939
                '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
   940
        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
   941
            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
   942
        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
   943
                   '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
   944
                   '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
   945
                   '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
   946
        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
   947
        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
   948
                          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
   949
        return self.show_hide_actions(divid, not hidden)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   950
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   951
    def main_var_index(self):
8012
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
   952
        """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
   953
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
   954
        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
   955
        XXX explain the concept
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
   956
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
   957
        May return None if none is found.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   958
        """
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   959
        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
   960
        for i, etype in enumerate(self.cw_rset.description[0]):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   961
            try:
3689
deb13e88e037 follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3228
diff changeset
   962
                if not eschema(etype).final:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   963
                    return i
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   964
            except KeyError: # XXX possible?
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   965
                continue
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   966
        return None
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   967
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
   968
    def displaycols(self, displaycols, headers):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   969
        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
   970
            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
   971
                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
   972
            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
   973
                displaycols = range(len(headers))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   974
            else:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   975
                displaycols = range(len(self.cw_rset.syntax_tree().children[0].selection))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   976
        return displaycols
1635
866563e2d0fc don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents: 1370
diff changeset
   977
7952
48330faf4cd7 [table] use explicit add_onload() to setup table sorting (closes #2013493)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7900
diff changeset
   978
    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
   979
        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
   980
        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
   981
        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
   982
    $("#%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
   983
});''' % (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
   984
        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
   985
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   986
    @cachedproperty
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   987
    def initial_load(self):
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   988
        """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
   989
        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
   990
        """
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   991
        form = self._cw.form
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
   992
        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
   993
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   994
    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
   995
             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
   996
             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
   997
             paginate=False, page_size=None):
5312
d2dbba898a96 [doc/book] misc on views, docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4618
diff changeset
   998
        """Produces a table displaying a composite query
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   999
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1000
        :param title: title added before table
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1001
        :param subvid: cell view
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1002
        :param displayfilter: filter that selects rows to display
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1003
        :param headers: columns' titles
7883
cd98785b4a84 [views] fix docstring of tableview
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7830
diff changeset
  1004
        :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
  1005
        :param displayactions: if True, display action menu
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1006
        """
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1007
        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
  1008
        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
  1009
        self._setup_tablesorter(divid)
2226
f5216e540168 allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2206
diff changeset
  1010
        # 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
  1011
        # information from the rql syntax tree
f5216e540168 allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2206
diff changeset
  1012
        if mainindex is None:
f5216e540168 allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2206
diff changeset
  1013
            mainindex = self.main_var_index()
2206
009e2856afcb columns_labels is an AnyRsetView method...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2204
diff changeset
  1014
        computed_labels = self.columns_labels(mainindex)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1015
        if not subvid and 'subvid' in req.form:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1016
            subvid = req.form.pop('subvid')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1017
        actions = list(actions)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1018
        if mainindex is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1019
            displayfilter, displayactions = False, False
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1020
        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
  1021
            if displayfilter is None and req.form.get('displayfilter'):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1022
                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
  1023
            if displayactions is None and req.form.get('displayactions'):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1024
                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
  1025
        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
  1026
        if self.initial_load:
3009
3deb0fa95761 no comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3006
diff changeset
  1027
            self.w(u'<div class="section">')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1028
            if not title and 'title' in req.form:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1029
                title = req.form['title']
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1030
            if title:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1031
                self.w(u'<h2 class="tableTitle">%s</h2>\n' % title)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1032
            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
  1033
                actions += self.form_filter(divid, displaycols, displayfilter,
5669
1340f14c38c9 [table] propagate paginate
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5668
diff changeset
  1034
                                            displayactions, paginate)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1035
        elif displayfilter:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1036
            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
  1037
        self.w(u'<div id="%s">' % divid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1038
        if displayactions:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1039
            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
  1040
            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
  1041
                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
  1042
                    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
  1043
                                     action.html_class(), None) )
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1044
        # render actions menu
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1045
        if actions:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1046
            self.render_actions(divid, actions)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1047
        # render table
5617
f0bc8f5ddee2 [tableview] support for json-paginated table if paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5529
diff changeset
  1048
        if paginate:
f0bc8f5ddee2 [tableview] support for json-paginated table if paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5529
diff changeset
  1049
            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
  1050
            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
  1051
        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
  1052
        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
  1053
                                       subvid, cellvids, cellattrs, mainindex):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1054
            table.append_column(column)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1055
        table.render(self.w)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1056
        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
  1057
        if self.initial_load:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1058
            self.w(u'</div>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1059
5617
f0bc8f5ddee2 [tableview] support for json-paginated table if paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5529
diff changeset
  1060
    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
  1061
        """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
  1062
27ab1649bd71 [old table view] drop duplicated method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8032
diff changeset
  1063
        :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
  1064
        :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
  1065
        :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
  1066
27ab1649bd71 [old table view] drop duplicated method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8032
diff changeset
  1067
        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
  1068
        """
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
  1069
        if hasattr(self, 'divid'):
8042
27ab1649bd71 [old table view] drop duplicated method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8032
diff changeset
  1070
            # 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
  1071
            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
  1072
        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
  1073
        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
  1074
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1075
    def show_hide_actions(self, divid, currentlydisplayed=False):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1076
        showhide = u';'.join(toggle_action('%s%s' % (divid, what))[11:]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1077
                             for what in ('Form', 'Show', 'Hide', 'Actions'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1078
        showhide = 'javascript:' + showhide
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1079
        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
  1080
        hidelabel = self._cw._('hide filter form')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1081
        if currentlydisplayed:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1082
            return [(showhide, showlabel, 'hidden', '%sShow' % divid),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1083
                    (showhide, hidelabel, None, '%sHide' % divid)]
1635
866563e2d0fc don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents: 1370
diff changeset
  1084
        return [(showhide, showlabel, None, '%sShow' % divid),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1085
                (showhide, hidelabel, 'hidden', '%sHide' % divid)]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1086
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1087
    def render_actions(self, divid, actions):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1088
        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
  1089
        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
  1090
                         alt=xml_escape(self._cw._('action(s) on this selection')))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1091
        menu = PopupBoxMenu(label, isitem=False, link_class='actionsBox',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1092
                            ident='%sActions' % divid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1093
        box.append(menu)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1094
        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
  1095
            menu.append(component.Link(url, label, klass=klass, id=ident))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1096
        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
  1097
        self.w(u'<div class="clear"></div>')
1635
866563e2d0fc don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents: 1370
diff changeset
  1098
2204
3472c5498478 use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2115
diff changeset
  1099
    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
  1100
                    cellvids, cellattrs, mainindex):
8012
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
  1101
        """build columns description from various parameters
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
  1102
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
  1103
        : 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
  1104
        : displaycols: see :meth:`call`
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
  1105
        : headers: explicitly define columns headers
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
  1106
        : subvid: see :meth:`call`
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
  1107
        : cellvids: see :meth:`call`
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
  1108
        : cellattrs: see :meth:`call`
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
  1109
        : mainindex: see :meth:`call`
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
  1110
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
  1111
        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
  1112
               :class:`~cubicweb.web.htmlwidgets.TableWidget`
2080e476ece7 [deprecated] TableView: update some documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8009
diff changeset
  1113
        """
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1114
        columns = []
3729
e4f20b74af51 remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3720
diff changeset
  1115
        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
  1116
        for colindex, label in enumerate(computed_labels):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1117
            if colindex not in displaycols:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1118
                continue
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1119
            # compute column header
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1120
            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
  1121
                _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
  1122
                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
  1123
                    label = _label
5503
5b7eb0839da3 [table view] take care to None label
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
  1124
            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
  1125
                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
  1126
            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
  1127
            coltype = self.cw_rset.description[0][colindex]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1128
            # 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
  1129
            # join, use the default non final subvid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1130
            if cellvids and colindex in cellvids:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1131
                column.append_renderer(cellvids[colindex], colindex)
3729
e4f20b74af51 remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3720
diff changeset
  1132
            elif coltype is not None and eschema(coltype).final:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1133
                column.append_renderer(self.finalview, colindex)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1134
            else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1135
                column.append_renderer(subvid or 'incontext', colindex)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1136
            if cellattrs and colindex in cellattrs:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1137
                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
  1138
                    column.add_attr(name, value)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1139
            # add column
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1140
            columns.append(column)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1141
        return columns
1635
866563e2d0fc don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents: 1370
diff changeset
  1142
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1143
1730
cec526a96535 fix 'render' method name conflict
sylvain.thenault@logilab.fr
parents: 1635
diff changeset
  1144
    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
  1145
        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
  1146
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1147
    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
  1148
        return self.cw_rset
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1149
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1150
    @htmlescape
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1151
    @jsonize
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1152
    @limitsize(10)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1153
    def sortvalue(self, row, col):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1154
        # XXX it might be interesting to try to limit value's
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1155
        #     length as much as possible (e.g. by returning the 10
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1156
        #     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
  1157
        val = self.cw_rset[row][col]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1158
        if val is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1159
            return u''
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1160
        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
  1161
        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
  1162
            return u''
3729
e4f20b74af51 remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3720
diff changeset
  1163
        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
  1164
            entity, rtype = self.cw_rset.related_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1165
            if entity is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1166
                return val # remove_html_tags() ?
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1167
            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
  1168
        entity = self.cw_rset.get_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1169
        return entity.sortvalue()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1170
843
5676811ef760 cleanup
sylvain.thenault@logilab.fr
parents: 762
diff changeset
  1171
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1172
class EditableTableView(TableView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3230
diff changeset
  1173
    __regid__ = 'editable-table'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1174
    finalview = 'editable-final'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1175
    title = _('editable-table')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1176
1635
866563e2d0fc don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents: 1370
diff changeset
  1177
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1178
class CellView(EntityView):
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
  1179
    __metaclass__ = class_deprecated
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
  1180
    __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
  1181
    __regid__ = 'cell'
742
99115e029dca replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 692
diff changeset
  1182
    __select__ = nonempty_rset()
1635
866563e2d0fc don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents: 1370
diff changeset
  1183
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1184
    def cell_call(self, row, col, cellvid=None):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1185
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1186
        :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
  1187
        :param cellvid: cell view (defaults to 'outofcontext')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1188
        """
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1189
        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
  1190
        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
  1191
            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
  1192
                # 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
  1193
                # 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
  1194
                # 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
  1195
                # 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
  1196
                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
  1197
            else:
1ec9fe1dfba9 [tableview] fix view selection when value is None (closes #1936781)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
  1198
                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
  1199
        else:
7814
1ec9fe1dfba9 [tableview] fix view selection when value is None (closes #1936781)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7600
diff changeset
  1200
            # 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
  1201
            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
  1202
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1203
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1204
class InitialTableView(TableView):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1205
    """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
  1206
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1207
    * 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
  1208
      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
  1209
      structure as the actual without actual restriction (but link to
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1210
      restriction variables) and usually with a limit for efficiency (limit set
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1211
      to 2 is advised)
1635
866563e2d0fc don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents: 1370
diff changeset
  1212
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1213
    * the actual query (`actualrql` form parameter) whose results will be
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1214
      displayed with default restrictions set
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1215
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3230
diff changeset
  1216
    __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
  1217
    __select__ = nonempty_rset()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1218
    # should not be displayed in possible view since it expects some specific
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1219
    # parameters
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1220
    title = None
1635
866563e2d0fc don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents: 1370
diff changeset
  1221
469
365826a58664 allow divid as argument
sylvain.thenault@logilab.fr
parents: 431
diff changeset
  1222
    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
  1223
             paginate=False, displaycols=None, displayactions=None,
fd0cbb801007 cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6104
diff changeset
  1224
             mainindex=None):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1225
        """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
  1226
        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
  1227
            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
  1228
        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
  1229
            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
  1230
        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
  1231
            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
  1232
        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
  1233
        if displayactions is None and 'displayactions' in self._cw.form:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1234
            displayactions = True
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1235
        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
  1236
            divid = self._cw.form['divid']
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1237
        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
  1238
        if not title and 'title' in self._cw.form:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1239
            # 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
  1240
            title = self._cw.form.pop('title')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1241
        if title:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1242
            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
  1243
        if mainindex is None:
f5216e540168 allow to specify mainindex
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2206
diff changeset
  1244
            mainindex = self.main_var_index()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1245
        if mainindex is not None:
5669
1340f14c38c9 [table] propagate paginate
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5668
diff changeset
  1246
            actions = self.form_filter(divid, displaycols, displayactions,
6240
fd0cbb801007 cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6104
diff changeset
  1247
                                       displayfilter=True, paginate=paginate,
fd0cbb801007 cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6104
diff changeset
  1248
                                       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
  1249
        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
  1250
            actions = ()
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1251
        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
  1252
            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
  1253
        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
  1254
                      '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
  1255
                      displayactions=displayactions, displaycols=displaycols,
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
  1256
                      actions=actions, headers=headers, divid=divid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1257
        self.w(u'</div>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1258
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1259
527
sylvain.thenault@logilab.fr
parents: 521
diff changeset
  1260
class EditableInitialTableTableView(InitialTableView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3230
diff changeset
  1261
    __regid__ = 'editable-initialtable'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1262
    finalview = 'editable-final'
5234
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1263
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1264
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1265
class EntityAttributesTableView(EntityView):
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1266
    """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
  1267
    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
  1268
    column header.
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
    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
  1271
    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
  1272
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1273
    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
  1274
    defined otherwise COLNAME will be used.
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1275
    """
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
  1276
    __metaclass__ = class_deprecated
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7958
diff changeset
  1277
    __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
  1278
    __abstract__ = True
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1279
    columns = ()
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1280
    table_css = "listing"
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1281
    css_files = ()
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1282
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1283
    def call(self, columns=None):
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1284
        if self.css_files:
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1285
            self._cw.add_css(self.css_files)
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1286
        _ = self._cw._
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1287
        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
  1288
        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
  1289
        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
  1290
        self.table_header(sample)
5234
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1291
        self.w(u'<tbody>')
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1292
        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
  1293
            self.cell_call(row=row, col=0)
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1294
        self.w(u'</tbody>')
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1295
        self.w(u'</table>')
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1296
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1297
    def cell_call(self, row, col):
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1298
        _ = self._cw._
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1299
        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
  1300
        entity.complete()
5234
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1301
        infos = {}
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1302
        for col in self.columns:
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1303
            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
  1304
            # 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
  1305
            if meth:
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1306
                content = meth(entity)
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1307
            else:
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1308
                content = entity.printable_value(col)
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1309
            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
  1310
        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
  1311
            onmouseout="$(this).removeClass('highlighted')">""")
5234
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1312
        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
  1313
        self.w(line % infos)
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1314
        self.w(u'</tr>\n')
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1315
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5545
diff changeset
  1316
    def table_header(self, sample):
5234
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1317
        """builds the table's header"""
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1318
        self.w(u'<thead><tr>')
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1319
        for column in self.columns:
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1320
            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
  1321
            if meth:
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5545
diff changeset
  1322
                colname = meth(sample)
5234
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1323
            else:
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5545
diff changeset
  1324
                colname = self._cw._(column)
5234
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1325
            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
  1326
        self.w(u'</tr></thead>\n')
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4618
diff changeset
  1327