web/views/baseviews.py
author Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
Fri, 16 Dec 2011 14:35:25 +0100
changeset 8130 85ade620056c
parent 7940 ac8052334e0d
child 8190 2a3c1b787688
permissions -rw-r--r--
[views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
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
8130
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   160
    context. By default it produces the result of ``entity.dc_title()`` wrapped in a
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   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)
8130
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   168
        self.w(u'<a href="%s" title="%s">%s</a>' % (
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   169
            xml_escape(entity.absolute_url()), xml_escape(desc),
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   170
            xml_escape(entity.dc_title())))
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   171
0ada13ce2e16 [doc] get 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
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
   173
    """:__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
   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
    This view is used whenthe entity should be considered as displayed out of
8130
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   176
    its context. By default it produces the result of ``entity.dc_long_title()`` wrapped
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   177
    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
   178
    """
0ada13ce2e16 [doc] get 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
    __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
   180
0ada13ce2e16 [doc] get 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
    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
   182
        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
   183
        desc = cut(entity.dc_description(), 50)
8130
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   184
        self.w(u'<a href="%s" title="%s">%s</a>' % (
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   185
            xml_escape(entity.absolute_url()), xml_escape(desc),
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   186
            xml_escape(entity.dc_long_title())))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   187
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   188
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   189
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
   190
    """:__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
   191
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   192
    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
   193
    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
   194
    `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
   195
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   196
    __regid__ = 'oneline'
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   197
    title = _('oneline')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   198
3682
9b62c5887639 add kwargs to some base views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3264
diff changeset
   199
    def cell_call(self, row, col, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   200
        """the one line view for an entity: linked text view
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   201
        """
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   202
        entity = self.cw_rset.get_entity(row, col)
8130
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   203
        desc = cut(entity.dc_description(), 50)
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   204
        title = cut(entity.dc_title(),
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   205
                    self._cw.property_value('navigation.short-line-size'))
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   206
        self.w(u'<a href="%s" title="%s">%s</a>' % (
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   207
                xml_escape(entity.absolute_url()), xml_escape(desc),
85ade620056c [views] (in/outof)context views now use directly dc_(long)_title() (closes #2110235)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7940
diff changeset
   208
                xml_escape(title)))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   209
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   210
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   211
# 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
   212
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   213
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
   214
    """:__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
   215
