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