web/views/baseviews.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 12 Oct 2011 19:06:15 +0200
changeset 7940 ac8052334e0d
parent 7918 d59db6068731
child 8130 85ade620056c
child 8416 e7f06e562a27
permissions -rw-r--r--
[printers] fix bug introduced by final view refactoring: &#160; shouldn't be escaped. Also remove some msgids which should have been removed during this refactoring
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7815
2a164a9cf81c [exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7310
diff changeset
     1
# copyright 2003-2011 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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
__docformat__ = "restructuredtext en"
1882
ce662160bb46 cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1760
diff changeset
    79
_ = unicode
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
3235
bad0ff9b0c13 fix when Interval is coming from date substraction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2996
diff changeset
    81
from datetime import timedelta
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
    82
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
    83
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
from rql import nodes
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
6883
1538542a88ed [cleanup]
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6740
diff changeset
    86
from logilab.mtconverter import TransformError, xml_escape
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    87
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
    88
from cubicweb import NoSelectableObject, tags
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
    89
from cubicweb.selectors import yes, empty_rset, one_etype_rset, match_kwargs
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
    90
from cubicweb.schema import display_name
756
2c3981830408 update import
sylvain.thenault@logilab.fr
parents: 742
diff changeset
    91
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
    92
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
    93
from cubicweb.web.views import calendar
0
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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
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
    97
    """:__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
    98
0ada13ce2e16 [doc] get 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
    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
   100
    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
   101
    :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
   102
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   103
    __regid__ = 'null'
758
0c0dfd33a76d instantiate selectors wherever needed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 742
diff changeset
   104
    __select__ = yes()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
    def call(self, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
        pass
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
    cell_call = call
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
632
3a394a90b702 kill EmptyRsetVeiw
sylvain.thenault@logilab.fr
parents: 631
diff changeset
   110
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
   111
    """:__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
   112
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   113
    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
   114
    (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
   115
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   116
    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
   117
    "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
   118
    """
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   119
    __regid__ = 'noresult'
742
99115e029dca replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 647
diff changeset
   120
    __select__ = empty_rset()
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   121
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   122
    def call(self, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
        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
   124
               % self._cw._('No result matching query'))
0
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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   127
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
   128
    """:__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
   129
0ada13ce2e16 [doc] get 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
    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
   131
    (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
   132
    though usually dedicated for cells containing an attribute's value.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   133
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   134
    __regid__ = 'final'
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   135
3165
0a50ebe53db7 [views] remove parameter displaytime from final view
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 2996
diff changeset
   136
    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
   137
        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
   138
        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
   139
            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
   140
            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
   141
        etype = self.cw_rset.description[row][col]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   142
        if etype == 'String':
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   143
            entity, rtype = self.cw_rset.related_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   144
            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
   145
                # 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
   146
                # about string format & all
573
9c8fd72ba6c1 try to get raw text values in rset csv view
sylvain.thenault@logilab.fr
parents: 570
diff changeset
   147
                self.w(entity.printable_value(rtype, value, format=format))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   148
                return
7918
d59db6068731 remove 3.14 deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7913
diff changeset
   149
        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
   150
        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
   151
            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
   152
        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
   153
            self.wdata(value)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   155
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
   156
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
   157
    """:__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
   158
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   159
    This view is used whenthe entity should be considered as displayed in its
0ada13ce2e16 [doc] get 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
    context. By default it produces the result of `textincontext` wrapped in 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
   161
    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
   162
    """
0ada13ce2e16 [doc] get 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
    __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
   164
0ada13ce2e16 [doc] get 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
    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
   166
        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
   167
        desc = cut(entity.dc_description(), 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
   168
        self.w(u'<a href="%s" title="%s">' % (
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   169
            xml_escape(entity.absolute_url()), xml_escape(desc)))
0ada13ce2e16 [doc] get 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
        self.w(xml_escape(self._cw.view('textincontext', self.cw_rset,
0ada13ce2e16 [doc] get 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
                                        row=row, col=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
   172
        self.w(u'</a>')
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   173
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
   174
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   175
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
   176
    """:__regid__: *outofcontext*
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   177
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   178
    This view is used whenthe entity should be considered as displayed 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
   179
    its context. By default it produces the result of `textoutofcontext` wrapped
0ada13ce2e16 [doc] get 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
    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
   181
    """
0ada13ce2e16 [doc] get 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
    __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
   183
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   184
    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
   185
        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
   186
        desc = cut(entity.dc_description(), 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
   187
        self.w(u'<a href="%s" title="%s">' % (
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   188
            xml_escape(entity.absolute_url()), xml_escape(desc)))
0ada13ce2e16 [doc] get 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
        self.w(xml_escape(self._cw.view('textoutofcontext', self.cw_rset,
0ada13ce2e16 [doc] get 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
                                        row=row, col=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
   191
        self.w(u'</a>')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   192
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   193
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   194
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
   195
    """:__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
   196
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   197
    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
   198
    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
   199
    `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
   200
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   201
    __regid__ = 'oneline'
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   202
    title = _('oneline')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   203
3682
9b62c5887639 add kwargs to some base views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3264
diff changeset
   204
    def cell_call(self, row, col, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   205
        """the one line view for an entity: linked text view
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   206
        """
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   207
        entity = self.cw_rset.get_entity(row, col)
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   208
        self.w(u'<a href="%s">' % xml_escape(entity.absolute_url()))
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   209
        self.w(xml_escape(self._cw.view('text', self.cw_rset, row=row, col=col)))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   210
        self.w(u'</a>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   211
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   212
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
# 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
   214
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   215
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
   216
    """:__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
   217
0ada13ce2e16 [doc] get 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
    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
   219
    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
   220
    `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
   221
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   222
    __regid__ = 'text'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   223
    title = _('text')
532
ce3e94cbb074 specify content type for text views
sylvain.thenault@logilab.fr
parents: 531
diff changeset
   224
    content_type = 'text/plain'
647
49bb57a9606b some selectors update + drop EntityRelationView (only used by jpl)
sylvain.thenault@logilab.fr
parents: 632
diff changeset
   225
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   226
    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
   227
        """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
   228
        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
   229
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
   230
        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
   231
        override this method.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   232
        """
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   233
        rset = self.cw_rset
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   234
        if rset is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   235
            raise NotImplementedError, self
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   236
        for i in xrange(len(rset)):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   237
            self.wview(self.__regid__, rset, row=i, **kwargs)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   238
            if len(rset) > 1:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   239
                self.w(u"\n")
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   240
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   241
    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
   242
        entity = self.cw_rset.get_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   243
        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
   244
                   self._cw.property_value('navigation.short-line-size')))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   245
137
7e45cf48c2f1 don't display additional owners in metadata, this is confusing
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 0
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
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
   248
    """:__regid__: *textincontext*
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   249
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
   250
    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
   251
    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
   252
    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
   253
    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
   254
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   255
    __regid__ = 'textincontext'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   256
    title = None # not listed as a possible view
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   257
    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
   258
        entity = self.cw_rset.get_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   259
        self.w(entity.dc_title())
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   260
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   261
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   262
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
   263
    """:__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
   264
0ada13ce2e16 [doc] get 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
    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
   266
    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
   267
    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
   268
    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
   269
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   270
    __regid__ = 'textoutofcontext'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   271
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   272
    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
   273
        entity = self.cw_rset.get_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   274
        self.w(entity.dc_long_title())
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
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   277
# list views ##################################################################
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   278
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   279
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
   280
    """:__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
   281
0ada13ce2e16 [doc] get 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
    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
   283
    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
   284
    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
   285
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   286
    .. 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
   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 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
   289
        <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
   290
        ...
0ada13ce2e16 [doc] get 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
      </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
   292
0ada13ce2e16 [doc] get 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
    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
   294
    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
   295
    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
   296
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   297
    __regid__ = 'list'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   298
    title = _('list')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   299
    item_vid = 'listitem'
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
    def call(self, klass=None, title=None, subvid=None, listid=None, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   302
        """display a list of entities by calling their <item_vid> view
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   303
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   304
        :param listid: the DOM id to use for the root element
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   305
        """
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   306
        # 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
   307
        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
   308
            subvid = self._cw.form.pop('subvid') # consume it
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   309
        if listid:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   310
            listid = u' id="%s"' % listid
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   311
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   312
            listid = u''
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   313
        if title:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   314
            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
   315
            self.w(u'<ul>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   316
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   317
            self.w(u'<ul%s class="%s">\n' % (listid, klass or 'section'))
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   318
        for i in xrange(self.cw_rset.rowcount):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   319
            self.cell_call(row=i, col=0, vid=subvid, **kwargs)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   320
        self.w(u'</ul>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   321
        if title:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   322
            self.w(u'</div>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   323
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   324
    def cell_call(self, row, col=0, vid=None, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   325
        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
   326
        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
   327
        self.w(u'</li>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   328
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
class ListItemView(EntityView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   331
    __regid__ = 'listitem'
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   332
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   333
    @property
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   334
    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
   335
        if self._cw.search_state[0] == 'normal':
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   336
            return 'outofcontext'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   337
        return 'outofcontext-search'
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   338
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   339
    def cell_call(self, row, col, vid=None, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   340
        if not vid:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   341
            vid = self.redirect_vid
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   342
        try:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   343
            self.wview(vid, self.cw_rset, row=row, col=col, **kwargs)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   344
        except NoSelectableObject:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   345
            if vid == self.redirect_vid:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   346
                raise
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   347
            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
   348
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   349
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   350
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
   351
    """:__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
   352
0ada13ce2e16 [doc] get 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
    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
   354
    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
   355
    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
   356
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   357
    .. 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
   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
      <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
   360
      ...
0ada13ce2e16 [doc] get 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
0ada13ce2e16 [doc] get 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
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   363
    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
   364
    :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
   365
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   366
    __regid__ = 'simplelist'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   367
    redirect_vid = 'incontext'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   368
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
   369
    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
   370
        """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
   371
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
        :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
   373
        """
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
        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
   375
            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
   376
                 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
   377
        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
   378
            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
   379
        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
   380
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   381
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   382
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
   383
    """:__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
   384
0ada13ce2e16 [doc] get 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
    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
   386
    ('<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
   387
    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
   388
    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
   389
    are only images entities).
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   390
    """
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   391
    __regid__ = 'sameetypelist'
2645
91c71276f999 F [adapted list view] fix selector
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2472
diff changeset
   392
    __select__ = EntityView.__select__ & one_etype_rset()
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   393
    item_vid = 'sameetypelistitem'
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   394
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   395
    @property
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   396
    def title(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   397
        etype = iter(self.cw_rset.column_types(0)).next()
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   398
        return display_name(self._cw, etype, form='plural')
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   399
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   400
    def call(self, **kwargs):
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   401
        """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
   402
        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
   403
        if showtitle:
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   404
            self.w(u'<h1>%s</h1>' % self.title)
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   405
        super(SameETypeListView, self).call(**kwargs)
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   406
4507
57927ad07e63 no need for a specific vid argument here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4494
diff changeset
   407
    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
   408
        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
   409
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   410
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   411
class SameETypeListItemView(EntityView):
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   412
    __regid__ = 'sameetypelistitem'
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   413
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
   414
    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
   415
        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
   416
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   417
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   418
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
   419
    """:__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
   420
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   421
    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
   422
    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
   423
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   424
    __regid__ = 'csv'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   425
    redirect_vid = 'incontext'
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   426
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
   427
    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
   428
        if subvid is None and 'vid' in kwargs:
6583
4e7325d6b616 [deprecation] add version info
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6455
diff changeset
   429
            warn("[3.9] should give a 'subvid' argument instead of 'vid'",
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
   430
                 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
   431
        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
   432
            kwargs['vid'] = subvid
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   433
        rset = self.cw_rset
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   434
        for i in xrange(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
   435
            self.cell_call(i, 0, **kwargs)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   436
            if i < rset.rowcount-1:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   437
                self.w(u", ")
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   438
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   439
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
   440
# 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
   441
0ada13ce2e16 [doc] get 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
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
   443
    """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
   444
    __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
   445
    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
   446
0ada13ce2e16 [doc] get 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
    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
   448
        _ = 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
   449
        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
   450
        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
   451
        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
   452
            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
   453
        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
   454
            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
   455
            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
   456
                   % 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
   457
        # 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
   458
        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
   459
            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
   460
            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
   461
                   % 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
   462
        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
   463
            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
   464
                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
   465
            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
   466
                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
   467
            self.w(u'<span class="value">%s</span>' % entity.creator.name())
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   468
        meta = entity.cw_metainformation()
0ada13ce2e16 [doc] get 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
        if meta['source']['uri'] != 'system':
0ada13ce2e16 [doc] get 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
            self.w(u' (<span>%s</span>' % _('cw_source'))
0ada13ce2e16 [doc] get 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
            self.w(u' <span class="value">%s</span>)' % meta['source']['uri'])
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   472
        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
   473
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   474
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   475
class TreeItemView(ListItemView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   476
    __regid__ = 'treeitem'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   477
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   478
    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
   479
        self.wview('incontext', self.cw_rset, row=row, col=col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   480
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
   481
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   482
class TextSearchResultView(EntityView):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   483
    """this view is used to display full-text search
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   484
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   485
    It tries to highlight part of data where the search word appears.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   486
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   487
    XXX: finish me (fixed line width, fixed number of lines, CSS, etc.)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   488
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   489
    __regid__ = 'tsearch'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   490
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   491
    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
   492
        entity = self.cw_rset.complete_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   493
        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
   494
        searched = self.cw_rset.searched_text()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   495
        if searched is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   496
            return
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   497
        searched = searched.lower()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   498
        highlighted = '<b>%s</b>' % searched
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   499
        for attr in entity.e_schema.indexable_attributes():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   500
            try:
1680
39860636e184 use xml_escape
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents: 1653
diff changeset
   501
                value = xml_escape(entity.printable_value(attr, format='text/plain').lower())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   502
            except TransformError, ex:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   503
                continue
7815
2a164a9cf81c [exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7310
diff changeset
   504
            except Exception:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   505
                continue
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   506
            if searched in value:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   507
                contexts = []
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   508
                for ctx in value.split(searched):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   509
                    if len(ctx) > 30:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   510
                        contexts.append(u'...' + ctx[-30:])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   511
                    else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   512
                        contexts.append(ctx)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   513
                value = u'\n' + highlighted.join(contexts)
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   514
                self.w(value.replace('\n', '<br/>'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   515
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   516
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   517
class TooltipView(EntityView):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   518
    """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
   519
    __regid__ = 'tooltip'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   520
    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
   521
        self.wview('oneline', self.cw_rset, row=row, col=col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   522
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   523
6455
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   524
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
   525
    """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
   526
    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
   527
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   528
    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
   529
    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
   530
    """
7835
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7815
diff changeset
   531
    __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
   532
    __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
   533
    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
   534
    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
   535
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
    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
   537
        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
   538
            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
   539
        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
   540
                                  **kwargs)
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   541
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
    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
   543
        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
   544
        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
   545
            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
   546
        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
   547
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
    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
   549
        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
   550
        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
   551
            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
   552
        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
   553
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
    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
   555
        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
        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
   557
            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
   558
        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
   559
        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
   560
            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
   561
        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
   562
            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
   563
        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
   564
            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
   565
            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
   566
        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
   567
        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
   568
        for key in 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
   569
            w(u'<li>%s</li>\n' %
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   570
              self.index_link(basepath, key, index[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
   571
        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
   572
            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
   573
                                     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
   574
            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
   575
                                         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
   576
        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
   577
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
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
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
   580
    """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
   581
    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
   582
    """
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
    __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
   584
    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
   585
    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
   586
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
    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
   588
        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
   589
        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
   590
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
    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
   592
        """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
   593
        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
   594
        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
   595
                                 year, len(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
   596
        etypes = set(entity.__regid__ for entity in 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
   597
        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
   598
                                      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
   599
                            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
   600
        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
   601
            '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
   602
        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
   603
        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
   604
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   605
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   606
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
   607
    """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
   608
    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
   609
    """
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
    __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
   611
    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
   612
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
    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
   614
        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
   615
        if 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
   616
            return value.login
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
        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
   618
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   619
    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
   620
        label = u'%s [%s]' % (key, len(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
   621
        etypes = set(entity.__regid__ for entity in 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
   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}
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   626
        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
   627
        title = self._cw._('archive for %(author)s') % {'author': 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
   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)
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   644
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   645
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   646
class SecondaryView(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
   647
    __metaclass__ = 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
   648
    __deprecation_warning__ = '[3.9] the secondary view is deprecated, use one of oneline/incontext/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
   649
    __regid__ = 'secondary'
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   650
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   651
    def cell_call(self, row, col, **kwargs):
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   652
        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
   653
        self.w(u'&#160;')
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   654
        self.wview('oneline', self.cw_rset, row=row, col=col)