cubicweb/web/views/baseviews.py
author Denis Laxalde <denis.laxalde@logilab.fr>
Fri, 22 Mar 2019 17:42:36 +0100
changeset 12542 85194bd49119
parent 12503 b01dd0ef43aa
child 12567 26744ad37953
permissions -rw-r--r--
Drop more deprecated code This follows up on changeset a8c1ea390400, in which code deprecated using logilab.common.deprecation got dropped. Now we also drop code deprecated using stdlib's warn(<msg>, DeprecationWarning). Notice that, as a consequence of dropping old/new etypes aliases in cubicweb/schema.py, we drop the import ETYPE_NAME_MAP (no longer needed); but since other modules imported that name from cubicweb.schema, we need to update the import statement to use "cubicweb" directly.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8130
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: 5392
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: 5392
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: 5392
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: 5392
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: 5392
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: 5392
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: 5392
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: 5392
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: 5392
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: 5392
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: 5392
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: 5392
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: 5392
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: 5392
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: 5392
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    18
"""
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    19
HTML views
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    20
~~~~~~~~~~
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    21
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    22
Special views
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    23
`````````````
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    24
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    25
.. autoclass:: NullView
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    26
.. autoclass:: NoResultView
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    27
.. autoclass:: FinalView
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    28
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    29
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    30
Base entity views
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    31
`````````````````
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    32
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    33
.. autoclass:: InContextView
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    34
.. autoclass:: OutOfContextView
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    35
.. autoclass:: OneLineView
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    37
Those are used to display a link to an entity, whose label depends on the entity
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    38
having to be displayed in or out of context (of another entity): some entities
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    39
make sense in the context of another entity. For instance, the `Version` of a
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    40
`Project` in forge. So one may expect that 'incontext' will be called when
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    41
display a version from within the context of a project, while 'outofcontext"'
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    42
will be called in other cases. In our example, the 'incontext' view of the
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    43
version would be something like '0.1.2', while the 'outofcontext' view would
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    44
include the project name, e.g. 'baz 0.1.2' (since only a version number without
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    45
the associated project doesn't make sense if you don't know yet that you're
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    46
talking about the famous 'baz' project. |cubicweb| tries to make guess and call
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    47
'incontext'/'outofcontext' nicely. When it can't know, the 'oneline' view should
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    48
be used.
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    49
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    50
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    51
List entity views
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    52
`````````````````
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    53
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    54
.. autoclass:: ListView
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    55
.. autoclass:: SimpleListView
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    56
.. autoclass:: SameETypeListView
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    57
.. autoclass:: CSVView
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    58
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    59
Those list views can be given a 'subvid' arguments, telling the view to use of
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    60
each item in the list. When not specified, the value of the 'redirect_vid'
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    61
attribute of :class:`ListItemView` (for 'listview') or of
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    62
:class:`SimpleListView` will be used. This default to 'outofcontext' for 'list'
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    63
/ 'incontext' for 'simplelist'
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    64
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    65
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    66
Text entity views
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    67
~~~~~~~~~~~~~~~~~
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    68
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    69
Basic HTML view have some variants to be used when generating raw text, not HTML
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    70
(for notifications for instance). Also, as explained above, some of the HTML
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    71
views use those text views as a basis.
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    72
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    73
.. autoclass:: TextView
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    74
.. autoclass:: InContextTextView
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    75
.. autoclass:: OutOfContextView
5518
ceea458025b9 [web] unify list views call arguments: use subvid to specify the view to use for each item
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    76
"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    77
10666
7f6b5f023884 [py3k] replace '_ = unicode' in global scope (closes #7589459)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10609
diff changeset
    78
from cubicweb import _
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
10609
e2d8e81bfe68 [py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10590
diff changeset
    80
from six.moves import range
e2d8e81bfe68 [py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10590
diff changeset
    81
6883
1538542a88ed [cleanup]
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6740
diff changeset
    82
from logilab.mtconverter import TransformError, xml_escape
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8130
diff changeset
    83
from logilab.common.registry import yes
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
6455
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
    85
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: 8130
diff changeset
    86
from cubicweb.predicates import empty_rset, one_etype_rset, match_kwargs
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
    87
from cubicweb.schema import display_name
756
2c3981830408 update import
sylvain.thenault@logilab.fr
parents: 742
diff changeset
    88
from cubicweb.view import EntityView, AnyRsetView, View
7918
d59db6068731 remove 3.14 deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7913
diff changeset
    89
from cubicweb.uilib import cut
6455
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
    90
from cubicweb.web.views import calendar
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    91
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    92
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    93
class NullView(AnyRsetView):
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    94
    """:__regid__: *null*
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    95
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    96
    This view is the default view used when nothing needs to be rendered. It is
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    97
    always applicable and is usually used as fallback view when calling
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    98
    :meth:`_cw.view` to display nothing if the result set is empty.
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
    99
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   100
    __regid__ = 'null'
