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