cubicweb/web/views/baseviews.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 30 Sep 2016 18:25:08 +0200
changeset 11767 432f87a63057
parent 11759 7b7108eb8178
child 12503 b01dd0ef43aa
permissions -rw-r--r--
flake8 and all * update some copyright * drop most __docformat__ declaration * fix some flake8 warnings / errors
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
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
    80
from warnings import warn
3235
bad0ff9b0c13 fix when Interval is coming from date substraction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2996
diff changeset
    81
10609
e2d8e81bfe68 [py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10590
diff changeset
    82
from six.moves import range
e2d8e81bfe68 [py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10590
diff changeset
    83
6883
1538542a88ed [cleanup]
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6740
diff changeset
    84
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
    85
from logilab.common.registry import yes
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    86
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
    87
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
    88
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
    89
from cubicweb.schema import display_name
756
2c3981830408 update import
sylvain.thenault@logilab.fr
parents: 742
diff changeset
    90
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
    91
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
    92
from cubicweb.web.views import calendar
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    93
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    95
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
    96
    """:__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
    97
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
    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
    99
    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
   100
    :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
   101
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   102
    __regid__ = 'null'
758
0c0dfd33a76d instantiate selectors wherever needed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 742
diff changeset
   103
    __select__ = yes()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
    def call(self, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
        pass
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
    cell_call = call
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
632
3a394a90b702 kill EmptyRsetVeiw
sylvain.thenault@logilab.fr
parents: 631
diff changeset
   109
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
   110
    """:__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
   111
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
    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
   113
    (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
   114
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
    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
   116
    "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
   117
    """
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
   118
    __regid__ = 'noresult'
742
99115e029dca replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 647
diff changeset
   119
    __select__ = empty_rset()
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   120
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
    def call(self, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   122
        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
   123
               % self._cw._('No result matching query'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   124
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   126
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
   127
    """:__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
   128
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
    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
   130
    (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
   131
    though usually dedicated for cells containing an attribute's value.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   132
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   133
    __regid__ = 'final'
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   134
3165
0a50ebe53db7 [views] remove parameter displaytime from final view
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 2996
diff changeset
   135
    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
   136
        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
   137
        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
   138
            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
   139
            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
   140
        etype = self.cw_rset.description[row][col]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   141
        if etype == 'String':
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   142
            entity, rtype = self.cw_rset.related_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   143
            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
   144
                # 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
   145
                # about string format & all
573
9c8fd72ba6c1 try to get raw text values in rset csv view
sylvain.thenault@logilab.fr
parents: 570
diff changeset
   146
                self.w(entity.printable_value(rtype, value, format=format))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   147
                return
7918
d59db6068731 remove 3.14 deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7913
diff changeset
   148
        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
   149
        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
   150
            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
   151
        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
   152
            self.wdata(value)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
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
   155
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
   156
    """:__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
   157
8995
a90a98800578 [view] typo in a docstring
David Douard <david.douard@logilab.fr>
parents: 8900
diff changeset
   158
    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
   159
    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
   160
    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
   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
    __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
   163
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
    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
   165
        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
   166
        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
   167
        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
   168
            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
   169
            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
   170
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
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
   172
    """:__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
   173
8418
3f87aa655466 [docstrings] typos corrected
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 8416
diff changeset
   174
    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
   175
    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
   176
    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
   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
    __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
   179
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
    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
   181
        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
   182
        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
   183
        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
   184
            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
   185
            xml_escape(entity.dc_long_title())))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   186
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   187
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   188
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
   189
    """:__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
   190
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
    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
   192
    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
   193
    `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
   194
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   195
    __regid__ = 'oneline'
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   196
    title = _('oneline')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   197
3682
9b62c5887639 add kwargs to some base views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3264
diff changeset
   198
    def cell_call(self, row, col, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   199
        """the one line view for an entity: linked text view
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   200
        """
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   201
        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
   202
        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
   203
        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
   204
                    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
   205
        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
   206
                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
   207
                xml_escape(title)))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   208
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   209
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
   210
# 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
   211
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   212
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
   213
    """:__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
   214
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
    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
   216
    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
   217
    `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
   218
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   219
    __regid__ = 'text'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   220
    title = _('text')
532
ce3e94cbb074 specify content type for text views
sylvain.thenault@logilab.fr
parents: 531
diff changeset
   221
    content_type = 'text/plain'
647
49bb57a9606b some selectors update + drop EntityRelationView (only used by jpl)
sylvain.thenault@logilab.fr
parents: 632
diff changeset
   222
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   223
    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
   224
        """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
   225
        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
   226
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
   227
        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
   228
        override this method.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   229
        """
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   230
        rset = self.cw_rset
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   231
        if rset is None:
10590
7629902e7554 [py3k] Fix raise with embedded traceback
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10411
diff changeset
   232
            raise NotImplementedError(self)
10609
e2d8e81bfe68 [py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10590
diff changeset
   233
        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
   234
            self.wview(self.__regid__, rset, row=i, **kwargs)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   235
            if len(rset) > 1:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   236
                self.w(u"\n")
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   237
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   238
    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
   239
        entity = self.cw_rset.get_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   240
        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
   241
                   self._cw.property_value('navigation.short-line-size')))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   242
137
7e45cf48c2f1 don't display additional owners in metadata, this is confusing
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 0
diff changeset
   243
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
   244
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
   245
    """:__regid__: *textincontext*
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   246
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
   247
    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
   248
    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
   249
    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
   250
    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
   251
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   252
    __regid__ = 'textincontext'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   253
    title = None # not listed as a possible view
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   254
    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
   255
        entity = self.cw_rset.get_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   256
        self.w(entity.dc_title())
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   257
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   258
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   259
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
   260
    """:__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
   261
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
    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
   263
    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
   264
    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
   265
    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
   266
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   267
    __regid__ = 'textoutofcontext'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   268
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   269
    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
   270
        entity = self.cw_rset.get_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   271
        self.w(entity.dc_long_title())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   272
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   273
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   274
# list views ##################################################################
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   275
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   276
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
   277
    """:__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
   278
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
    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
   280
    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
   281
    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
   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
    .. 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
   284
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
      <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
   286
        <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
   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
      </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
   289
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
    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
   291
    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
   292
    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
   293
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   294
    __regid__ = 'list'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   295
    title = _('list')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   296
    item_vid = 'listitem'
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   297
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   298
    def call(self, klass=None, title=None, subvid=None, listid=None, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   299
        """display a list of entities by calling their <item_vid> view
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   300
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   301
        :param listid: the DOM id to use for the root element
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   302
        """
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   303
        # 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
   304
        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
   305
            subvid = self._cw.form.pop('subvid') # consume it
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   306
        if listid:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   307
            listid = u' id="%s"' % listid
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   308
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   309
            listid = u''
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   310
        if title:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   311
            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
   312
            self.w(u'<ul>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   313
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   314
            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
   315
        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
   316
            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
   317
        self.w(u'</ul>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   318
        if title:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   319
            self.w(u'</div>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   320
10167
de62952550d9 [web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9257
diff changeset
   321
    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
   322
        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
   323
        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
   324
        self.w(u'</li>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   325
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   326
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   327
class ListItemView(EntityView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   328
    __regid__ = 'listitem'
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   329
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   330
    @property
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   331
    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
   332
        if self._cw.search_state[0] == 'normal':
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   333
            return 'outofcontext'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   334
        return 'outofcontext-search'
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   335
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   336
    def cell_call(self, row, col, vid=None, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   337
        if not vid:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   338
            vid = self.redirect_vid
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   339
        try:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   340
            self.wview(vid, self.cw_rset, row=row, col=col, **kwargs)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   341
        except NoSelectableObject:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   342
            if vid == self.redirect_vid:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   343
                raise
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   344
            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
   345
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   346
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   347
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
   348
    """:__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
   349
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
    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
   351
    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
   352
    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
   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
    .. 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
   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
      <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
   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
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
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
    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
   361
    :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
   362
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   363
    __regid__ = 'simplelist'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   364
    redirect_vid = 'incontext'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   365
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
   366
    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
   367
        """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
   368
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
   369
        :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
   370
        """
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
        if subvid is None and 'vid' in 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
            warn("should give a 'subvid' argument instead of 'vid'",
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
   373
                 DeprecationWarning, stacklevel=2)
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
   374
        else:
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
   375
            kwargs['vid'] = subvid
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
   376
        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
   377
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   378
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   379
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
   380
    """:__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
   381
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
   382
    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
   383
    ('<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
   384
    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
   385
    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
   386
    are only images entities).
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   387
    """
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   388
    __regid__ = 'sameetypelist'
2645
91c71276f999 F [adapted list view] fix selector
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2472
diff changeset
   389
    __select__ = EntityView.__select__ & one_etype_rset()
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   390
    item_vid = 'sameetypelistitem'
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
    @property
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   393
    def title(self):
10669
155c29e0ed1c [py3k] use next builtin instead of next method
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10666
diff changeset
   394
        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
   395
        return display_name(self._cw, etype, form='plural')
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   396
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   397
    def call(self, **kwargs):
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   398
        """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
   399
        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
   400
        if showtitle:
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   401
            self.w(u'<h1>%s</h1>' % self.title)
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   402
        super(SameETypeListView, self).call(**kwargs)
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   403
4507
57927ad07e63 no need for a specific vid argument here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4494
diff changeset
   404
    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
   405
        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
   406
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   407
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   408
class SameETypeListItemView(EntityView):
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   409
    __regid__ = 'sameetypelistitem'
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   410
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
   411
    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
   412
        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
   413
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   414
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   415
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
   416
    """:__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
   417
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
   418
    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
   419
    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
   420
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   421
    __regid__ = 'csv'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   422
    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
   423
    separator = u', '
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   424
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
   425
    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
   426
        kwargs['vid'] = subvid
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   427
        rset = self.cw_rset
10609
e2d8e81bfe68 [py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10590
diff changeset
   428
        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
   429
            self.cell_call(i, 0, **kwargs)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   430
            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
   431
                self.w(self.separator)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   432
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   433
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
   434
# 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
   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
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
   437
    """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
   438
    __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
   439
    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
   440
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
    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
   442
        _ = 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
   443
        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
   444
        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
   445
        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
   446
            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
   447
        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
   448
            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
   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.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
   451
        # 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
   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> ' % _('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
   454
            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
   455
                   % 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
   456
        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
   457
            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
   458
                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
   459
            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
   460
                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
   461
            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
   462
        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
   463
        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
   464
            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
   465
            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
   466
            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
   467
            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
   468
                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
   469
        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
   470
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
   471
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   472
class TreeItemView(ListItemView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   473
    __regid__ = 'treeitem'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   474
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   475
    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
   476
        self.wview('incontext', self.cw_rset, row=row, col=col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   477
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
   478
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   479
class TextSearchResultView(EntityView):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   480
    """this view is used to display full-text search
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   481
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   482
    It tries to highlight part of data where the search word appears.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   483
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   484
    XXX: finish me (fixed line width, fixed number of lines, CSS, etc.)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   485
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   486
    __regid__ = 'tsearch'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   487
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   488
    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
   489
        entity = self.cw_rset.complete_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   490
        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
   491
        searched = self.cw_rset.searched_text()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   492
        if searched is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   493
            return
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   494
        searched = searched.lower()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   495
        highlighted = '<b>%s</b>' % searched
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   496
        for attr in entity.e_schema.indexable_attributes():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   497
            try:
1680
39860636e184 use xml_escape
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents: 1653
diff changeset
   498
                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
   499
            except TransformError as ex:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   500
                continue
7815
2a164a9cf81c [exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7310
diff changeset
   501
            except Exception:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   502
                continue
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   503
            if searched in value:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   504
                contexts = []
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   505
                for ctx in value.split(searched):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   506
                    if len(ctx) > 30:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   507
                        contexts.append(u'...' + ctx[-30:])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   508
                    else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   509
                        contexts.append(ctx)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   510
                value = u'\n' + highlighted.join(contexts)
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   511
                self.w(value.replace('\n', '<br/>'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   512
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   513
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   514
class TooltipView(EntityView):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   515
    """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
   516
    __regid__ = 'tooltip'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   517
    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
   518
        self.wview('oneline', self.cw_rset, row=row, col=col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   519
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   520
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
   521
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
   522
    """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
   523
    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
   524
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
    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
   526
    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
   527
    """
7835
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7815
diff changeset
   528
    __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
   529
    __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
   530
    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
   531
    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
   532
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
    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
   534
        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
   535
            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
   536
        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
   537
                                  **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
   538
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
    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
   540
        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
   541
        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
   542
            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
   543
        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
   544
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
    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
   546
        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
   547
        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
   548
            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
   549
        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
   550
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
    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
   552
        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
   553
        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
   554
            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
   555
        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
   556
        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
   557
            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
   558
        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
   559
            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
   560
        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
   561
            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
   562
            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
   563
        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
   564
        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
   565
        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
   566
            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
   567
                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
   568
                  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
   569
        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
   570
            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
   571
                                     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
   572
            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
   573
                                         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
   574
        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
   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
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
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
   578
    """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
   579
    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
   580
    """
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
    __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
   582
    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
   583
    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
   584
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
    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
   586
        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
   587
        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
   588
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   589
    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
   590
        """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
   591
        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
   592
        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
   593
                                 year, len(items))
8900
010a59e12d89 use cw_etype instead of __regid__
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8745
diff changeset
   594
        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
   595
        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
   596
                                      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
   597
                            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
   598
        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
   599
            '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
   600
        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
   601
        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
   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
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
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
   605
    """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
   606
    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
   607
    """
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
    __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
   609
    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
   610
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
    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
   612
        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
   613
        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
   614
            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
   615
        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
   616
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
    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
   618
        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
   619
            return
8416
e7f06e562a27 [ui] display author name in box instead of login (closes #1529147)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 7940
diff changeset
   620
        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
   621
        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
   622
        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
   623
            '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
   624
                               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
   625
            '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
   626
        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
   627
        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
   628
        return tags.a(label, href=url, title=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
   629
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
   630
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
   631
# bw compat ####################################################################
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
   632
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
   633
from logilab.common.deprecation import class_moved, class_deprecated
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
   634
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
   635
from cubicweb.web.views import boxes, xmlrss, primary, tableview
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
   636
PrimaryView = class_moved(primary.PrimaryView)
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
   637
SideBoxView = class_moved(boxes.SideBoxView)
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
   638
XmlView = class_moved(xmlrss.XMLView)
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
   639
XmlItemView = class_moved(xmlrss.XMLItemView)
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
   640
XmlRsetView = class_moved(xmlrss.XMLRsetView)
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
   641
RssView = class_moved(xmlrss.RSSView)
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
   642
RssItemView = class_moved(xmlrss.RSSItemView)
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
   643
TableView = class_moved(tableview.TableView)