758
0c0dfd33a76d instantiate selectors wherever needed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 742
diff changeset
   101
    __select__ = yes()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
    def call(self, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
        pass
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
    cell_call = call
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
632
3a394a90b702 kill EmptyRsetVeiw
sylvain.thenault@logilab.fr
parents: 631
diff changeset
   107
class NoResultView(View):
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   108
    """:__regid__: *noresult*
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   109
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   110
    This view is the default view to be used when no result has been found
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   111
    (i.e. empty result set).
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   112
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   113
    It's usually used as fallback view when calling :meth:`_cw.view` to display
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   114
    "no results" if the result set is empty.
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   115
    """
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   116
    __regid__ = 'noresult'
742
99115e029dca replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 647
diff changeset
   117
    __select__ = empty_rset()
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   118
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   119
    def call(self, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
        self.w(u'<div class="searchMessage"><strong>%s</strong></div>\n'
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   121
               % self._cw._('No result matching query'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   122
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   124
class FinalView(AnyRsetView):
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   125
    """:__regid__: *final*
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   126
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   127
    Display the value of a result set cell with minimal transformations
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   128
    (i.e. you'll get a number for entities). It is applicable on any result set,
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   129
    though usually dedicated for cells containing an attribute's value.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   130
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   131
    __regid__ = 'final'
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   132
3165
0a50ebe53db7 [views] remove parameter displaytime from final view
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 2996
diff changeset
   133
    def cell_call(self, row, col, props=None, format='text/html'):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   134
        value = self.cw_rset.rows[row][col]
4315
2f957ad8e082 [views] FinalView should display an empty string if value is None
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4212
diff changeset
   135
        if value is None:
2f957ad8e082 [views] FinalView should display an empty string if value is None
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4212
diff changeset
   136
            self.w(u'')
2f957ad8e082 [views] FinalView should display an empty string if value is None
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4212
diff changeset
   137
            return
7913
d0c6a7993cec [web, formatting] move Interval data type display logic from final view to printable_value (closes #1984742)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7840
diff changeset
   138
        etype = self.cw_rset.description[row][col]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
        if etype == 'String':
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   140
            entity, rtype = self.cw_rset.related_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   141
            if entity is not None:
7913
d0c6a7993cec [web, formatting] move Interval data type display logic from final view to printable_value (closes #1984742)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7840
diff changeset
   142
                # call entity's printable_value which may have more information
d0c6a7993cec [web, formatting] move Interval data type display logic from final view to printable_value (closes #1984742)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7840
diff changeset
   143
                # about string format & all
573
9c8fd72ba6c1 try to get raw text values in rset csv view
sylvain.thenault@logilab.fr
parents: 570
diff changeset
   144
                self.w(entity.printable_value(rtype, value, format=format))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   145
                return
7918
d59db6068731 remove 3.14 deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7913
diff changeset
   146
        value = self._cw.printable_value(etype, value, props)
7913
d0c6a7993cec [web, formatting] move Interval data type display logic from final view to printable_value (closes #1984742)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7840
diff changeset
   147
        if etype in ('Time', 'Interval'):
7940
ac8052334e0d [printers] fix bug introduced by final view refactoring: &#160; shouldn't be escaped.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7918
diff changeset
   148
            self.w(value.replace(' ', '&#160;'))
ac8052334e0d [printers] fix bug introduced by final view refactoring: &#160; shouldn't be escaped.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7918
diff changeset
   149
        else:
ac8052334e0d [printers] fix bug introduced by final view refactoring: &#160; shouldn't be escaped.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7918
diff changeset
   150
            self.wdata(value)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   151
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   152
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   153
class InContextView(EntityView):
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   154
    """:__regid__: *incontext*
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   155
8995
a90a98800578 [view] typo in a docstring
David Douard <david.douard@logilab.fr>
parents: 8900
diff changeset
   156
    This view is used when the entity should be considered as displayed in its
8130
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   157
    context. By default it produces the result of ``entity.dc_title()`` wrapped in a
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   158
    link leading to the primary view of the entity.
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   159
    """
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   160
    __regid__ = 'incontext'
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   161
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   162
    def cell_call(self, row, col):
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   163
        entity = self.cw_rset.get_entity(row, col)
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   164
        desc = cut(entity.dc_description(), 50)
8130
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   165
        self.w(u'<a href="%s" title="%s">%s</a>' % (
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   166
            xml_escape(entity.absolute_url()), xml_escape(desc),
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   167
            xml_escape(entity.dc_title())))
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   168
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   169
class OutOfContextView(EntityView):
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   170
    """:__regid__: *outofcontext*
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   171
8418
3f87aa655466 [docstrings] typos corrected
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8416
diff changeset
   172
    This view is used when the entity should be considered as displayed out of
8425
b86bdc343c18 backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8190 8418
diff changeset
   173
    its context. By default it produces the result of ``entity.dc_long_title()``
b86bdc343c18 backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8190 8418
diff changeset
   174
    wrapped in a link leading to the primary view of the entity.
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   175
    """
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   176
    __regid__ = 'outofcontext'
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   177
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   178
    def cell_call(self, row, col):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   179
        entity = self.cw_rset.get_entity(row, col)
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   180
        desc = cut(entity.dc_description(), 50)
8130
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   181
        self.w(u'<a href="%s" title="%s">%s</a>' % (
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   182
            xml_escape(entity.absolute_url()), xml_escape(desc),
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   183
            xml_escape(entity.dc_long_title())))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   184
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   185
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   186
class OneLineView(EntityView):
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   187
    """:__regid__: *oneline*
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   188
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   189
    This view is used when we can't tell if the entity should be considered as
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   190
    displayed in or out of context. By default it produces the result of the
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   191
    `text` view in a link leading to the primary view of the entity.
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   192
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   193
    __regid__ = 'oneline'
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   194
    title = _('oneline')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   195
3682
9b62c5887639 add kwargs to some base views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3264
diff changeset
   196
    def cell_call(self, row, col, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   197
        """the one line view for an entity: linked text view
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   198
        """
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   199
        entity = self.cw_rset.get_entity(row, col)
8130
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   200
        desc = cut(entity.dc_description(), 50)
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   201
        title = cut(entity.dc_title(),
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   202
                    self._cw.property_value('navigation.short-line-size'))
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   203
        self.w(u'<a href="%s" title="%s">%s</a>' % (
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   204
                xml_escape(entity.absolute_url()), xml_escape(desc),
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   205
                xml_escape(title)))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   206
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   207
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   208
# text views ###################################################################
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   209
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   210
class TextView(EntityView):
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   211
    """:__regid__: *text*
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   212
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   213
    This is the simplest text view for an entity. By default it returns the
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   214
    result of the entity's `dc_title()` method, which is cut to fit the
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   215
    `navigation.short-line-size` property if necessary.
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   216
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   217
    __regid__ = 'text'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   218
    title = _('text')
532
ce3e94cbb074 specify content type for text views
sylvain.thenault@logilab.fr
parents: 531
diff changeset
   219
    content_type = 'text/plain'
647
49bb57a9606b some selectors update + drop EntityRelationView (only used by jpl)
sylvain.thenault@logilab.fr
parents: 632
diff changeset
   220
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   221
    def call(self, **kwargs):
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   222
        """The view is called for an entire result set, by default loop other
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   223
        rows of the result set and call the same view on the particular row.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   224
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   225
        Subclasses views that are applicable on None result sets will have to
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   226
        override this method.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   227
        """
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   228
        rset = self.cw_rset
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   229
        if rset is None:
10590
7629902e7554 [py3k] Fix raise with embedded traceback
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10411
diff changeset
   230
            raise NotImplementedError(self)
10609
e2d8e81bfe68 [py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10590
diff changeset
   231
        for i in range(len(rset)):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   232
            self.wview(self.__regid__, rset, row=i, **kwargs)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   233
            if len(rset) > 1:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   234
                self.w(u"\n")
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   235
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   236
    def cell_call(self, row, col=0, **kwargs):
3418
7b49fa7e942d [api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   237
        entity = self.cw_rset.get_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   238
        self.w(cut(entity.dc_title(),
3418
7b49fa7e942d [api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   239
                   self._cw.property_value('navigation.short-line-size')))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   240
137
7e45cf48c2f1 don't display additional owners in metadata, this is confusing
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 0
diff changeset
   241
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   242
class InContextTextView(TextView):
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   243
    """:__regid__: *textincontext*
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   244
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   245
    Similar to the `text` view, but called when an entity is considered in
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   246
    context (see description of incontext HTML view for more information on
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   247
    this). By default it displays what's returned by the `dc_title()` method of
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   248
    the entity.
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   249
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   250
    __regid__ = 'textincontext'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   251
    title = None # not listed as a possible view
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   252
    def cell_call(self, row, col):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   253
        entity = self.cw_rset.get_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   254
        self.w(entity.dc_title())
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   255
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   256
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   257
class OutOfContextTextView(InContextTextView):
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   258
    """:__regid__: *textoutofcontext*
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   259
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   260
    Similar to the `text` view, but called when an entity is considered out of
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   261
    context (see description of outofcontext HTML view for more information on
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   262
    this). By default it displays what's returned by the `dc_long_title()`
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   263
    method of the entity.
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   264
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   265
    __regid__ = 'textoutofcontext'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   266
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   267
    def cell_call(self, row, col):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   268
        entity = self.cw_rset.get_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   269
        self.w(entity.dc_long_title())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   270
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   271
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   272
# list views ##################################################################
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   273
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   274
class ListView(EntityView):
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   275
    """:__regid__: *list*
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   276
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   277
    This view displays a list of entities by creating a HTML list (`<ul>`) and
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   278
    call the view `listitem` for each entity of the result set. The 'list' view
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   279
    will generate HTML like:
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   280
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   281
    .. sourcecode:: html
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   282
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   283
      <ul class="section">
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   284
        <li>"result of 'subvid' view for a row</li>
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   285
        ...
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   286
      </ul>
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   287
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   288
    If you wish to use a different view for each entity, either subclass and
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   289
    change the :attr:`item_vid` class attribute or specify a `subvid` argument
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   290
    when calling this view.
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   291
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   292
    __regid__ = 'list'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   293
    title = _('list')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   294
    item_vid = 'listitem'
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   295
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   296
    def call(self, klass=None, title=None, subvid=None, listid=None, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   297
        """display a list of entities by calling their <item_vid> view
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   298
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   299
        :param listid: the DOM id to use for the root element
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   300
        """
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   301
        # XXX much of the behaviour here should probably be outside this view
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   302
        if subvid is None and 'subvid' in self._cw.form:
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   303
            subvid = self._cw.form.pop('subvid') # consume it
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   304
        if listid:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   305
            listid = u' id="%s"' % listid
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   306
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   307
            listid = u''
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   308
        if title:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   309
            self.w(u'<div%s class="%s"><h4>%s</h4>\n' % (listid, klass or 'section', title))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   310
            self.w(u'<ul>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   311
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   312
            self.w(u'<ul%s class="%s">\n' % (listid, klass or 'section'))
10609
e2d8e81bfe68 [py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10590
diff changeset
   313
        for i in range(self.cw_rset.rowcount):
10167
de62952550d9 [web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9257
diff changeset
   314
            self.cell_call(row=i, col=0, vid=subvid, klass=klass, **kwargs)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   315
        self.w(u'</ul>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   316
        if title:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   317
            self.w(u'</div>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   318
10167
de62952550d9 [web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9257
diff changeset
   319
    def cell_call(self, row, col=0, vid=None, klass=None, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   320
        self.w(u'<li>')
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   321
        self.wview(self.item_vid, self.cw_rset, row=row, col=col, vid=vid, **kwargs)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   322
        self.w(u'</li>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   323
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   324
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   325
class ListItemView(EntityView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   326
    __regid__ = 'listitem'
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   327
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   328
    @property
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   329
    def redirect_vid(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   330
        if self._cw.search_state[0] == 'normal':
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   331
            return 'outofcontext'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   332
        return 'outofcontext-search'
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   333
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   334
    def cell_call(self, row, col, vid=None, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   335
        if not vid:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   336
            vid = self.redirect_vid
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   337
        try:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   338
            self.wview(vid, self.cw_rset, row=row, col=col, **kwargs)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   339
        except NoSelectableObject:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   340
            if vid == self.redirect_vid:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   341
                raise
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   342
            self.wview(self.redirect_vid, self.cw_rset, row=row, col=col, **kwargs)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   343
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   344
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   345
class SimpleListView(ListItemView):
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   346
    """:__regid__: *simplelist*
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   347
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   348
    Similar to :class:~cubicweb.web.views.baseviews.ListView but using '<div>'
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   349
    instead of '<ul>'. It rely on '<div>' behaviour to separate items. HTML will
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   350
    look like
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   351
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   352
    .. sourcecode:: html
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   353
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   354
      <div class="section">"result of 'subvid' view for a row</div>
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   355
      ...
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   356
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   357
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   358
    It relies on base :class:`~cubicweb.view.View` class implementation of the
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   359
    :meth:`call` method to insert those <div>.
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   360
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   361
    __regid__ = 'simplelist'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   362
    redirect_vid = 'incontext'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   363
5518
ceea458025b9 [web] unify list views call arguments: use subvid to specify the view to use for each item
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   364
    def call(self, subvid=None, **kwargs):
ceea458025b9 [web] unify list views call arguments: use subvid to specify the view to use for each item
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   365
        """display a list of entities by calling their <item_vid> view
ceea458025b9 [web] unify list views call arguments: use subvid to specify the view to use for each item
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   366
ceea458025b9 [web] unify list views call arguments: use subvid to specify the view to use for each item
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   367
        :param listid: the DOM id to use for the root element
ceea458025b9 [web] unify list views call arguments: use subvid to specify the view to use for each item
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   368
        """
12542
85194bd49119 Drop more deprecated code
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12503
diff changeset
   369
        assert 'vid' not in kwargs
85194bd49119 Drop more deprecated code
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12503
diff changeset
   370
        kwargs['vid'] = subvid
5518
ceea458025b9 [web] unify list views call arguments: use subvid to specify the view to use for each item
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   371
        return super(SimpleListView, self).call(**kwargs)
ceea458025b9 [web] unify list views call arguments: use subvid to specify the view to use for each item
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   372
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   373
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   374
class SameETypeListView(EntityView):
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   375
    """:__regid__: *sameetypelist*
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   376
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   377
    This view displays a list of entities of the same type, in HTML section
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   378
    ('<div>') and call the view `sameetypelistitem` for each entity of the
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   379
    result set. It's designed to get a more adapted global list when displayed
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   380
    entities are all of the same type (for instance, display gallery if there
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   381
    are only images entities).
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   382
    """
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   383
    __regid__ = 'sameetypelist'
2645
91c71276f999 F [adapted list view] fix selector
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2472
diff changeset
   384
    __select__ = EntityView.__select__ & one_etype_rset()
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   385
    item_vid = 'sameetypelistitem'
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   386
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   387
    @property
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   388
    def title(self):
10669
155c29e0ed1c [py3k] use next builtin instead of next method
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10666
diff changeset
   389
        etype = next(iter(self.cw_rset.column_types(0)))
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   390
        return display_name(self._cw, etype, form='plural')
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   391
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   392
    def call(self, **kwargs):
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   393
        """display a list of entities by calling their <item_vid> view"""
5392
899d93e4dbe0 [view] better control wether same etype view should display title or not
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5222
diff changeset
   394
        showtitle = kwargs.pop('showtitle', not 'vtitle' in self._cw.form)
899d93e4dbe0 [view] better control wether same etype view should display title or not
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5222
diff changeset
   395
        if showtitle:
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   396
            self.w(u'<h1>%s</h1>' % self.title)
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   397
        super(SameETypeListView, self).call(**kwargs)
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   398
4507
57927ad07e63 no need for a specific vid argument here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4494
diff changeset
   399
    def cell_call(self, row, col=0, **kwargs):
57927ad07e63 no need for a specific vid argument here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4494
diff changeset
   400
        self.wview(self.item_vid, self.cw_rset, row=row, col=col, **kwargs)
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   401
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   402
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   403
class SameETypeListItemView(EntityView):
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   404
    __regid__ = 'sameetypelistitem'
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   405
4482
1f4f33535d9a we should not use inheritance there but proper view redirection, so if one adapt listitem view, he gets the same thing by default with the adapted list
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4335
diff changeset
   406
    def cell_call(self, row, col, **kwargs):
1f4f33535d9a we should not use inheritance there but proper view redirection, so if one adapt listitem view, he gets the same thing by default with the adapted list
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4335
diff changeset
   407
        self.wview('listitem', self.cw_rset, row=row, col=col, **kwargs)
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   408
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   409
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   410
class CSVView(SimpleListView):
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   411
    """:__regid__: *csv*
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   412
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   413
    This view displays each entity in a coma separated list. It is NOT related
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   414
    to the well-known text file format.
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   415
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   416
    __regid__ = 'csv'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   417
    redirect_vid = 'incontext'
10300
bfe33b5710d1 [web/views] Allow changing CSVView's separator (closes #5227442)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10167
diff changeset
   418
    separator = u', '
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   419
5518
ceea458025b9 [web] unify list views call arguments: use subvid to specify the view to use for each item
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   420
    def call(self, subvid=None, **kwargs):
9257
ce338133c92c remove cw 3.9 bw compat (bw compat other than the interface -> adapter changes)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8995
diff changeset
   421
        kwargs['vid'] = subvid
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   422
        rset = self.cw_rset
10609
e2d8e81bfe68 [py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10590
diff changeset
   423
        for i in range(len(rset)):
5518
ceea458025b9 [web] unify list views call arguments: use subvid to specify the view to use for each item
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   424
            self.cell_call(i, 0, **kwargs)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   425
            if i < rset.rowcount-1:
10300
bfe33b5710d1 [web/views] Allow changing CSVView's separator (closes #5227442)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10167
diff changeset
   426
                self.w(self.separator)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   427
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   428
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   429
# XXX to be documented views ###################################################
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   430
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   431
class MetaDataView(EntityView):
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   432
    """paragraph view of some metadata"""
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   433
    __regid__ = 'metadata'
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   434
    show_eid = True
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   435
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   436
    def cell_call(self, row, col):
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   437
        _ = self._cw._
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   438
        entity = self.cw_rset.get_entity(row, col)
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   439
        self.w(u'<div>')
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   440
        if self.show_eid:
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   441
            self.w(u'%s #%s - ' % (entity.dc_type(), entity.eid))
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   442
        if entity.modification_date != entity.creation_date:
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   443
            self.w(u'<span>%s</span> ' % _('latest update on'))
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   444
            self.w(u'<span class="value">%s</span>, '
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   445
                   % self._cw.format_date(entity.modification_date))
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   446
        # entities from external source may not have a creation date (eg ldap)
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   447
        if entity.creation_date:
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   448
            self.w(u'<span>%s</span> ' % _('created on'))
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   449
            self.w(u'<span class="value">%s</span>'
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   450
                   % self._cw.format_date(entity.creation_date))
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   451
        if entity.creator:
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   452
            if entity.creation_date:
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   453
                self.w(u' <span>%s</span> ' % _('by'))
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   454
            else:
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   455
                self.w(u' <span>%s</span> ' % _('created_by'))
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   456
            self.w(u'<span class="value">%s</span>' % entity.creator.name())
11759
7b7108eb8178 [entity] Stop linking to external site for external entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11057
diff changeset
   457
        source = entity.cw_source[0]
7b7108eb8178 [entity] Stop linking to external site for external entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11057
diff changeset
   458
        if source.name != 'system':
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   459
            self.w(u' (<span>%s</span>' % _('cw_source'))
11759
7b7108eb8178 [entity] Stop linking to external site for external entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11057
diff changeset
   460
            self.w(u' <span class="value">%s</span>)' % source.view('oneline'))
7b7108eb8178 [entity] Stop linking to external site for external entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11057
diff changeset
   461
            source_def = self._cw.source_defs()[source.name]
7b7108eb8178 [entity] Stop linking to external site for external entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11057
diff changeset
   462
            if source_def.get('use-cwuri-as-url'):
7b7108eb8178 [entity] Stop linking to external site for external entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11057
diff changeset
   463
                self.w(u' <a href="%s">%s</span>' % (entity.cwuri, self._cw._('view original')))
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   464
        self.w(u'</div>')
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   465
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   466
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   467
class TreeItemView(ListItemView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   468
    __regid__ = 'treeitem'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   469
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   470
    def cell_call(self, row, col):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   471
        self.wview('incontext', self.cw_rset, row=row, col=col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   472
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   473
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   474
class TextSearchResultView(EntityView):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   475
    """this view is used to display full-text search
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   476
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   477
    It tries to highlight part of data where the search word appears.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   478
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   479
    XXX: finish me (fixed line width, fixed number of lines, CSS, etc.)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   480
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   481
    __regid__ = 'tsearch'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   482
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   483
    def cell_call(self, row, col, **kwargs):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   484
        entity = self.cw_rset.complete_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   485
        self.w(entity.view('incontext'))
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   486
        searched = self.cw_rset.searched_text()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   487
        if searched is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   488
            return
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   489
        searched = searched.lower()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   490
        highlighted = '<b>%s</b>' % searched
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   491
        for attr in entity.e_schema.indexable_attributes():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   492
            try:
1680
39860636e184 use xml_escape
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents: 1653
diff changeset
   493
                value = xml_escape(entity.printable_value(attr, format='text/plain').lower())
8695
358d8bed9626 [toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8425
diff changeset
   494
            except TransformError as ex:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   495
                continue
7815
2a164a9cf81c [exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7310
diff changeset
   496
            except Exception:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   497
                continue
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   498
            if searched in value:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   499
                contexts = []
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   500
                for ctx in value.split(searched):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   501
                    if len(ctx) > 30:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   502
                        contexts.append(u'...' + ctx[-30:])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   503
                    else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   504
                        contexts.append(ctx)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   505
                value = u'\n' + highlighted.join(contexts)
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   506
                self.w(value.replace('\n', '<br/>'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   507
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   508
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   509
class TooltipView(EntityView):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   510
    """A entity view used in a tooltip"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   511
    __regid__ = 'tooltip'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   512
    def cell_call(self, row, col):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   513
        self.wview('oneline', self.cw_rset, row=row, col=col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   514
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   515
6455
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   516
class GroupByView(EntityView):
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   517
    """grouped view of a result set. The `group_key` method return the group
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   518
    key of an entities (a string or tuple of string).
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   519
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   520
    For each group, display a link to entities of this group by generating url
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   521
    like <basepath>/<key> or <basepath>/<key item 1>/<key item 2>.
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   522
    """
7835
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7815
diff changeset
   523
    __abstract__ = True
6455
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   524
    __select__ = EntityView.__select__ & match_kwargs('basepath')
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   525
    entity_attribute = None
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   526
    reversed = False
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   527
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   528
    def index_url(self, basepath, key, **kwargs):
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   529
        if isinstance(key, (list, tuple)):
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   530
            key = '/'.join(key)
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   531
        return self._cw.build_url('%s/%s' % (basepath, key),
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   532
                                  **kwargs)
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   533
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   534
    def index_link(self, basepath, key, items):
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   535
        url = self.index_url(basepath, key)
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   536
        if isinstance(key, (list, tuple)):
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   537
            key = ' '.join(key)
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   538
        return tags.a(key, href=url)
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   539
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   540
    def group_key(self, entity, **kwargs):
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   541
        value = getattr(entity, self.entity_attribute)
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   542
        if callable(value):
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   543
            value = value()
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   544
        return value
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   545
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   546
    def call(self, basepath, maxentries=None, **kwargs):
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   547
        index = {}
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   548
        for entity in self.cw_rset.entities():
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   549
            index.setdefault(self.group_key(entity, **kwargs), []).append(entity)
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   550
        displayed = sorted(index)
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   551
        if self.reversed:
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   552
            displayed = reversed(displayed)
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   553
        if maxentries is None:
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   554
            needmore = False
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   555
        else:
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   556
            needmore = len(index) > maxentries
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   557
            displayed = tuple(displayed)[:maxentries]
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   558
        w = self.w
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   559
        w(u'<ul class="boxListing">')
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   560
        for key in displayed:
8745
00c5ea2a064a [web] don't link to None in author box (when author has been deleted) (closes #2409855)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8695
diff changeset
   561
            if key:
00c5ea2a064a [web] don't link to None in author box (when author has been deleted) (closes #2409855)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8695
diff changeset
   562
                w(u'<li>%s</li>\n' %
00c5ea2a064a [web] don't link to None in author box (when author has been deleted) (closes #2409855)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8695
diff changeset
   563
                  self.index_link(basepath, key, index[key]))
6455
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   564
        if needmore:
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   565
            url = self._cw.build_url('view', vid=self.__regid__,
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   566
                                     rql=self.cw_rset.printable_rql())
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   567
            w( u'<li>%s</li>\n' % tags.a(u'[%s]' % self._cw._('see more'),
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   568
                                         href=url))
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   569
        w(u'</ul>\n')
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   570
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   571
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   572
class ArchiveView(GroupByView):
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   573
    """archive view of a result set. Links to months are built using a basepath
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   574
    parameters, eg using url like <basepath>/<year>/<month>
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   575
    """
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   576
    __regid__ = 'cw.archive.by_date'
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   577
    entity_attribute = 'creation_date'
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   578
    reversed = True
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   579
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   580
    def group_key(self, entity, **kwargs):
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   581
        value = super(ArchiveView, self).group_key(entity, **kwargs)
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   582
        return '%04d' % value.year, '%02d' % value.month
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   583
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   584
    def index_link(self, basepath, key, items):
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   585
        """represent a single month entry"""
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   586
        year, month = key
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   587
        label = u'%s %s [%s]' % (self._cw._(calendar.MONTHNAMES[int(month)-1]),
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   588
                                 year, len(items))
8900
010a59e12d89 use cw_etype instead of __regid__
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8745
diff changeset
   589
        etypes = set(entity.cw_etype for entity in items)
6455
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   590
        vtitle = '%s %s' % (', '.join(display_name(self._cw, etype, 'plural')
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   591
                                      for etype in etypes),
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   592
                            label)
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   593
        title = self._cw._('archive for %(month)s/%(year)s') % {
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   594
            'month': month, 'year': year}
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   595
        url = self.index_url(basepath, key, vtitle=vtitle)
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   596
        return tags.a(label, href=url, title=title)
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   597
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   598
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   599
class AuthorView(GroupByView):
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   600
    """author view of a result set. Links to month are built using a basepath
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   601
    parameters, eg using url like <basepath>/<author>
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   602
    """
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   603
    __regid__ = 'cw.archive.by_author'
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   604
    entity_attribute = 'creator'
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   605
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   606
    def group_key(self, entity, **kwargs):
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   607
        value = super(AuthorView, self).group_key(entity, **kwargs)
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   608
        if value:
8416
e7f06e562a27 [ui] display author name in box instead of login (closes #1529147)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 7940
diff changeset
   609
            return (value.name(), value.login)
e7f06e562a27 [ui] display author name in box instead of login (closes #1529147)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 7940
diff changeset
   610
        return (None, None)
6455
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   611
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   612
    def index_link(self, basepath, key, items):
8745
00c5ea2a064a [web] don't link to None in author box (when author has been deleted) (closes #2409855)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8695
diff changeset
   613
        if key[0] is None:
00c5ea2a064a [web] don't link to None in author box (when author has been deleted) (closes #2409855)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8695
diff changeset
   614
            return
8416
e7f06e562a27 [ui] display author name in box instead of login (closes #1529147)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 7940
diff changeset
   615
        label = u'%s [%s]' % (key[0], len(items))
8900
010a59e12d89 use cw_etype instead of __regid__
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8745
diff changeset
   616
        etypes = set(entity.cw_etype for entity in items)
6455
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   617
        vtitle = self._cw._('%(etype)s by %(author)s') % {
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   618
            'etype': ', '.join(display_name(self._cw, etype, 'plural')
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   619
                               for etype in etypes),
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   620
            'author': label}
8416
e7f06e562a27 [ui] display author name in box instead of login (closes #1529147)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 7940
diff changeset
   621
        url = self.index_url(basepath, key[1], vtitle=vtitle)
e7f06e562a27 [ui] display author name in box instead of login (closes #1529147)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 7940
diff changeset
   622
        title = self._cw._('archive for %(author)s') % {'author': key[0]}
6455
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   623
        return tags.a(label, href=url, title=title)