web/component.py
author Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
Wed, 18 Feb 2009 17:04:18 +0100
branchtls-sprint
changeset 817 12320ff8d6e4
parent 799 ad129d374ee2
child 822 e3d8db01f3f5
permissions -rw-r--r--
improve selector of RelatedObjectsVComponent: make sure the relation exists before fetching related entities
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     1
"""abstract component class and base components definition for CubicWeb web client
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     2
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     3
:organization: Logilab
640
8e64f12be69c drop EntityAction usage in cw, upgrade rql_condition and friends
sylvain.thenault@logilab.fr
parents: 593
diff changeset
     4
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     5
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     6
"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     7
__docformat__ = "restructuredtext en"
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     8
681
7cb402fa3958 use class_renamed, not class_moved
sylvain.thenault@logilab.fr
parents: 670
diff changeset
     9
from logilab.common.deprecation import class_renamed
743
62ff117dc99c update imports
sylvain.thenault@logilab.fr
parents: 687
diff changeset
    10
from logilab.mtconverter import html_escape
661
4f61eb8a96b7 properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents: 659
diff changeset
    11
799
ad129d374ee2 fix page_size handling, use abstract_has_related_entities
sylvain.thenault@logilab.fr
parents: 747
diff changeset
    12
from cubicweb import role
743
62ff117dc99c update imports
sylvain.thenault@logilab.fr
parents: 687
diff changeset
    13
from cubicweb.utils import merge_dicts
62ff117dc99c update imports
sylvain.thenault@logilab.fr
parents: 687
diff changeset
    14
from cubicweb.view import View, Component
655
ca3c4992c7d1 kill [Singleton]VComponent
sylvain.thenault@logilab.fr
parents: 652
diff changeset
    15
from cubicweb.selectors import (
ca3c4992c7d1 kill [Singleton]VComponent
sylvain.thenault@logilab.fr
parents: 652
diff changeset
    16
    paginated_rset, one_line_rset, primary_view, match_context_prop,
817
12320ff8d6e4 improve selector of RelatedObjectsVComponent: make sure the relation exists before fetching related entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 799
diff changeset
    17
    abstract_has_related_entities, abstract_relation_possible,
655
ca3c4992c7d1 kill [Singleton]VComponent
sylvain.thenault@logilab.fr
parents: 652
diff changeset
    18
    condition_compat, accepts_compat, has_relation_compat)
670
6c332f5c969c drop more registerers
sylvain.thenault@logilab.fr
parents: 661
diff changeset
    19
from cubicweb.common.registerers import accepts_registerer
0
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
_ = unicode
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
661
4f61eb8a96b7 properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents: 659
diff changeset
    23
class EntityVComponent(Component):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
    """abstract base class for additinal components displayed in content
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    25
    headers and footer according to:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
    
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
    * the displayed entity's type
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
    * a context (currently 'header' or 'footer')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
    it should be configured using .accepts, .etype, .rtype, .target and
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
    .context class attributes
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    32
    """
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
    __registry__ = 'contentnavigation'
670
6c332f5c969c drop more registerers
sylvain.thenault@logilab.fr
parents: 661
diff changeset
    35
    __registerer__ = accepts_registerer    
742
99115e029dca replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 687
diff changeset
    36
    __select__ = one_line_rset() & primary_view() & match_context_prop()
687
c23315c11185 removing explicit access to im_func, this is not necessary anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 681
diff changeset
    37
    registered = accepts_compat(has_relation_compat(condition_compat(View.registered)))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
    
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
    property_defs = {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
        _('visible'):  dict(type='Boolean', default=True,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    41
                            help=_('display the box or not')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
        _('order'):    dict(type='Int', default=99,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
                            help=_('display order of the component')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
        _('context'):  dict(type='String', default='header',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    45
                            vocabulary=(_('navtop'), _('navbottom'), 
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
                                        _('navcontenttop'), _('navcontentbottom')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
                            #vocabulary=(_('header'), _('incontext'), _('footer')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
                            help=_('context where this component should be displayed')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
        _('htmlclass'):dict(type='String', default='mainRelated',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
                            help=_('html class of the component')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    51
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
    
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
    context = 'navcontentbottom' # 'footer' | 'header' | 'incontext'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    54
    
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    55
    def call(self, view):
529
6e84e93fa7ec EntityVComponent should now implements cell_call
sylvain.thenault@logilab.fr
parents: 330
diff changeset
    56
        return self.cell_call(0, 0, view)
6e84e93fa7ec EntityVComponent should now implements cell_call
sylvain.thenault@logilab.fr
parents: 330
diff changeset
    57
6e84e93fa7ec EntityVComponent should now implements cell_call
sylvain.thenault@logilab.fr
parents: 330
diff changeset
    58
    def cell_call(self, row, col, view):
6e84e93fa7ec EntityVComponent should now implements cell_call
sylvain.thenault@logilab.fr
parents: 330
diff changeset
    59
        raise NotImplementedError()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
    
661
4f61eb8a96b7 properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents: 659
diff changeset
    62
class NavigationComponent(Component):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
    """abstract base class for navigation components"""
655
ca3c4992c7d1 kill [Singleton]VComponent
sylvain.thenault@logilab.fr
parents: 652
diff changeset
    64
    id = 'navigation'
742
99115e029dca replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 687
diff changeset
    65
    __select__ = paginated_rset()
655
ca3c4992c7d1 kill [Singleton]VComponent
sylvain.thenault@logilab.fr
parents: 652
diff changeset
    66
    
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
    page_size_property = 'navigation.page-size'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
    start_param = '__start'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
    stop_param = '__stop'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
    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
    71
    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
    72
    previous_page_link_templ = next_page_link_templ = page_link_templ
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    73
    no_previous_page_link = no_next_page_link = u''
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    74
    
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
    def __init__(self, req, rset):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    76
        super(NavigationComponent, self).__init__(req, rset)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    77
        self.starting_from = 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
        self.total = rset.rowcount
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
    def get_page_size(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
        try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
            return self._page_size
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
        except AttributeError:
799
ad129d374ee2 fix page_size handling, use abstract_has_related_entities
sylvain.thenault@logilab.fr
parents: 747
diff changeset
    84
            if 'page_size' in self.extra_kwargs:
ad129d374ee2 fix page_size handling, use abstract_has_related_entities
sylvain.thenault@logilab.fr
parents: 747
diff changeset
    85
                page_size = self.extra_kwargs['page_size']
ad129d374ee2 fix page_size handling, use abstract_has_related_entities
sylvain.thenault@logilab.fr
parents: 747
diff changeset
    86
            elif 'page_size' in self.req.form:
ad129d374ee2 fix page_size handling, use abstract_has_related_entities
sylvain.thenault@logilab.fr
parents: 747
diff changeset
    87
                page_size = int(self.req.form['page_size'])
ad129d374ee2 fix page_size handling, use abstract_has_related_entities
sylvain.thenault@logilab.fr
parents: 747
diff changeset
    88
            else:
ad129d374ee2 fix page_size handling, use abstract_has_related_entities
sylvain.thenault@logilab.fr
parents: 747
diff changeset
    89
                page_size = self.req.property_value(self.page_size_property)
ad129d374ee2 fix page_size handling, use abstract_has_related_entities
sylvain.thenault@logilab.fr
parents: 747
diff changeset
    90
            self._page_size = page_size
ad129d374ee2 fix page_size handling, use abstract_has_related_entities
sylvain.thenault@logilab.fr
parents: 747
diff changeset
    91
            return page_size
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    92
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    93
    def set_page_size(self, page_size):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
        self._page_size = page_size
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
    page_size = property(get_page_size, set_page_size)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
    
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
    def page_boundaries(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
        try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
            stop = int(self.req.form[self.stop_param]) + 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   101
            start = int(self.req.form[self.start_param])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
        except KeyError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
            start, stop = 0, self.page_size
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
        self.starting_from = start
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
        return start, stop
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 clean_params(self, params):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
        if self.start_param in params:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
            del params[self.start_param]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
        if self.stop_param in params:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
            del params[self.stop_param]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   112
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
    def page_link(self, path, params, start, stop, content):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   114
        url = self.build_url(path, **merge_dicts(params, {self.start_param : start,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   115
                                                          self.stop_param : stop,}))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   116
        url = html_escape(url)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   117
        if start == self.starting_from:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   118
            return self.selected_page_link_templ % (url, content, content)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   119
        return self.page_link_templ % (url, content, content)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
    def previous_link(self, params, content='&lt;&lt;', title=_('previous_results')):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   122
        start = self.starting_from
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
        if not start :
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   124
            return self.no_previous_page_link
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
        start = max(0, start - self.page_size)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   126
        stop = start + self.page_size - 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   127
        url = self.build_url(**merge_dicts(params, {self.start_param : start,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   128
                                                    self.stop_param : stop,}))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   129
        url = html_escape(url)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   130
        return self.previous_page_link_templ % (url, title, content)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   131
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   132
    def next_link(self, params, content='&gt;&gt;', title=_('next_results')):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   133
        start = self.starting_from + self.page_size
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   134
        if start >= self.total:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
            return self.no_next_page_link
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   136
        stop = start + self.page_size - 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   137
        url = self.build_url(**merge_dicts(params, {self.start_param : start,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   138
                                                    self.stop_param : stop,}))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
        url = html_escape(url)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   140
        return self.next_page_link_templ % (url, title, content)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   141
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   142
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   143
class RelatedObjectsVComponent(EntityVComponent):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   144
    """a section to display some related entities"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   145
    vid = 'list'
