common/selectors.py
author Emile Anclin <emile.anclin@logilab.fr>
Thu, 02 Apr 2009 18:57:24 +0200
changeset 1221 d474534fd04d
parent 1118 8ad7737fc458
child 1263 01152fffd593
permissions -rw-r--r--
[doc] improve Concept explainings
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     1
"""This file contains some basic selectors required by application objects.
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
A selector is responsible to score how well an object may be used with a
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     4
given result set (publishing time selection)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     5
333
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
     6
If you have trouble with selectors, especially if the objet (typically
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
     7
a view or a component) you want to use is not selected and you want to
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
     8
know which one(s) of its selectors fail (e.g. returns 0), you can use
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
     9
`traced_selection` or even direclty `TRACED_OIDS`.
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    10
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    11
`TRACED_OIDS` is a tuple of traced object ids. The special value
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    12
'all' may be used to log selectors for all objects.
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    13
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    14
For instance, say that the following code yields a `NoSelectableObject`
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    15
exception::
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    16
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    17
    self.view('calendar', myrset)
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    18
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    19
You can log the selectors involved for *calendar* by replacing the line
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    20
above by::
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    21
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    22
    # in Python2.5
560
005f78d21fc7 [selectors] fix inline doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 446
diff changeset
    23
    from cubicweb.common.selectors import traced_selection
333
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    24
    with traced_selection():
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    25
        self.view('calendar', myrset)
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    26
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    27
    # in Python2.4
560
005f78d21fc7 [selectors] fix inline doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 446
diff changeset
    28
    from cubicweb.common import selectors
333
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    29
    selectors.TRACED_OIDS = ('calendar',)
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    30
    self.view('calendar', myrset)
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    31
    selectors.TRACED_OIDS = ()
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    32
 
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    33
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    34
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
:organization: Logilab
402
sylvain.thenault@logilab.fr
parents: 394
diff changeset
    36
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
__docformat__ = "restructuredtext en"
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    41
333
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    42
import logging
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    43
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
from logilab.common.compat import all
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
    45
from logilab.common.deprecation import deprecated_function
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
230
6e71adc5ccdd new has_related_entities selector
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 215
diff changeset
    47
from cubicweb import Unauthorized, NoSelectableObject, role
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
from cubicweb.cwvreg import DummyCursorError
149
a7cd4296a85e cleaning code
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 148
diff changeset
    49
from cubicweb.vregistry import chainall, chainfirst, NoSelectableObject
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
from cubicweb.cwconfig import CubicWebConfiguration
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    51
from cubicweb.schema import split_expression
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
333
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    53
# helpers for debugging selectors
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    54
SELECTOR_LOGGER = logging.getLogger('cubicweb.selectors')
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    55
TRACED_OIDS = ()
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    56
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    57
def lltrace(selector):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    58
    # don't wrap selectors if not in development mode
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
    if CubicWebConfiguration.mode == 'installed':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
        return selector
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
    def traced(cls, *args, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
        ret = selector(cls, *args, **kwargs)
333
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    63
        if TRACED_OIDS == 'all' or cls.id in TRACED_OIDS:
1118
8ad7737fc458 use critical severity so it shows up during test execution
sylvain.thenault@logilab.fr
parents: 593
diff changeset
    64
            SELECTOR_LOGGER.critical('selector %s returned %s for %s', selector.__name__, ret, cls)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
        return ret
429
10854a2f9c03 some changes to make update to new selector names easier
sylvain.thenault@logilab.fr
parents: 402
diff changeset
    66
    traced.__name__ = selector.__name__
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
    return traced
333
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    68
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    69
class traced_selection(object):
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    70
    """selector debugging helper.
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    71
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    72
    Typical usage is :
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    73
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    74
    >>> with traced_selection():
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    75
    ...     # some code in which you want to debug selectors
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    76
    ...     # for all objects
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    77
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    78
    or
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    79
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    80
    >>> with traced_selection( ('oid1', 'oid2') ):
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    81
    ...     # some code in which you want to debug selectors
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    82
    ...     # for objects with id 'oid1' and 'oid2'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
    