0ada13ce2e16 [doc] get 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
    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
   217
    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
   218
    `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
   219
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   220
    __regid__ = 'text'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   221
    title = _('text')
532
ce3e94cbb074 specify content type for text views
sylvain.thenault@logilab.fr
parents: 531
diff changeset
   222
    content_type = 'text/plain'
647
49bb57a9606b some selectors update + drop EntityRelationView (only used by jpl)
sylvain.thenault@logilab.fr
parents: 632
diff changeset
   223
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   224
    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
   225
        """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
   226
        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
   227
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
   228
        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
   229
        override this method.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   230
        """
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   231
        rset = self.cw_rset
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   232
        if rset is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   233
            raise NotImplementedError, self
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   234
        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
   235
            self.wview(self.__regid__, rset, row=i, **kwargs)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   236
            if len(rset) > 1:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   237
                self.w(u"\n")
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   238
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   239
    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
   240
        entity = self.cw_rset.get_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   241
        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
   242
                   self._cw.property_value('navigation.short-line-size')))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   243
137
7e45cf48c2f1 don't display additional owners in metadata, this is confusing
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 0
diff changeset
   244
7836
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   245
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
   246
    """:__regid__: *textincontext*
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   247
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
   248
    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
   249
    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
   250
    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
   251
    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
   252
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   253
    __regid__ = 'textincontext'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   254
    title = None # not listed as a possible view
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   255
    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
   256
        entity = self.cw_rset.get_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   257
        self.w(entity.dc_title())
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   258
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   259
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   260
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
   261
    """:__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
   262
0ada13ce2e16 [doc] get 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
    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
   264
    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
   265
    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
   266
    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
   267
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   268
    __regid__ = 'textoutofcontext'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   269
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   270
    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
   271
        entity = self.cw_rset.get_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   272
        self.w(entity.dc_long_title())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   273
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   274
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   275
# list views ##################################################################
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   276
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   277
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
   278
    """:__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
   279
0ada13ce2e16 [doc] get 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
    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
   281
    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
   282
    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
   283
0ada13ce2e16 [doc] get 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
    .. 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
   285
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   286
      <ul 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
   287
        <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
   288
        ...
0ada13ce2e16 [doc] get 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
      </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
   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
    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
   292
    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
   293
    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
   294
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   295
    __regid__ = 'list'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   296
    title = _('list')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   297
    item_vid = 'listitem'
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   298
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   299
    def call(self, klass=None, title=None, subvid=None, listid=None, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   300
        """display a list of entities by calling their <item_vid> view
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   301
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   302
        :param listid: the DOM id to use for the root element
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   303
        """
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   304
        # 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
   305
        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
   306
            subvid = self._cw.form.pop('subvid') # consume it
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   307
        if listid:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   308
            listid = u' id="%s"' % listid
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   309
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   310
            listid = u''
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   311
        if title:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   312
            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
   313
            self.w(u'<ul>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   314
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   315
            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
   316
        for i in xrange(self.cw_rset.rowcount):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   317
            self.cell_call(row=i, col=0, vid=subvid, **kwargs)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   318
        self.w(u'</ul>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   319
        if title:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   320
            self.w(u'</div>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   321
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   322
    def cell_call(self, row, col=0, vid=None, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   323
        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
   324
        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
   325
        self.w(u'</li>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   326
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   327
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   328
class ListItemView(EntityView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   329
    __regid__ = 'listitem'
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   330
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   331
    @property
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   332
    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
   333
        if self._cw.search_state[0] == 'normal':
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   334
            return 'outofcontext'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   335
        return 'outofcontext-search'
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   336
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   337
    def cell_call(self, row, col, vid=None, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   338
        if not vid:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   339
            vid = self.redirect_vid
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   340
        try:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   341
            self.wview(vid, self.cw_rset, row=row, col=col, **kwargs)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   342
        except NoSelectableObject:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   343
            if vid == self.redirect_vid:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   344
                raise
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   345
            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
   346
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   347
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   348
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
   349
    """:__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
   350
0ada13ce2e16 [doc] get 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
    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
   352
    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
   353
    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
   354
0ada13ce2e16 [doc] get 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
    .. 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
   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
      <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
   358
      ...
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   359
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   360
0ada13ce2e16 [doc] get 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
    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
   362
    :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
   363
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   364
    __regid__ = 'simplelist'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   365
    redirect_vid = 'incontext'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   366
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
   367
    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
   368
        """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
   369
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
        :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
   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
        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
   373
            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
   374
                 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
   375
        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
   376
            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
   377
        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
   378
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   379
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   380
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
   381
    """:__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
   382
0ada13ce2e16 [doc] get 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
    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
   384
    ('<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
   385
    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
   386
    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
   387
    are only images entities).
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   388
    """
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   389
    __regid__ = 'sameetypelist'
2645
91c71276f999 F [adapted list view] fix selector
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2472
diff changeset
   390
    __select__ = EntityView.__select__ & one_etype_rset()
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   391
    item_vid = 'sameetypelistitem'
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   392
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   393
    @property
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   394
    def title(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   395
        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
   396
        return display_name(self._cw, etype, form='plural')
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   397
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   398
    def call(self, **kwargs):
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   399
        """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
   400
        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
   401
        if showtitle:
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   402
            self.w(u'<h1>%s</h1>' % self.title)
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   403
        super(SameETypeListView, self).call(**kwargs)
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   404
4507
57927ad07e63 no need for a specific vid argument here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4494
diff changeset
   405
    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
   406
        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
   407
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   408
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   409
class SameETypeListItemView(EntityView):
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   410
    __regid__ = 'sameetypelistitem'
2469
b87c4d150e09 new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2468
diff changeset
   411
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
   412
    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
   413
        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
   414
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4482
diff changeset
   415
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   416
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
   417
    """:__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
   418
0ada13ce2e16 [doc] get 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
    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
   420
    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
   421
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   422
    __regid__ = 'csv'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   423
    redirect_vid = 'incontext'
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   424
5518
ceea458025b9 [web] unify list views call arguments: use subvid to specify the view to use for each item
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   425
    def call(self, subvid=None, **kwargs):
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
   426
        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
   427
            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
   428
                 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
   429
        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
   430
            kwargs['vid'] = subvid
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   431
        rset = self.cw_rset
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   432
        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
   433
            self.cell_call(i, 0, **kwargs)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   434
            if i < rset.rowcount-1:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   435
                self.w(u", ")
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   436
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   437
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
   438
# 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
   439
0ada13ce2e16 [doc] get 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
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
   441
    """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
   442
    __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
   443
    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
   444
0ada13ce2e16 [doc] get 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
    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
   446
        _ = 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
   447
        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
   448
        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
   449
        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
   450
            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
   451
        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
   452
            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
   453
            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
   454
                   % 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
   455
        # 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
   456
        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
   457
            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
   458
            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
   459
                   % 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
   460
        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
   461
            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
   462
                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
   463
            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
   464
                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
   465
            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
   466
        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
   467
        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
   468
            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
   469
            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
   470
        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
   471
0ada13ce2e16 [doc] get 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
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   473
class TreeItemView(ListItemView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   474
    __regid__ = 'treeitem'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   475
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   476
    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
   477
        self.wview('incontext', self.cw_rset, row=row, col=col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   478
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
   479
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   480
class TextSearchResultView(EntityView):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   481
    """this view is used to display full-text search
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   482
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   483
    It tries to highlight part of data where the search word appears.
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
    XXX: finish me (fixed line width, fixed number of lines, CSS, etc.)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   486
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3293
diff changeset
   487
    __regid__ = 'tsearch'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   488
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   489
    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
   490
        entity = self.cw_rset.complete_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   491
        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
   492
        searched = self.cw_rset.searched_text()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   493
        if searched is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   494
            return
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   495
        searched = searched.lower()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   496
        highlighted = '<b>%s</b>' % searched
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   497
        for attr in entity.e_schema.indexable_attributes():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   498
            try:
1680
39860636e184 use xml_escape
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents: 1653
diff changeset
   499
                value = xml_escape(entity.printable_value(attr, format='text/plain').lower())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   500
            except TransformError, ex:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   501
                continue
7815
2a164a9cf81c [exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7310
diff changeset
   502
            except Exception:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   503
                continue
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   504
            if searched in value:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   505
                contexts = []
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   506
                for ctx in value.split(searched):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   507
                    if len(ctx) > 30:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   508
                        contexts.append(u'...' + ctx[-30:])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   509
                    else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   510
                        contexts.append(ctx)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   511
                value = u'\n' + highlighted.join(contexts)
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   512
                self.w(value.replace('\n', '<br/>'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   513
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   514
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   515
class TooltipView(EntityView):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   516
    """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
   517
    __regid__ = 'tooltip'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   518
    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
   519
        self.wview('oneline', self.cw_rset, row=row, col=col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   520
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents: 795
diff changeset
   521
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
   522
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
   523
    """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
   524
    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
   525
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
    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
   527
    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
   528
    """
7835
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7815
diff changeset
   529
    __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
   530
    __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
   531
    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
   532
    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
   533
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   534
    def index_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
   535
        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
   536
            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
   537
        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
   538
                                  **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
   539
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   540
    def 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
   541
        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
   542
        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
   543
            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
   544
        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
   545
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   546
    def 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
   547
        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
   548
        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
   549
            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
   550
        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
   551
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
    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
   553
        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
   554
        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
   555
            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
   556
        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
   557
        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
   558
            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
   559
        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
   560
            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
   561
        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
   562
            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
   563
            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
   564
        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
   565
        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
   566
        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
   567
            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
   568
              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
   569
        if needmore:
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   570
            url = self._cw.build_url('view', vid=self.__regid__,
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   571
                                     rql=self.cw_rset.printable_rql())
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   572
            w( u'<li>%s</li>\n' % tags.a(u'[%s]' % self._cw._('see more'),
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   573
                                         href=url))
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   574
        w(u'</ul>\n')
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   575
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   576
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   577
class ArchiveView(GroupByView):
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   578
    """archive view of a result set. Links to months are built using a basepath
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   579
    parameters, eg using url like <basepath>/<year>/<month>
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   580
    """
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   581
    __regid__ = 'cw.archive.by_date'
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   582
    entity_attribute = 'creation_date'
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   583
    reversed = True
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   584
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   585
    def group_key(self, entity, **kwargs):
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   586
        value = super(ArchiveView, self).group_key(entity, **kwargs)
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   587
        return '%04d' % value.year, '%02d' % value.month
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   588
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   589
    def index_link(self, basepath, key, items):
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   590
        """represent a single month entry"""
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   591
        year, month = key
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   592
        label = u'%s %s [%s]' % (self._cw._(calendar.MONTHNAMES[int(month)-1]),
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   593
                                 year, len(items))
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
        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
   595
        vtitle = '%s %s' % (', '.join(display_name(self._cw, etype, 'plural')
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   596
                                      for etype in etypes),
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   597
                            label)
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   598
        title = self._cw._('archive for %(month)s/%(year)s') % {
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   599
            'month': month, 'year': year}
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   600
        url = self.index_url(basepath, key, vtitle=vtitle)
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   601
        return tags.a(label, href=url, title=title)
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   602
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   603
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   604
class AuthorView(GroupByView):
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   605
    """author view of a result set. Links to month are built using a basepath
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   606
    parameters, eg using url like <basepath>/<author>
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   607
    """
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   608
    __regid__ = 'cw.archive.by_author'
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   609
    entity_attribute = 'creator'
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   610
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   611
    def group_key(self, entity, **kwargs):
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   612
        value = super(AuthorView, self).group_key(entity, **kwargs)
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   613
        if value:
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
            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
   615
        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
   616
3282742dd4c6 [baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5518
diff changeset
   617
    def index_link(self, basepath, key, items):
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
        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
   619
        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
   620
        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
   621
            '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
   622
                               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
   623
            '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
   624
        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
   625
        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
   626
        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
   627
0ada13ce2e16 [doc] get back baseviews documentation into the code, enhance it and reorganize the module accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7835
diff changeset
   628
0ada13ce2e16 [doc] get 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
# 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
   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
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
   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 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
   634
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
   635
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
   636
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
   637
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
   638
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
   639
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
   640
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
   641
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
   642
0ada13ce2e16 [doc] get 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
0ada13ce2e16 [doc] get 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
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
   645
    __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
   646
    __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
   647
    __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
   648
0ada13ce2e16 [doc] get 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
    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
   650
        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
   651
        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
   652
        self.wview('oneline', self.cw_rset, row=row, col=col)