817
12320ff8d6e4 improve selector of RelatedObjectsVComponent: make sure the relation exists before fetching related entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 799
diff changeset
   146
    __select__ = abstract_relation_possible() & abstract_has_related_entities()
799
ad129d374ee2 fix page_size handling, use abstract_has_related_entities
sylvain.thenault@logilab.fr
parents: 747
diff changeset
   147
    
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   148
    def rql(self):
655
ca3c4992c7d1 kill [Singleton]VComponent
sylvain.thenault@logilab.fr
parents: 652
diff changeset
   149
        """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
   150
        return None
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   151
    
529
6e84e93fa7ec EntityVComponent should now implements cell_call
sylvain.thenault@logilab.fr
parents: 330
diff changeset
   152
    def cell_call(self, row, col, view=None):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
        rql = self.rql()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
        if rql is None:
529
6e84e93fa7ec EntityVComponent should now implements cell_call
sylvain.thenault@logilab.fr
parents: 330
diff changeset
   155
            entity = self.rset.get_entity(row, col)
799
ad129d374ee2 fix page_size handling, use abstract_has_related_entities
sylvain.thenault@logilab.fr
parents: 747
diff changeset
   156
            rset = entity.related(self.rtype, role(self))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   157
        else:
529
6e84e93fa7ec EntityVComponent should now implements cell_call
sylvain.thenault@logilab.fr
parents: 330
diff changeset
   158
            eid = self.rset[row][col]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   159
            rset = self.req.execute(self.rql(), {'x': eid}, 'x')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   160
        if not rset.rowcount:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   161
            return
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   162
        self.w(u'<div class="%s">' % self.div_class())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   163
        self.wview(self.vid, rset, title=self.req._(self.title).capitalize())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   164
        self.w(u'</div>')
661
4f61eb8a96b7 properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents: 659
diff changeset
   165
4f61eb8a96b7 properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents: 659
diff changeset
   166
681
7cb402fa3958 use class_renamed, not class_moved
sylvain.thenault@logilab.fr
parents: 670
diff changeset
   167
VComponent = class_renamed('VComponent', Component,
7cb402fa3958 use class_renamed, not class_moved
sylvain.thenault@logilab.fr
parents: 670
diff changeset
   168
                           'VComponent is deprecated, use Component')
7cb402fa3958 use class_renamed, not class_moved
sylvain.thenault@logilab.fr
parents: 670
diff changeset
   169
SingletonVComponent = class_renamed('SingletonVComponent', Component,
7cb402fa3958 use class_renamed, not class_moved
sylvain.thenault@logilab.fr
parents: 670
diff changeset
   170
                                    'SingletonVComponent is deprecated, use '
7cb402fa3958 use class_renamed, not class_moved
sylvain.thenault@logilab.fr
parents: 670
diff changeset
   171
                                    'Component and explicit registration control')