333
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    84
    """
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    85
    def __init__(self, traced='all'):
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    86
        self.traced = traced
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    87
        
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    88
    def __enter__(self):
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    89
        global TRACED_OIDS
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    90
        TRACED_OIDS = self.traced
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    91
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    92
    def __exit__(self, exctype, exc, traceback):
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    93
        global TRACED_OIDS
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    94
        TRACED_OIDS = ()
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    95
        return traceback is None
c65eccf85895 simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 266
diff changeset
    96
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
# very basic selectors ########################################################
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
    99
def yes(cls, *args, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
    """accept everything"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   101
    return 1
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   102
yes_selector = deprecated_function(yes)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
@lltrace
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   105
def none_rset(cls, req, rset, *args, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
    """accept no result set"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
    if rset is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
        return 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
    return 0
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   110
norset_selector = deprecated_function(none_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   112
@lltrace
430
6fbc0ab79a2d any_rset is a better name than rset
sylvain.thenault@logilab.fr
parents: 429
diff changeset
   113
def any_rset(cls, req, rset, *args, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   114
    """accept result set, whatever the number of result"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   115
    if rset is not None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   116
        return 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   117
    return 0
430
6fbc0ab79a2d any_rset is a better name than rset
sylvain.thenault@logilab.fr
parents: 429
diff changeset
   118
rset_selector = deprecated_function(any_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   119
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
@lltrace
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   121
def nonempty_rset(cls, req, rset, *args, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   122
    """accept any non empty result set"""
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   123
    if rset is not None and rset.rowcount:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   124
        return 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
    return 0
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   126
anyrset_selector = deprecated_function(nonempty_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   127
    
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   128
@lltrace
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   129
def empty_rset(cls, req, rset, *args, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   130
    """accept empty result set"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   131
    if rset is not None and rset.rowcount == 0:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   132
        return 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   133
    return 0
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   134
emptyrset_selector = deprecated_function(empty_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   136
@lltrace
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   137
def one_line_rset(cls, req, rset, row=None, *args, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   138
    """accept result set with a single line of result"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
    if rset is not None and (row is not None or rset.rowcount == 1):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   140
        return 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   141
    return 0
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   142
onelinerset_selector = deprecated_function(one_line_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   143
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   144
@lltrace
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   145
def two_lines_rset(cls, req, rset, *args, **kwargs):
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   146
    """accept result set with *at least* two lines of result"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   147
    if rset is not None and rset.rowcount > 1:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   148
        return 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   149
    return 0
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   150
twolinerset_selector = deprecated_function(two_lines_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   151
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   152
@lltrace
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   153
def two_cols_rset(cls, req, rset, *args, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
    """accept result set with at least one line and two columns of result"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   155
    if rset is not None and rset.rowcount > 0 and len(rset.rows[0]) > 1:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
        return 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   157
    return 0
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   158
twocolrset_selector = deprecated_function(two_cols_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   159
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   160
@lltrace
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   161
def paginated_rset(cls, req, rset, *args, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   162
    """accept result sets with more rows than the page size
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   163
    """
591
9eeb3d0a4463 get custom page_size as argument
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 560
diff changeset
   164
    page_size = kwargs.get('page_size')
9eeb3d0a4463 get custom page_size as argument
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 560
diff changeset
   165
    if page_size is None:
593
6f6549780096 page_size can be given in url attributes
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 591
diff changeset
   166
        page_size = req.form.get('page_size')
6f6549780096 page_size can be given in url attributes
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 591
diff changeset
   167
        if page_size is None:
6f6549780096 page_size can be given in url attributes
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 591
diff changeset
   168
            page_size = req.property_value('navigation.page-size')
6f6549780096 page_size can be given in url attributes
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 591
diff changeset
   169
        else:
6f6549780096 page_size can be given in url attributes
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 591
diff changeset
   170
            page_size = int(page_size)
591
9eeb3d0a4463 get custom page_size as argument
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 560
diff changeset
   171
    if rset is None or len(rset) <= page_size:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   172
        return 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   173
    return 1
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   174
largerset_selector = deprecated_function(paginated_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   175
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   176
@lltrace
591
9eeb3d0a4463 get custom page_size as argument
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 560
diff changeset
   177
def sorted_rset(cls, req, rset, row=None, col=None, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   178
    """accept sorted result set"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   179
    rqlst = rset.syntax_tree()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   180
    if len(rqlst.children) > 1 or not rqlst.children[0].orderby:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   181
        return 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   182
    return 2
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   183
sortedrset_selector = deprecated_function(sorted_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   184
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   185
@lltrace
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   186
def one_etype_rset(cls, req, rset, *args, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   187
    """accept result set where entities in the first columns are all of the
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   188
    same type
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   189
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   190
    if len(rset.column_types(0)) != 1:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   191
        return 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   192
    return 1
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   193
oneetyperset_selector = deprecated_function(one_etype_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   194
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   195
@lltrace
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   196
def two_etypes_rset(cls, req, rset, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   197
    """accepts resultsets containing several entity types"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   198
    if rset:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   199
        etypes = rset.column_types(0)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   200
        if len(etypes) > 1:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   201
            return 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   202
    return 0
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   203
multitype_selector = deprecated_function(two_etypes_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   204
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   205
@lltrace
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   206
def match_search_state(cls, req, rset, row=None, col=None, **kwargs):
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   207
    """checks if the current search state is in a .search_states attribute of
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   208
    the wrapped class
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   209
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   210
    search state should be either 'normal' or 'linksearch' (eg searching for an
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   211
    object to create a relation with another)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   212
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   213
    try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   214
        if not req.search_state[0] in cls.search_states:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   215
            return 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   216
    except AttributeError:
352
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 333
diff changeset
   217
        return 1 # class doesn't care about search state, accept it
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   218
    return 1
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   219
searchstate_selector = deprecated_function(match_search_state)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   220
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   221
@lltrace
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   222
def anonymous_user(cls, req, *args, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   223
    """accept if user is anonymous"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   224
    if req.cnx.anonymous_connection:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   225
        return 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   226
    return 0
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   227
anonymous_selector = deprecated_function(anonymous_user)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   228
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   229
@lltrace
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   230
def authenticated_user(cls, req, *args, **kwargs):
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   231
    """accept if user is authenticated"""
431
18b4dd650ef8 massive selector update
sylvain.thenault@logilab.fr
parents: 430
diff changeset
   232
    return not anonymous_user(cls, req, *args, **kwargs)
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   233
not_anonymous_selector = deprecated_function(authenticated_user)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   234
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   235
@lltrace
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   236
def match_form_params(cls, req, *args, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   237
    """check if parameters specified by the form_params attribute on
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   238
    the wrapped class are specified in request form parameters
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   239
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   240
    score = 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   241
    for param in cls.form_params:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   242
        val = req.form.get(param)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   243
        if not val:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   244
            return 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   245
        score += 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   246
    return score + 1
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   247
req_form_params_selector = deprecated_function(match_form_params)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   248
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   249
@lltrace
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   250
def match_kwargs(cls, req, *args, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   251
    """check if arguments specified by the expected_kwargs attribute on
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   252
    the wrapped class are specified in given named parameters
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   253
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   254
    values = []
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   255
    for arg in cls.expected_kwargs:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   256
        if not arg in kwargs:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   257
            return 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   258
    return 1
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   259
kwargs_selector = deprecated_function(match_kwargs)
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   260
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   261
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   262
# not so basic selectors ######################################################
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   263
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   264
@lltrace
237
3df2e0ae2eba begin selector renaming (work in progress)
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 236
diff changeset
   265
def accept_etype(cls, req, *args, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   266
    """check etype presence in request form *and* accepts conformance"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   267
    if 'etype' not in req.form and 'etype' not in kwargs:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   268
        return 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   269
    try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   270
        etype = req.form['etype']
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   271
    except KeyError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   272
        etype = kwargs['etype']
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   273
    # value is a list or a tuple if web request form received several
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   274
    # values for etype parameter
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   275
    assert isinstance(etype, basestring), "got multiple etype parameters in req.form"
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   276
    if 'Any' in cls.accepts:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   277
        return 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   278
    # no Any found, we *need* exact match
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   279
    if etype not in cls.accepts:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   280
        return 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   281
    # exact match must return a greater value than 'Any'-match
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   282
    return 2
237
3df2e0ae2eba begin selector renaming (work in progress)
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 236
diff changeset
   283
etype_form_selector = deprecated_function(accept_etype)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   284
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   285
@lltrace
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   286
def _non_final_entity(cls, req, rset, row=None, col=None, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   287
    """accept non final entities
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   288
    if row is not specified, use the first one
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   289
    if col is not specified, use the first one
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   290
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   291
    etype = rset.description[row or 0][col or 0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   292
    if etype is None: # outer join
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   293
        return 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   294
    if cls.schema.eschema(etype).is_final():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   295
        return 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   296
    return 1
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   297
_nfentity_selector = deprecated_function(_non_final_entity)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   298
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   299
@lltrace
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   300
def _rql_condition(cls, req, rset, row=None, col=None, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   301
    """accept single entity result set if the entity match an rql condition
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   302
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   303
    if cls.condition:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   304
        eid = rset[row or 0][col or 0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   305
        if 'U' in frozenset(split_expression(cls.condition)):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   306
            rql = 'Any X WHERE X eid %%(x)s, U eid %%(u)s, %s' % cls.condition
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   307
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   308
            rql = 'Any X WHERE X eid %%(x)s, %s' % cls.condition
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   309
        try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   310
            return len(req.execute(rql, {'x': eid, 'u': req.user.eid}, 'x'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   311
        except Unauthorized:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   312
            return 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   313
        
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   314
    return 1
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   315
_rqlcondition_selector = deprecated_function(_rql_condition)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   316
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   317
@lltrace
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   318
def _implement_interface(cls, req, rset, row=None, col=None, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   319
    """accept uniform result sets, and apply the following rules:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   320
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   321
    * wrapped class must have a accepts_interfaces attribute listing the
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   322
      accepted ORed interfaces
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   323
    * if row is None, return the sum of values returned by the method
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   324
      for each entity's class in the result set. If any score is 0,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   325
      return 0.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   326
    * if row is specified, return the value returned by the method with
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   327
      the entity's class of this row
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   328
    """
184
92aebc6b533c fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 162
diff changeset
   329
    # XXX this selector can be refactored : extract the code testing
92aebc6b533c fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 162
diff changeset
   330
    #     for entity schema / interface compliance
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   331
    score = 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   332
    # check 'accepts' to give priority to more specific classes
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   333
    if row is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   334
        for etype in rset.column_types(col or 0):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   335
            eclass = cls.vreg.etype_class(etype)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   336
            escore = 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   337
            for iface in cls.accepts_interfaces:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   338
                escore += iface.is_implemented_by(eclass)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   339
            if not escore:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   340
                return 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   341
            score += escore
184
92aebc6b533c fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 162
diff changeset
   342
            accepts = set(getattr(cls, 'accepts', ()))
92aebc6b533c fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 162
diff changeset
   343
            # if accepts is defined on the vobject, eclass must match
92aebc6b533c fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 162
diff changeset
   344
            if accepts:
92aebc6b533c fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 162
diff changeset
   345
                eschema = eclass.e_schema
92aebc6b533c fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 162
diff changeset
   346
                etypes = set([eschema] + eschema.ancestors())
92aebc6b533c fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 162
diff changeset
   347
                if accepts & etypes:
92aebc6b533c fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 162
diff changeset
   348
                    score += 2
92aebc6b533c fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 162
diff changeset
   349
                elif 'Any' not in accepts:
92aebc6b533c fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 162
diff changeset
   350
                    return 0
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   351
        return score + 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   352
    etype = rset.description[row][col or 0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   353
    if etype is None: # outer join
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   354
        return 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   355
    eclass = cls.vreg.etype_class(etype)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   356
    for iface in cls.accepts_interfaces:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   357
        score += iface.is_implemented_by(eclass)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   358
    if score:
184
92aebc6b533c fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 162
diff changeset
   359
        accepts = set(getattr(cls, 'accepts', ()))
92aebc6b533c fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 162
diff changeset
   360
        # if accepts is defined on the vobject, eclass must match
92aebc6b533c fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 162
diff changeset
   361
        if accepts:
92aebc6b533c fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 162
diff changeset
   362
            eschema = eclass.e_schema
92aebc6b533c fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 162
diff changeset
   363
            etypes = set([eschema] + eschema.ancestors())
92aebc6b533c fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 162
diff changeset
   364
            if accepts & etypes:
92aebc6b533c fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 162
diff changeset
   365
                score += 1
92aebc6b533c fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 162
diff changeset
   366
            elif 'Any' not in accepts:
92aebc6b533c fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 162
diff changeset
   367
                return 0
92aebc6b533c fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 162
diff changeset
   368
        score += 1
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   369
    return score
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   370
_interface_selector = deprecated_function(_implement_interface)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   371
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   372
@lltrace
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   373
def score_entity_selector(cls, req, rset, row=None, col=None, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   374
    if row is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   375
        rows = xrange(rset.rowcount)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   376
    else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   377
        rows = (row,)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   378
    for row in rows:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   379
        try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   380
            score = cls.score_entity(rset.get_entity(row, col or 0))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   381
        except DummyCursorError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   382
            # get a dummy cursor error, that means we are currently
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   383
            # using a dummy rset to list possible views for an entity
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   384
            # type, not for an actual result set. In that case, we
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   385
            # don't care of the value, consider the object as selectable
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   386
            return 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   387
        if not score:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   388
            return 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   389
    return 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   390
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   391
@lltrace
237
3df2e0ae2eba begin selector renaming (work in progress)
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 236
diff changeset
   392
def accept_rset(cls, req, rset, row=None, col=None, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   393
    """simply delegate to cls.accept_rset method"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   394
    return cls.accept_rset(req, rset, row=row, col=col)
237
3df2e0ae2eba begin selector renaming (work in progress)
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 236
diff changeset
   395
accept_rset_selector = deprecated_function(accept_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   396
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   397
@lltrace
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   398
def but_etype(cls, req, rset, row=None, col=None, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   399
    """restrict the searchstate_accept_one_selector to exclude entity's type
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   400
    refered by the .etype attribute
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   401
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   402
    if rset.description[row or 0][col or 0] == cls.etype:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   403
        return 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   404
    return 1
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   405
but_etype_selector = deprecated_function(but_etype)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   406
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   407
@lltrace
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   408
def etype_rtype_selector(cls, req, rset, row=None, col=None, **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   409
    """only check if the user has read access on the entity's type refered
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   410
    by the .etype attribute and on the relations's type refered by the
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   411
    .rtype attribute if set.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   412
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   413
    schema = cls.schema
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   414
    perm = getattr(cls, 'require_permission', 'read')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   415
    if hasattr(cls, 'etype'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   416
        eschema = schema.eschema(cls.etype)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   417
        if not (eschema.has_perm(req, perm) or eschema.has_local_role(perm)):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   418
            return 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   419
    if hasattr(cls, 'rtype'):
394
1cc99ab21304 fix w/ local roles
sylvain.thenault@logilab.fr
parents: 367
diff changeset
   420
        rschema = schema.rschema(cls.rtype)
1cc99ab21304 fix w/ local roles
sylvain.thenault@logilab.fr
parents: 367
diff changeset
   421
        if not (rschema.has_perm(req, perm) or rschema.has_local_role(perm)):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   422
            return 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   423
    return 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   424
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   425
@lltrace
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   426
def has_relation(cls, req, rset, row=None, col=None, **kwargs):
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   427
    """check if the user has read access on the relations's type refered by the
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   428
    .rtype attribute of the class, and if all entities types in the
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   429
    result set has this relation.
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   430
    """
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   431
    if hasattr(cls, 'rtype'):
394
1cc99ab21304 fix w/ local roles
sylvain.thenault@logilab.fr
parents: 367
diff changeset
   432
        rschema = cls.schema.rschema(cls.rtype)
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   433
        perm = getattr(cls, 'require_permission', 'read')
394
1cc99ab21304 fix w/ local roles
sylvain.thenault@logilab.fr
parents: 367
diff changeset
   434
        if not (rschema.has_perm(req, perm) or rschema.has_local_role(perm)):
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   435
            return 0
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   436
        if row is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   437
            for etype in rset.column_types(col or 0):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   438
                if not cls.relation_possible(etype):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   439
                    return 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   440
        elif not cls.relation_possible(rset.description[row][col or 0]):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   441
            return 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   442
    return 1
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   443
accept_rtype_selector = deprecated_function(has_relation)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   444
237
3df2e0ae2eba begin selector renaming (work in progress)
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 236
diff changeset
   445
@lltrace
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   446
def one_has_relation(cls, req, rset, row=None, col=None, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   447
    """check if the user has read access on the relations's type refered by the
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   448
    .rtype attribute of the class, and if at least one entity type in the
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   449
    result set has this relation.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   450
    """
394
1cc99ab21304 fix w/ local roles
sylvain.thenault@logilab.fr
parents: 367
diff changeset
   451
    rschema = cls.schema.rschema(cls.rtype)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   452
    perm = getattr(cls, 'require_permission', 'read')
394
1cc99ab21304 fix w/ local roles
sylvain.thenault@logilab.fr
parents: 367
diff changeset
   453
    if not (rschema.has_perm(req, perm) or rschema.has_local_role(perm)):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   454
        return 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   455
    if row is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   456
        for etype in rset.column_types(col or 0):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   457
            if cls.relation_possible(etype):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   458
                return 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   459
    elif cls.relation_possible(rset.description[row][col or 0]):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   460
        return 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   461
    return 0
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   462
one_has_relation_selector = deprecated_function(one_has_relation)
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   463
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   464
@lltrace
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   465
def has_related_entities(cls, req, rset, row=None, col=None, **kwargs):
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   466
    return bool(rset.get_entity(row or 0, col or 0).related(cls.rtype, role(cls)))
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   467
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   468
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   469
@lltrace
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   470
def match_user_group(cls, req, rset=None, row=None, col=None, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   471
    """select according to user's groups"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   472
    if not cls.require_groups:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   473
        return 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   474
    user = req.user
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   475
    if user is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   476
        return int('guests' in cls.require_groups)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   477
    score = 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   478
    if 'owners' in cls.require_groups and rset:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   479
        if row is not None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   480
            eid = rset[row][col or 0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   481
            if user.owns(eid):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   482
                score = 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   483
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   484
            score = all(user.owns(r[col or 0]) for r in rset)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   485
    score += user.matching_groups(cls.require_groups)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   486
    if score:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   487
        # add 1 so that an object with one matching group take priority
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   488
        # on an object without require_groups
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   489
        return score + 1 
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   490
    return 0
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   491
in_group_selector = deprecated_function(match_user_group)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   492
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   493
@lltrace
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   494
def user_can_add_etype(cls, req, rset, row=None, col=None, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   495
    """only check if the user has add access on the entity's type refered
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   496
    by the .etype attribute.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   497
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   498
    if not cls.schema.eschema(cls.etype).has_perm(req, 'add'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   499
        return 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   500
    return 1
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   501
add_etype_selector = deprecated_function(user_can_add_etype)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   502
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   503
@lltrace
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   504
def match_context_prop(cls, req, rset, row=None, col=None, context=None,
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   505
                       **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   506
    propval = req.property_value('%s.%s.context' % (cls.__registry__, cls.id))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   507
    if not propval:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   508
        propval = cls.context
446
3a3ab6bbccc5 use empty string instead of None as possible context value to avoid getting an <optgroup> tag in associated widget
sylvain.thenault@logilab.fr
parents: 431
diff changeset
   509
    if context is not None and propval and context != propval:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   510
        return 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   511
    return 1
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   512
contextprop_selector = deprecated_function(match_context_prop)
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
@lltrace
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   515
def primary_view(cls, req, rset, row=None, col=None, view=None,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   516
                          **kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   517
    if view is not None and not view.is_primary():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   518
        return 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   519
    return 1
236
8ab9e72dd8f1 begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 230
diff changeset
   520
primaryview_selector = deprecated_function(primary_view)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   521
142
0425ee84cfa6 add selector to test if result set is an object (for rss feed component)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 0
diff changeset
   522
def appobject_selectable(registry, oid):
161
328bc32b5701 repairing error from preceding commit
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 157
diff changeset
   523
    """return a selector that will have a positive score if an object for the
328bc32b5701 repairing error from preceding commit
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 157
diff changeset
   524
    given registry and object id is selectable for the input context
328bc32b5701 repairing error from preceding commit
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 157
diff changeset
   525
    """
142
0425ee84cfa6 add selector to test if result set is an object (for rss feed component)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 0
diff changeset
   526
    @lltrace
0425ee84cfa6 add selector to test if result set is an object (for rss feed component)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 0
diff changeset
   527
    def selector(cls, req, rset, *args, **kwargs):
0425ee84cfa6 add selector to test if result set is an object (for rss feed component)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 0
diff changeset
   528
        try:
0425ee84cfa6 add selector to test if result set is an object (for rss feed component)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 0
diff changeset
   529
            cls.vreg.select_object(registry, oid, req, rset, *args, **kwargs)
0425ee84cfa6 add selector to test if result set is an object (for rss feed component)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 0
diff changeset
   530
            return 1
0425ee84cfa6 add selector to test if result set is an object (for rss feed component)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 0
diff changeset
   531
        except NoSelectableObject:
0425ee84cfa6 add selector to test if result set is an object (for rss feed component)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 0
diff changeset
   532
            return 0
0425ee84cfa6 add selector to test if result set is an object (for rss feed component)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 0
diff changeset
   533
    return selector
0425ee84cfa6 add selector to test if result set is an object (for rss feed component)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 0
diff changeset
   534
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   535
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   536
# compound selectors ##########################################################
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   537
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   538
non_final_entity = chainall(nonempty_rset, _non_final_entity)
429
10854a2f9c03 some changes to make update to new selector names easier
sylvain.thenault@logilab.fr
parents: 402
diff changeset
   539
non_final_entity.__name__ = 'non_final_entity'
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   540
nfentity_selector = deprecated_function(non_final_entity)
237
3df2e0ae2eba begin selector renaming (work in progress)
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 236
diff changeset
   541
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   542
implement_interface = chainall(non_final_entity, _implement_interface)
429
10854a2f9c03 some changes to make update to new selector names easier
sylvain.thenault@logilab.fr
parents: 402
diff changeset
   543
implement_interface.__name__ = 'implement_interface'
237
3df2e0ae2eba begin selector renaming (work in progress)
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 236
diff changeset
   544
interface_selector = deprecated_function(implement_interface)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   545
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   546
accept = chainall(non_final_entity, accept_rset)
429
10854a2f9c03 some changes to make update to new selector names easier
sylvain.thenault@logilab.fr
parents: 402
diff changeset
   547
accept.__name__ = 'accept'
237
3df2e0ae2eba begin selector renaming (work in progress)
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 236
diff changeset
   548
accept_selector = deprecated_function(accept)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   549
429
10854a2f9c03 some changes to make update to new selector names easier
sylvain.thenault@logilab.fr
parents: 402
diff changeset
   550
accept_one = chainall(one_line_rset, accept)
10854a2f9c03 some changes to make update to new selector names easier
sylvain.thenault@logilab.fr
parents: 402
diff changeset
   551
accept_one.__name__ = 'accept_one'
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   552
accept_one_selector = deprecated_function(accept_one)
237
3df2e0ae2eba begin selector renaming (work in progress)
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 236
diff changeset
   553
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   554
rql_condition = chainall(non_final_entity, one_line_rset, _rql_condition)
429
10854a2f9c03 some changes to make update to new selector names easier
sylvain.thenault@logilab.fr
parents: 402
diff changeset
   555
rql_condition.__name__ = 'rql_condition'
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   556
rqlcondition_selector = deprecated_function(rql_condition)
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   557
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   558
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   559
searchstate_accept = chainall(nonempty_rset, match_search_state, accept)
429
10854a2f9c03 some changes to make update to new selector names easier
sylvain.thenault@logilab.fr
parents: 402
diff changeset
   560
searchstate_accept.__name__ = 'searchstate_accept'
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   561
searchstate_accept_selector = deprecated_function(searchstate_accept)
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   562
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   563
searchstate_accept_one = chainall(one_line_rset, match_search_state,
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   564
                                  accept, _rql_condition)
429
10854a2f9c03 some changes to make update to new selector names easier
sylvain.thenault@logilab.fr
parents: 402
diff changeset
   565
searchstate_accept_one.__name__ = 'searchstate_accept_one'
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   566
searchstate_accept_one_selector = deprecated_function(searchstate_accept_one)
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   567
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   568
searchstate_accept_one_but_etype = chainall(searchstate_accept_one, but_etype)
429
10854a2f9c03 some changes to make update to new selector names easier
sylvain.thenault@logilab.fr
parents: 402
diff changeset
   569
searchstate_accept_one_but_etype.__name__ = 'searchstate_accept_one_but_etype'
254
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   570
searchstate_accept_one_but_etype_selector = deprecated_function(
b1eda3dd844a more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 247
diff changeset
   571
    searchstate_accept_one_but_etype)