web/component.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 26 May 2010 12:31:37 +0200
branchstable
changeset 5585 e1cbf6b304ea
parent 5426 0d4853a6e5ee
child 5616 859225caf375
permissions -rw-r--r--
[sqlite] fix crash on db-create with sqlite abd unexistent database due to missing paren in logical expression (closes #909604)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     1
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    18
"""abstract component class and base components definition for CubicWeb web client
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
__docformat__ = "restructuredtext en"
2259
5d90bd26af8b cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2237
diff changeset
    22
_ = unicode
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
681
7cb402fa3958 use class_renamed, not class_moved
sylvain.thenault@logilab.fr
parents: 670
diff changeset
    24
from logilab.common.deprecation import class_renamed
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2259
diff changeset
    25
from logilab.mtconverter import xml_escape
661
4f61eb8a96b7 properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents: 659
diff changeset
    26
799
ad129d374ee2 fix page_size handling, use abstract_has_related_entities
sylvain.thenault@logilab.fr
parents: 747
diff changeset
    27
from cubicweb import role
5389
809d3b5b3d31 [python2.6] careful: json-py provides a json package. We don't want that.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5377
diff changeset
    28
from cubicweb.web import json
2819
b864288fd316 remove more 3.2 deprecated code, reintroduce checkbox used by formrenderers
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2799
diff changeset
    29
from cubicweb.view import Component
655
ca3c4992c7d1 kill [Singleton]VComponent
sylvain.thenault@logilab.fr
parents: 652
diff changeset
    30
from cubicweb.selectors import (
ca3c4992c7d1 kill [Singleton]VComponent
sylvain.thenault@logilab.fr
parents: 652
diff changeset
    31
    paginated_rset, one_line_rset, primary_view, match_context_prop,
2819
b864288fd316 remove more 3.2 deprecated code, reintroduce checkbox used by formrenderers
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2799
diff changeset
    32
    partial_has_related_entities)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
661
4f61eb8a96b7 properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents: 659
diff changeset
    35
class EntityVComponent(Component):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
    """abstract base class for additinal components displayed in content
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
    headers and footer according to:
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
    38
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
    * the displayed entity's type
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
    * a context (currently 'header' or 'footer')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    41
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
    it should be configured using .accepts, .etype, .rtype, .target and
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
    .context class attributes
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
    """
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
    45
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
    __registry__ = 'contentnavigation'
742
99115e029dca replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 687
diff changeset
    47
    __select__ = one_line_rset() & primary_view() & match_context_prop()
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
    48
2799
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2381
diff changeset
    49
    cw_property_defs = {
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
        _('visible'):  dict(type='Boolean', default=True,
2237
7e546c3d6ea5 [primary] fix #344249
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1977
diff changeset
    51
                            help=_('display the component or not')),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
        _('order'):    dict(type='Int', default=99,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
                            help=_('display order of the component')),
3840
2eff4348b1e4 prepare support for a 'context toolbar', used in tracker but will much probably be backported in default primary view. Turn pdfview component into a toolbar element
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3750
diff changeset
    54
        _('context'):  dict(type='String', default='navtop',
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
    55
                            vocabulary=(_('navtop'), _('navbottom'),
3840
2eff4348b1e4 prepare support for a 'context toolbar', used in tracker but will much probably be backported in default primary view. Turn pdfview component into a toolbar element
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3750
diff changeset
    56
                                        _('navcontenttop'), _('navcontentbottom'),
2eff4348b1e4 prepare support for a 'context toolbar', used in tracker but will much probably be backported in default primary view. Turn pdfview component into a toolbar element
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3750
diff changeset
    57
                                        _('ctxtoolbar')),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    58
                            help=_('context where this component should be displayed')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
    }
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
    60
3840
2eff4348b1e4 prepare support for a 'context toolbar', used in tracker but will much probably be backported in default primary view. Turn pdfview component into a toolbar element
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3750
diff changeset
    61
    context = 'navcontentbottom'
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
    62
880
d46cf89ead07 view is optional
sylvain.thenault@logilab.fr
parents: 838
diff changeset
    63
    def call(self, view=None):
1661
00340ebedc24 name argument
sylvain.thenault@logilab.fr
parents: 1511
diff changeset
    64
        return self.cell_call(0, 0, view=view)
529
6e84e93fa7ec EntityVComponent should now implements cell_call
sylvain.thenault@logilab.fr
parents: 330
diff changeset
    65
880
d46cf89ead07 view is optional
sylvain.thenault@logilab.fr
parents: 838
diff changeset
    66
    def cell_call(self, row, col, view=None):
529
6e84e93fa7ec EntityVComponent should now implements cell_call
sylvain.thenault@logilab.fr
parents: 330
diff changeset
    67
        raise NotImplementedError()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
    69
661
4f61eb8a96b7 properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents: 659
diff changeset
    70
class NavigationComponent(Component):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    71
    """abstract base class for navigation components"""
3408
c92170fca813 [api] use __regid__ instead of deprecated id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3023
diff changeset
    72
    __regid__ = 'navigation'
742
99115e029dca replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 687
diff changeset
    73
    __select__ = paginated_rset()
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
    74
2799
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2381
diff changeset
    75
    cw_property_defs = {
1511
514e4e53a3c7 do not set visible property by default
sylvain.thenault@logilab.fr
parents: 1433
diff changeset
    76
        _('visible'):  dict(type='Boolean', default=True,
514e4e53a3c7 do not set visible property by default
sylvain.thenault@logilab.fr
parents: 1433
diff changeset
    77
                            help=_('display the component or not')),
514e4e53a3c7 do not set visible property by default
sylvain.thenault@logilab.fr
parents: 1433
diff changeset
    78
        }
514e4e53a3c7 do not set visible property by default
sylvain.thenault@logilab.fr
parents: 1433
diff changeset
    79
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
    page_size_property = 'navigation.page-size'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
    start_param = '__start'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
    stop_param = '__stop'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
    page_link_templ = u'<span class="slice"><a href="%s" title="%s">%s</a></span>'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
    selected_page_link_templ = u'<span class="selectedSlice"><a href="%s" title="%s">%s</a></span>'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
    previous_page_link_templ = next_page_link_templ = page_link_templ
3012
97696093ba54 [page nav] display non clickable previous/next page when it does'nt make sense instead of nothing
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3010
diff changeset
    86
    no_previous_page_link = u'&lt;&lt;'
97696093ba54 [page nav] display non clickable previous/next page when it does'nt make sense instead of nothing
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3010
diff changeset
    87
    no_next_page_link = u'&gt;&gt;'
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
    88
1339
f74674c042ed should take extra kwargs
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
    89
    def __init__(self, req, rset, **kwargs):
2890
fdcb8a2bb6eb fix __init__ parameters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2819
diff changeset
    90
        super(NavigationComponent, self).__init__(req, rset=rset, **kwargs)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    91
        self.starting_from = 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    92
        self.total = rset.rowcount
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    93
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
    def get_page_size(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    95
        try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
            return self._page_size
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
        except AttributeError:
3468
b02fa4db2868 [tests] make unittest_viewselectors pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3457
diff changeset
    98
            page_size = self.cw_extra_kwargs.get('page_size')
822
e3d8db01f3f5 test_views fixes
sylvain.thenault@logilab.fr
parents: 817
diff changeset
    99
            if page_size is None:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3408
diff changeset
   100
                if 'page_size' in self._cw.form:
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3408
diff changeset
   101
                    page_size = int(self._cw.form['page_size'])
822
e3d8db01f3f5 test_views fixes
sylvain.thenault@logilab.fr
parents: 817
diff changeset
   102
                else:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3408
diff changeset
   103
                    page_size = self._cw.property_value(self.page_size_property)
799
ad129d374ee2 fix page_size handling, use abstract_has_related_entities
sylvain.thenault@logilab.fr
parents: 747
diff changeset
   104
            self._page_size = page_size
ad129d374ee2 fix page_size handling, use abstract_has_related_entities
sylvain.thenault@logilab.fr
parents: 747
diff changeset
   105
            return page_size
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
    def set_page_size(self, page_size):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
        self._page_size = page_size
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
   109
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
    page_size = property(get_page_size, set_page_size)
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
   111
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   112
    def page_boundaries(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
        try:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3408
diff changeset
   114
            stop = int(self._cw.form[self.stop_param]) + 1
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3408
diff changeset
   115
            start = int(self._cw.form[self.start_param])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   116
        except KeyError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   117
            start, stop = 0, self.page_size
4089
ff92c7d692bf typos, api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890
diff changeset
   118
        if start >= len(self.cw_rset):
3607
a7c5e62c7e00 don't crash if specified page size is greater than rset size
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3014
diff changeset
   119
            start, stop = 0, self.page_size
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
        self.starting_from = start
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
        return start, stop
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
   122
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
    def clean_params(self, params):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   124
        if self.start_param in params:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
            del params[self.start_param]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   126
        if self.stop_param in params:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   127
            del params[self.stop_param]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   128
3013
6a40a9a72957 [page nav] json navigation (when coming from a facets restriction for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3012
diff changeset
   129
    def page_url(self, path, params, start, stop):
4882
4a42d700c52d [web] stop using deprecated merge_dicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   130
        params = dict(params)
4a42d700c52d [web] stop using deprecated merge_dicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   131
        params.update({self.start_param : start,
4a42d700c52d [web] stop using deprecated merge_dicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   132
                       self.stop_param : stop,})
3013
6a40a9a72957 [page nav] json navigation (when coming from a facets restriction for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3012
diff changeset
   133
        if path == 'json':
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3408
diff changeset
   134
            rql = params.pop('rql', self.cw_rset.printable_rql())
3013
6a40a9a72957 [page nav] json navigation (when coming from a facets restriction for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3012
diff changeset
   135
            # latest 'true' used for 'swap' mode
6a40a9a72957 [page nav] json navigation (when coming from a facets restriction for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3012
diff changeset
   136
            url = 'javascript: replacePageChunk(%s, %s, %s, %s, true)' % (
5389
809d3b5b3d31 [python2.6] careful: json-py provides a json package. We don't want that.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5377
diff changeset
   137
                json.dumps(params.get('divid', 'paginated-content')),
809d3b5b3d31 [python2.6] careful: json-py provides a json package. We don't want that.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5377
diff changeset
   138
                json.dumps(rql), json.dumps(params.pop('vid', None)), json.dumps(params))
3013
6a40a9a72957 [page nav] json navigation (when coming from a facets restriction for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3012
diff changeset
   139
        else:
3457
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   140
            url = self._cw.build_url(path, **params)
3013
6a40a9a72957 [page nav] json navigation (when coming from a facets restriction for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3012
diff changeset
   141
        return url
6a40a9a72957 [page nav] json navigation (when coming from a facets restriction for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3012
diff changeset
   142
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   143
    def page_link(self, path, params, start, stop, content):
3013
6a40a9a72957 [page nav] json navigation (when coming from a facets restriction for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3012
diff changeset
   144
        url = xml_escape(self.page_url(path, params, start, stop))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   145
        if start == self.starting_from:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   146
            return self.selected_page_link_templ % (url, content, content)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   147
        return self.page_link_templ % (url, content, content)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   148
3014
62ce5a139b52 [page nav] previous/next page links should also consider url's base path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3013
diff changeset
   149
    def previous_link(self, path, params, content='&lt;&lt;', title=_('previous_results')):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   150
        start = self.starting_from
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   151
        if not start :
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   152
            return self.no_previous_page_link
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
        start = max(0, start - self.page_size)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
        stop = start + self.page_size - 1
3014
62ce5a139b52 [page nav] previous/next page links should also consider url's base path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3013
diff changeset
   155
        url = xml_escape(self.page_url(path, params, start, stop))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
        return self.previous_page_link_templ % (url, title, content)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   157
3014
62ce5a139b52 [page nav] previous/next page links should also consider url's base path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3013
diff changeset
   158
    def next_link(self, path, params, content='&gt;&gt;', title=_('next_results')):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   159
        start = self.starting_from + self.page_size
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   160
        if start >= self.total:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   161
            return self.no_next_page_link
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   162
        stop = start + self.page_size - 1
3014
62ce5a139b52 [page nav] previous/next page links should also consider url's base path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3013
diff changeset
   163
        url = xml_escape(self.page_url(path, params, start, stop))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   164
        return self.next_page_link_templ % (url, title, content)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   165
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   166
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   167
class RelatedObjectsVComponent(EntityVComponent):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   168
    """a section to display some related entities"""
883
44f1aba675de missing selectors, no more need for relation_possible when using has_related_entities (implied)
sylvain.thenault@logilab.fr
parents: 880
diff changeset
   169
    __select__ = EntityVComponent.__select__ & partial_has_related_entities()
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
   170
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   171
    vid = 'list'
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
   172
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   173
    def rql(self):
655
ca3c4992c7d1 kill [Singleton]VComponent
sylvain.thenault@logilab.fr
parents: 652
diff changeset
   174
        """override this method if you want to use a custom rql query"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   175
        return None
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
   176
529
6e84e93fa7ec EntityVComponent should now implements cell_call
sylvain.thenault@logilab.fr
parents: 330
diff changeset
   177
    def cell_call(self, row, col, view=None):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   178
        rql = self.rql()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   179
        if rql is None:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3408
diff changeset
   180
            entity = self.cw_rset.get_entity(row, col)
799
ad129d374ee2 fix page_size handling, use abstract_has_related_entities
sylvain.thenault@logilab.fr
parents: 747
diff changeset
   181
            rset = entity.related(self.rtype, role(self))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   182
        else:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3408
diff changeset
   183
            eid = self.cw_rset[row][col]
5174
78438ad513ca #759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4882
diff changeset
   184
            rset = self._cw.execute(self.rql(), {'x': eid})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   185
        if not rset.rowcount:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   186
            return
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   187
        self.w(u'<div class="%s">' % self.div_class())
3777
3ef8cdb5fb1c backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3629 3750
diff changeset
   188
        self.w(u'<h4>%s</h4>\n' % self._cw._(self.title).capitalize())
3750
b7fa3d93640a display title in the component to avoid relying on view supporting title argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3607
diff changeset
   189
        self.wview(self.vid, rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   190
        self.w(u'</div>')
661
4f61eb8a96b7 properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents: 659
diff changeset
   191
4f61eb8a96b7 properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents: 659
diff changeset
   192
681
7cb402fa3958 use class_renamed, not class_moved
sylvain.thenault@logilab.fr
parents: 670
diff changeset
   193
VComponent = class_renamed('VComponent', Component,
7cb402fa3958 use class_renamed, not class_moved
sylvain.thenault@logilab.fr
parents: 670
diff changeset
   194
                           'VComponent is deprecated, use Component')
7cb402fa3958 use class_renamed, not class_moved
sylvain.thenault@logilab.fr
parents: 670
diff changeset
   195
SingletonVComponent = class_renamed('SingletonVComponent', Component,
7cb402fa3958 use class_renamed, not class_moved
sylvain.thenault@logilab.fr
parents: 670
diff changeset
   196
                                    'SingletonVComponent is deprecated, use '
7cb402fa3958 use class_renamed, not class_moved
sylvain.thenault@logilab.fr
parents: 670
diff changeset
   197
                                    'Component and explicit registration control')