author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Wed, 07 Jan 2009 14:42:43 +0100 | |
changeset 345 | 31f88b2e3500 |
parent 333 | c65eccf85895 |
child 352 | a1016e33a40c |
permissions | -rw-r--r-- |
0 | 1 |
"""This file contains some basic selectors required by application objects. |
2 |
||
3 |
A selector is responsible to score how well an object may be used with a |
|
4 |
given result set (publishing time selection) |
|
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 |
c65eccf85895
simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
266
diff
changeset
|
23 |
from cubicweb.selectors import traced_selection |
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 |
c65eccf85895
simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
266
diff
changeset
|
28 |
from cubicweb import selectors |
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 | 35 |
:organization: Logilab |
36 |
:copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
37 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
38 |
""" |
|
39 |
||
40 |
__docformat__ = "restructuredtext en" |
|
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 | 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 | 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 | 48 |
from cubicweb.cwvreg import DummyCursorError |
149 | 49 |
from cubicweb.vregistry import chainall, chainfirst, NoSelectableObject |
0 | 50 |
from cubicweb.cwconfig import CubicWebConfiguration |
51 |
from cubicweb.schema import split_expression |
|
52 |
||
53 |
||
333
c65eccf85895
simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
266
diff
changeset
|
54 |
# helpers for debugging selectors |
c65eccf85895
simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
266
diff
changeset
|
55 |
SELECTOR_LOGGER = logging.getLogger('cubicweb.selectors') |
c65eccf85895
simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
266
diff
changeset
|
56 |
TRACED_OIDS = () |
c65eccf85895
simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
266
diff
changeset
|
57 |
|
0 | 58 |
def lltrace(selector): |
59 |
# don't wrap selectors if not in development mode |
|
60 |
if CubicWebConfiguration.mode == 'installed': |
|
61 |
return selector |
|
62 |
def traced(cls, *args, **kwargs): |
|
63 |
ret = selector(cls, *args, **kwargs) |
|
333
c65eccf85895
simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
266
diff
changeset
|
64 |
if TRACED_OIDS == 'all' or cls.id in TRACED_OIDS: |
c65eccf85895
simplify selectors debugging
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
266
diff
changeset
|
65 |
SELECTOR_LOGGER.warning('selector %s returned %s for %s', selector.__name__, ret, cls) |
0 | 66 |
return ret |
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 | 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 | 97 |
# very basic selectors ######################################################## |
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 | 100 |
"""accept everything""" |
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 | 103 |
|
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 | 106 |
"""accept no result set""" |
107 |
if rset is None: |
|
108 |
return 1 |
|
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 | 111 |
|
112 |
@lltrace |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
113 |
def rset(cls, req, rset, *args, **kwargs): |
0 | 114 |
"""accept result set, whatever the number of result""" |
115 |
if rset is not None: |
|
116 |
return 1 |
|
117 |
return 0 |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
118 |
rset_selector = deprecated_function(rset) |
0 | 119 |
|
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 | 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 | 124 |
return 1 |
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 | 127 |
|
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 | 130 |
"""accept empty result set""" |
131 |
if rset is not None and rset.rowcount == 0: |
|
132 |
return 1 |
|
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 | 135 |
|
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 | 138 |
"""accept result set with a single line of result""" |
139 |
if rset is not None and (row is not None or rset.rowcount == 1): |
|
140 |
return 1 |
|
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 | 143 |
|
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 | 147 |
if rset is not None and rset.rowcount > 1: |
148 |
return 1 |
|
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 | 151 |
|
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 | 154 |
"""accept result set with at least one line and two columns of result""" |
155 |
if rset is not None and rset.rowcount > 0 and len(rset.rows[0]) > 1: |
|
156 |
return 1 |
|
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 | 159 |
|
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 | 162 |
"""accept result sets with more rows than the page size |
163 |
""" |
|
164 |
if rset is None or len(rset) <= req.property_value('navigation.page-size'): |
|
165 |
return 0 |
|
166 |
return 1 |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
167 |
largerset_selector = deprecated_function(paginated_rset) |
0 | 168 |
|
169 |
@lltrace |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
170 |
def sorted_rset(cls, req, rset, row=None, col=None): |
0 | 171 |
"""accept sorted result set""" |
172 |
rqlst = rset.syntax_tree() |
|
173 |
if len(rqlst.children) > 1 or not rqlst.children[0].orderby: |
|
174 |
return 0 |
|
175 |
return 2 |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
176 |
sortedrset_selector = deprecated_function(sorted_rset) |
0 | 177 |
|
178 |
@lltrace |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
179 |
def one_etype_rset(cls, req, rset, *args, **kwargs): |
0 | 180 |
"""accept result set where entities in the first columns are all of the |
181 |
same type |
|
182 |
""" |
|
183 |
if len(rset.column_types(0)) != 1: |
|
184 |
return 0 |
|
185 |
return 1 |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
186 |
oneetyperset_selector = deprecated_function(one_etype_rset) |
0 | 187 |
|
188 |
@lltrace |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
189 |
def two_etypes_rset(cls, req, rset, **kwargs): |
0 | 190 |
"""accepts resultsets containing several entity types""" |
191 |
if rset: |
|
192 |
etypes = rset.column_types(0) |
|
193 |
if len(etypes) > 1: |
|
194 |
return 1 |
|
195 |
return 0 |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
196 |
multitype_selector = deprecated_function(two_etypes_rset) |
0 | 197 |
|
198 |
@lltrace |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
199 |
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
|
200 |
"""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
|
201 |
the wrapped class |
0 | 202 |
|
203 |
search state should be either 'normal' or 'linksearch' (eg searching for an |
|
204 |
object to create a relation with another) |
|
205 |
""" |
|
206 |
try: |
|
207 |
if not req.search_state[0] in cls.search_states: |
|
208 |
return 0 |
|
209 |
except AttributeError: |
|
210 |
return 1 # class don't care about search state, accept it |
|
211 |
return 1 |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
212 |
searchstate_selector = deprecated_function(match_search_state) |
0 | 213 |
|
214 |
@lltrace |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
215 |
def anonymous_user(cls, req, *args, **kwargs): |
0 | 216 |
"""accept if user is anonymous""" |
217 |
if req.cnx.anonymous_connection: |
|
218 |
return 1 |
|
219 |
return 0 |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
220 |
anonymous_selector = deprecated_function(anonymous_user) |
0 | 221 |
|
222 |
@lltrace |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
223 |
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
|
224 |
"""accept if user is authenticated""" |
0 | 225 |
return not anonymous_selector(cls, req, *args, **kwargs) |
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
226 |
not_anonymous_selector = deprecated_function(authenticated_user) |
0 | 227 |
|
228 |
@lltrace |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
229 |
def match_form_params(cls, req, *args, **kwargs): |
0 | 230 |
"""check if parameters specified by the form_params attribute on |
231 |
the wrapped class are specified in request form parameters |
|
232 |
""" |
|
233 |
score = 0 |
|
234 |
for param in cls.form_params: |
|
235 |
val = req.form.get(param) |
|
236 |
if not val: |
|
237 |
return 0 |
|
238 |
score += 1 |
|
239 |
return score + 1 |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
240 |
req_form_params_selector = deprecated_function(match_form_params) |
0 | 241 |
|
242 |
@lltrace |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
243 |
def match_kwargs(cls, req, *args, **kwargs): |
0 | 244 |
"""check if arguments specified by the expected_kwargs attribute on |
245 |
the wrapped class are specified in given named parameters |
|
246 |
""" |
|
247 |
values = [] |
|
248 |
for arg in cls.expected_kwargs: |
|
249 |
if not arg in kwargs: |
|
250 |
return 0 |
|
251 |
return 1 |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
252 |
kwargs_selector = deprecated_function(match_kwargs) |
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
253 |
|
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
254 |
|
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
255 |
# not so basic selectors ###################################################### |
0 | 256 |
|
257 |
@lltrace |
|
237
3df2e0ae2eba
begin selector renaming (work in progress)
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
236
diff
changeset
|
258 |
def accept_etype(cls, req, *args, **kwargs): |
0 | 259 |
"""check etype presence in request form *and* accepts conformance""" |
260 |
if 'etype' not in req.form and 'etype' not in kwargs: |
|
261 |
return 0 |
|
262 |
try: |
|
263 |
etype = req.form['etype'] |
|
264 |
except KeyError: |
|
265 |
etype = kwargs['etype'] |
|
266 |
# value is a list or a tuple if web request form received several |
|
267 |
# values for etype parameter |
|
268 |
assert isinstance(etype, basestring), "got multiple etype parameters in req.form" |
|
269 |
if 'Any' in cls.accepts: |
|
270 |
return 1 |
|
271 |
# no Any found, we *need* exact match |
|
272 |
if etype not in cls.accepts: |
|
273 |
return 0 |
|
274 |
# exact match must return a greater value than 'Any'-match |
|
275 |
return 2 |
|
237
3df2e0ae2eba
begin selector renaming (work in progress)
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
236
diff
changeset
|
276 |
etype_form_selector = deprecated_function(accept_etype) |
0 | 277 |
|
278 |
@lltrace |
|
254
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
279 |
def _non_final_entity(cls, req, rset, row=None, col=None, **kwargs): |
0 | 280 |
"""accept non final entities |
281 |
if row is not specified, use the first one |
|
282 |
if col is not specified, use the first one |
|
283 |
""" |
|
284 |
etype = rset.description[row or 0][col or 0] |
|
285 |
if etype is None: # outer join |
|
286 |
return 0 |
|
287 |
if cls.schema.eschema(etype).is_final(): |
|
288 |
return 0 |
|
289 |
return 1 |
|
254
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
290 |
_nfentity_selector = deprecated_function(_non_final_entity) |
0 | 291 |
|
292 |
@lltrace |
|
254
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
293 |
def _rql_condition(cls, req, rset, row=None, col=None, **kwargs): |
0 | 294 |
"""accept single entity result set if the entity match an rql condition |
295 |
""" |
|
296 |
if cls.condition: |
|
297 |
eid = rset[row or 0][col or 0] |
|
298 |
if 'U' in frozenset(split_expression(cls.condition)): |
|
299 |
rql = 'Any X WHERE X eid %%(x)s, U eid %%(u)s, %s' % cls.condition |
|
300 |
else: |
|
301 |
rql = 'Any X WHERE X eid %%(x)s, %s' % cls.condition |
|
302 |
try: |
|
303 |
return len(req.execute(rql, {'x': eid, 'u': req.user.eid}, 'x')) |
|
304 |
except Unauthorized: |
|
305 |
return 0 |
|
306 |
||
307 |
return 1 |
|
254
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
308 |
_rqlcondition_selector = deprecated_function(_rql_condition) |
0 | 309 |
|
310 |
@lltrace |
|
254
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
311 |
def _implement_interface(cls, req, rset, row=None, col=None, **kwargs): |
0 | 312 |
"""accept uniform result sets, and apply the following rules: |
313 |
||
314 |
* wrapped class must have a accepts_interfaces attribute listing the |
|
315 |
accepted ORed interfaces |
|
316 |
* if row is None, return the sum of values returned by the method |
|
317 |
for each entity's class in the result set. If any score is 0, |
|
318 |
return 0. |
|
319 |
* if row is specified, return the value returned by the method with |
|
320 |
the entity's class of this row |
|
321 |
""" |
|
184
92aebc6b533c
fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
162
diff
changeset
|
322 |
# 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
|
323 |
# for entity schema / interface compliance |
0 | 324 |
score = 0 |
325 |
# check 'accepts' to give priority to more specific classes |
|
326 |
if row is None: |
|
327 |
for etype in rset.column_types(col or 0): |
|
328 |
eclass = cls.vreg.etype_class(etype) |
|
329 |
escore = 0 |
|
330 |
for iface in cls.accepts_interfaces: |
|
331 |
escore += iface.is_implemented_by(eclass) |
|
332 |
if not escore: |
|
333 |
return 0 |
|
334 |
score += escore |
|
184
92aebc6b533c
fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
162
diff
changeset
|
335 |
accepts = set(getattr(cls, 'accepts', ())) |
92aebc6b533c
fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
162
diff
changeset
|
336 |
# 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
|
337 |
if accepts: |
92aebc6b533c
fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
162
diff
changeset
|
338 |
eschema = eclass.e_schema |
92aebc6b533c
fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
162
diff
changeset
|
339 |
etypes = set([eschema] + eschema.ancestors()) |
92aebc6b533c
fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
162
diff
changeset
|
340 |
if accepts & etypes: |
92aebc6b533c
fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
162
diff
changeset
|
341 |
score += 2 |
92aebc6b533c
fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
162
diff
changeset
|
342 |
elif 'Any' not in accepts: |
92aebc6b533c
fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
162
diff
changeset
|
343 |
return 0 |
0 | 344 |
return score + 1 |
345 |
etype = rset.description[row][col or 0] |
|
346 |
if etype is None: # outer join |
|
347 |
return 0 |
|
348 |
eclass = cls.vreg.etype_class(etype) |
|
349 |
for iface in cls.accepts_interfaces: |
|
350 |
score += iface.is_implemented_by(eclass) |
|
351 |
if score: |
|
184
92aebc6b533c
fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
162
diff
changeset
|
352 |
accepts = set(getattr(cls, 'accepts', ())) |
92aebc6b533c
fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
162
diff
changeset
|
353 |
# 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
|
354 |
if accepts: |
92aebc6b533c
fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
162
diff
changeset
|
355 |
eschema = eclass.e_schema |
92aebc6b533c
fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
162
diff
changeset
|
356 |
etypes = set([eschema] + eschema.ancestors()) |
92aebc6b533c
fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
162
diff
changeset
|
357 |
if accepts & etypes: |
92aebc6b533c
fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
162
diff
changeset
|
358 |
score += 1 |
92aebc6b533c
fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
162
diff
changeset
|
359 |
elif 'Any' not in accepts: |
92aebc6b533c
fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
162
diff
changeset
|
360 |
return 0 |
92aebc6b533c
fix interface_selector bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
162
diff
changeset
|
361 |
score += 1 |
0 | 362 |
return score |
254
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
363 |
_interface_selector = deprecated_function(_implement_interface) |
0 | 364 |
|
365 |
@lltrace |
|
366 |
def score_entity_selector(cls, req, rset, row=None, col=None, **kwargs): |
|
367 |
if row is None: |
|
368 |
rows = xrange(rset.rowcount) |
|
369 |
else: |
|
370 |
rows = (row,) |
|
371 |
for row in rows: |
|
372 |
try: |
|
373 |
score = cls.score_entity(rset.get_entity(row, col or 0)) |
|
374 |
except DummyCursorError: |
|
375 |
# get a dummy cursor error, that means we are currently |
|
376 |
# using a dummy rset to list possible views for an entity |
|
377 |
# type, not for an actual result set. In that case, we |
|
378 |
# don't care of the value, consider the object as selectable |
|
379 |
return 1 |
|
380 |
if not score: |
|
381 |
return 0 |
|
382 |
return 1 |
|
383 |
||
384 |
@lltrace |
|
237
3df2e0ae2eba
begin selector renaming (work in progress)
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
236
diff
changeset
|
385 |
def accept_rset(cls, req, rset, row=None, col=None, **kwargs): |
0 | 386 |
"""simply delegate to cls.accept_rset method""" |
387 |
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
|
388 |
accept_rset_selector = deprecated_function(accept_rset) |
0 | 389 |
|
390 |
@lltrace |
|
254
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
391 |
def but_etype(cls, req, rset, row=None, col=None, **kwargs): |
0 | 392 |
"""restrict the searchstate_accept_one_selector to exclude entity's type |
393 |
refered by the .etype attribute |
|
394 |
""" |
|
395 |
if rset.description[row or 0][col or 0] == cls.etype: |
|
396 |
return 0 |
|
397 |
return 1 |
|
254
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
398 |
but_etype_selector = deprecated_function(but_etype) |
0 | 399 |
|
400 |
@lltrace |
|
401 |
def etype_rtype_selector(cls, req, rset, row=None, col=None, **kwargs): |
|
402 |
"""only check if the user has read access on the entity's type refered |
|
403 |
by the .etype attribute and on the relations's type refered by the |
|
404 |
.rtype attribute if set. |
|
405 |
""" |
|
406 |
schema = cls.schema |
|
407 |
perm = getattr(cls, 'require_permission', 'read') |
|
408 |
if hasattr(cls, 'etype'): |
|
409 |
eschema = schema.eschema(cls.etype) |
|
410 |
if not (eschema.has_perm(req, perm) or eschema.has_local_role(perm)): |
|
411 |
return 0 |
|
412 |
if hasattr(cls, 'rtype'): |
|
413 |
if not schema.rschema(cls.rtype).has_perm(req, perm): |
|
414 |
return 0 |
|
415 |
return 1 |
|
416 |
||
417 |
@lltrace |
|
254
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
418 |
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
|
419 |
"""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
|
420 |
.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
|
421 |
result set has this relation. |
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
422 |
""" |
0 | 423 |
if hasattr(cls, 'rtype'): |
254
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
424 |
perm = getattr(cls, 'require_permission', 'read') |
266 | 425 |
if not cls.schema.rschema(cls.rtype).has_perm(req, perm): |
254
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
426 |
return 0 |
0 | 427 |
if row is None: |
428 |
for etype in rset.column_types(col or 0): |
|
429 |
if not cls.relation_possible(etype): |
|
430 |
return 0 |
|
431 |
elif not cls.relation_possible(rset.description[row][col or 0]): |
|
432 |
return 0 |
|
433 |
return 1 |
|
254
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
434 |
accept_rtype_selector = deprecated_function(has_relation) |
0 | 435 |
|
237
3df2e0ae2eba
begin selector renaming (work in progress)
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
236
diff
changeset
|
436 |
@lltrace |
254
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
437 |
def one_has_relation(cls, req, rset, row=None, col=None, **kwargs): |
0 | 438 |
"""check if the user has read access on the relations's type refered by the |
439 |
.rtype attribute of the class, and if at least one entity type in the |
|
440 |
result set has this relation. |
|
441 |
""" |
|
442 |
perm = getattr(cls, 'require_permission', 'read') |
|
266 | 443 |
if not cls.schema.rschema(cls.rtype).has_perm(req, perm): |
0 | 444 |
return 0 |
445 |
if row is None: |
|
446 |
for etype in rset.column_types(col or 0): |
|
447 |
if cls.relation_possible(etype): |
|
448 |
return 1 |
|
449 |
elif cls.relation_possible(rset.description[row][col or 0]): |
|
450 |
return 1 |
|
451 |
return 0 |
|
254
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
452 |
one_has_relation_selector = deprecated_function(one_has_relation) |
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
453 |
|
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
454 |
@lltrace |
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
455 |
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
|
456 |
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
|
457 |
|
0 | 458 |
|
459 |
@lltrace |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
460 |
def match_user_group(cls, req, rset=None, row=None, col=None, **kwargs): |
0 | 461 |
"""select according to user's groups""" |
462 |
if not cls.require_groups: |
|
463 |
return 1 |
|
464 |
user = req.user |
|
465 |
if user is None: |
|
466 |
return int('guests' in cls.require_groups) |
|
467 |
score = 0 |
|
468 |
if 'owners' in cls.require_groups and rset: |
|
469 |
if row is not None: |
|
470 |
eid = rset[row][col or 0] |
|
471 |
if user.owns(eid): |
|
472 |
score = 1 |
|
473 |
else: |
|
474 |
score = all(user.owns(r[col or 0]) for r in rset) |
|
475 |
score += user.matching_groups(cls.require_groups) |
|
476 |
if score: |
|
477 |
# add 1 so that an object with one matching group take priority |
|
478 |
# on an object without require_groups |
|
479 |
return score + 1 |
|
480 |
return 0 |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
481 |
in_group_selector = deprecated_function(match_user_group) |
0 | 482 |
|
483 |
@lltrace |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
484 |
def user_can_add_etype(cls, req, rset, row=None, col=None, **kwargs): |
0 | 485 |
"""only check if the user has add access on the entity's type refered |
486 |
by the .etype attribute. |
|
487 |
""" |
|
488 |
if not cls.schema.eschema(cls.etype).has_perm(req, 'add'): |
|
489 |
return 0 |
|
490 |
return 1 |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
491 |
add_etype_selector = deprecated_function(user_can_add_etype) |
0 | 492 |
|
493 |
@lltrace |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
494 |
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
|
495 |
**kwargs): |
0 | 496 |
propval = req.property_value('%s.%s.context' % (cls.__registry__, cls.id)) |
497 |
if not propval: |
|
498 |
propval = cls.context |
|
499 |
if context is not None and propval is not None and context != propval: |
|
500 |
return 0 |
|
501 |
return 1 |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
502 |
contextprop_selector = deprecated_function(match_context_prop) |
0 | 503 |
|
504 |
@lltrace |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
505 |
def primary_view(cls, req, rset, row=None, col=None, view=None, |
0 | 506 |
**kwargs): |
507 |
if view is not None and not view.is_primary(): |
|
508 |
return 0 |
|
509 |
return 1 |
|
236
8ab9e72dd8f1
begin renaming for selectors, keeping bw compat
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
230
diff
changeset
|
510 |
primaryview_selector = deprecated_function(primary_view) |
0 | 511 |
|
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
|
512 |
def appobject_selectable(registry, oid): |
161
328bc32b5701
repairing error from preceding commit
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
157
diff
changeset
|
513 |
"""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
|
514 |
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
|
515 |
""" |
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
|
516 |
@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
|
517 |
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
|
518 |
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
|
519 |
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
|
520 |
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
|
521 |
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
|
522 |
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
|
523 |
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
|
524 |
|
0 | 525 |
|
526 |
# compound selectors ########################################################## |
|
527 |
||
254
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
528 |
non_final_entity = chainall(nonempty_rset, _non_final_entity) |
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
529 |
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
|
530 |
|
254
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
531 |
implement_interface = chainall(non_final_entity, _implement_interface) |
237
3df2e0ae2eba
begin selector renaming (work in progress)
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
236
diff
changeset
|
532 |
interface_selector = deprecated_function(implement_interface) |
0 | 533 |
|
254
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
534 |
accept = chainall(non_final_entity, accept_rset) |
237
3df2e0ae2eba
begin selector renaming (work in progress)
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
236
diff
changeset
|
535 |
accept_selector = deprecated_function(accept) |
0 | 536 |
|
254
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
537 |
accept_one = chainall(one_line_rset, accept_selector) |
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
538 |
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
|
539 |
|
254
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
540 |
rql_condition = chainall(non_final_entity, one_line_rset, _rql_condition) |
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
541 |
rqlcondition_selector = deprecated_function(rql_condition) |
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
542 |
|
0 | 543 |
|
254
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
544 |
searchstate_accept = chainall(nonempty_rset, match_search_state, accept) |
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
545 |
searchstate_accept_selector = deprecated_function(searchstate_accept) |
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
546 |
|
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
547 |
searchstate_accept_one = chainall(one_line_rset, match_search_state, |
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
548 |
accept, _rql_condition) |
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
549 |
searchstate_accept_one_selector = deprecated_function(searchstate_accept_one) |
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
550 |
|
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
551 |
searchstate_accept_one_but_etype = chainall(searchstate_accept_one, but_etype) |
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
552 |
searchstate_accept_one_but_etype_selector = deprecated_function( |
b1eda3dd844a
more selector renaming
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
247
diff
changeset
|
553 |
searchstate_accept_one_but_etype) |
0 | 554 |
|
237
3df2e0ae2eba
begin selector renaming (work in progress)
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
236
diff
changeset
|
555 |
#__all__ = [name for name in globals().keys() if name.endswith('selector')] |
3df2e0ae2eba
begin selector renaming (work in progress)
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
236
diff
changeset
|
556 |
#__all__ += ['chainall', 'chainfirst'] |