author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 17 Aug 2009 19:21:26 +0200 | |
changeset 2886 | 0b715e732330 |
parent 2885 | 0f8084bf2a21 |
child 2888 | 5492bafa4f17 |
permissions | -rw-r--r-- |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
1 |
"""Base class for dynamically loaded objects accessible through the vregistry. |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
2 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
3 |
You'll also find some convenience classes to build selectors. |
0 | 4 |
|
5 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1756
diff
changeset
|
6 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 7 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1756
diff
changeset
|
8 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 9 |
""" |
10 |
__docformat__ = "restructuredtext en" |
|
11 |
||
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
12 |
import types |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
13 |
from logging import getLogger |
0 | 14 |
|
699 | 15 |
from logilab.common.decorators import classproperty |
2613
5e19c2bb370e
R [all] logilab.common 0.44 provides only deprecated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2476
diff
changeset
|
16 |
from logilab.common.deprecation import deprecated |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
17 |
from logilab.common.logging_ext import set_log_methods |
447 | 18 |
|
1174 | 19 |
from cubicweb import Unauthorized, NoSelectableObject |
1524 | 20 |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
21 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
22 |
# selector base classes and operations ######################################## |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
23 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
24 |
def objectify_selector(selector_func): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
25 |
"""convenience decorator for simple selectors where a class definition |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
26 |
would be overkill:: |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
27 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
28 |
@objectify_selector |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
29 |
def yes(cls, *args, **kwargs): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
30 |
return 1 |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
31 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
32 |
""" |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
33 |
return type(selector_func.__name__, (Selector,), |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
34 |
{'__call__': lambda self, *args, **kwargs: selector_func(*args, **kwargs)}) |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
35 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
36 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
37 |
def _instantiate_selector(selector): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
38 |
"""ensures `selector` is a `Selector` instance |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
39 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
40 |
NOTE: This should only be used locally in build___select__() |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
41 |
XXX: then, why not do it ?? |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
42 |
""" |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
43 |
if isinstance(selector, types.FunctionType): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
44 |
return objectify_selector(selector)() |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
45 |
if isinstance(selector, type) and issubclass(selector, Selector): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
46 |
return selector() |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
47 |
return selector |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
48 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
49 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
50 |
class Selector(object): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
51 |
"""base class for selector classes providing implementation |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
52 |
for operators ``&`` and ``|`` |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
53 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
54 |
This class is only here to give access to binary operators, the |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
55 |
selector logic itself should be implemented in the __call__ method |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
56 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
57 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
58 |
a selector is called to help choosing the correct object for a |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
59 |
particular context by returning a score (`int`) telling how well |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
60 |
the class given as first argument apply to the given context. |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
61 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
62 |
0 score means that the class doesn't apply. |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
63 |
""" |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
64 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
65 |
@property |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
66 |
def func_name(self): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
67 |
# backward compatibility |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
68 |
return self.__class__.__name__ |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
69 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
70 |
def search_selector(self, selector): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
71 |
"""search for the given selector or selector instance in the selectors |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
72 |
tree. Return it of None if not found |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
73 |
""" |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
74 |
if self is selector: |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
75 |
return self |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
76 |
if isinstance(selector, type) and isinstance(self, selector): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
77 |
return self |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
78 |
return None |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
79 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
80 |
def __str__(self): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
81 |
return self.__class__.__name__ |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
82 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
83 |
def __and__(self, other): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
84 |
return AndSelector(self, other) |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
85 |
def __rand__(self, other): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
86 |
return AndSelector(other, self) |
2833
9aa47a3c0dfe
[selectors] explicity fail on inplace and/or
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2829
diff
changeset
|
87 |
def __iand__(self, other): |
9aa47a3c0dfe
[selectors] explicity fail on inplace and/or
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2829
diff
changeset
|
88 |
raise NotImplementedError('cant use inplace & (binary and)') |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
89 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
90 |
def __or__(self, other): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
91 |
return OrSelector(self, other) |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
92 |
def __ror__(self, other): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
93 |
return OrSelector(other, self) |
2833
9aa47a3c0dfe
[selectors] explicity fail on inplace and/or
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2829
diff
changeset
|
94 |
def __ior__(self, other): |
9aa47a3c0dfe
[selectors] explicity fail on inplace and/or
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2829
diff
changeset
|
95 |
raise NotImplementedError('cant use inplace | (binary or)') |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
96 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
97 |
def __invert__(self): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
98 |
return NotSelector(self) |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
99 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
100 |
# XXX (function | function) or (function & function) not managed yet |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
101 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
102 |
def __call__(self, cls, *args, **kwargs): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
103 |
return NotImplementedError("selector %s must implement its logic " |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
104 |
"in its __call__ method" % self.__class__) |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
105 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
106 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
107 |
class MultiSelector(Selector): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
108 |
"""base class for compound selector classes""" |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
109 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
110 |
def __init__(self, *selectors): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
111 |
self.selectors = self.merge_selectors(selectors) |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
112 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
113 |
def __str__(self): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
114 |
return '%s(%s)' % (self.__class__.__name__, |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
115 |
','.join(str(s) for s in self.selectors)) |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
116 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
117 |
@classmethod |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
118 |
def merge_selectors(cls, selectors): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
119 |
"""deal with selector instanciation when necessary and merge |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
120 |
multi-selectors if possible: |
0 | 121 |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
122 |
AndSelector(AndSelector(sel1, sel2), AndSelector(sel3, sel4)) |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
123 |
==> AndSelector(sel1, sel2, sel3, sel4) |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
124 |
""" |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
125 |
merged_selectors = [] |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
126 |
for selector in selectors: |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
127 |
try: |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
128 |
selector = _instantiate_selector(selector) |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
129 |
except: |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
130 |
pass |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
131 |
#assert isinstance(selector, Selector), selector |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
132 |
if isinstance(selector, cls): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
133 |
merged_selectors += selector.selectors |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
134 |
else: |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
135 |
merged_selectors.append(selector) |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
136 |
return merged_selectors |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
137 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
138 |
def search_selector(self, selector): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
139 |
"""search for the given selector or selector instance in the selectors |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
140 |
tree. Return it of None if not found |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
141 |
""" |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
142 |
for childselector in self.selectors: |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
143 |
if childselector is selector: |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
144 |
return childselector |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
145 |
found = childselector.search_selector(selector) |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
146 |
if found is not None: |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
147 |
return found |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
148 |
return None |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
149 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
150 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
151 |
class AndSelector(MultiSelector): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
152 |
"""and-chained selectors (formerly known as chainall)""" |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
153 |
def __call__(self, cls, *args, **kwargs): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
154 |
score = 0 |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
155 |
for selector in self.selectors: |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
156 |
partscore = selector(cls, *args, **kwargs) |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
157 |
if not partscore: |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
158 |
return 0 |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
159 |
score += partscore |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
160 |
return score |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
161 |
|
1524 | 162 |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
163 |
class OrSelector(MultiSelector): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
164 |
"""or-chained selectors (formerly known as chainfirst)""" |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
165 |
def __call__(self, cls, *args, **kwargs): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
166 |
for selector in self.selectors: |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
167 |
partscore = selector(cls, *args, **kwargs) |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
168 |
if partscore: |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
169 |
return partscore |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
170 |
return 0 |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
171 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
172 |
class NotSelector(Selector): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
173 |
"""negation selector""" |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
174 |
def __init__(self, selector): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
175 |
self.selector = selector |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
176 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
177 |
def __call__(self, cls, *args, **kwargs): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
178 |
score = self.selector(cls, *args, **kwargs) |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
179 |
return int(not score) |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
180 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
181 |
def __str__(self): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
182 |
return 'NOT(%s)' % super(NotSelector, self).__str__() |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
183 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
184 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
185 |
class yes(Selector): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
186 |
"""return arbitrary score |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
187 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
188 |
default score of 0.5 so any other selector take precedence |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
189 |
""" |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
190 |
def __init__(self, score=0.5): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
191 |
self.score = score |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
192 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
193 |
def __call__(self, *args, **kwargs): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
194 |
return self.score |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
195 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
196 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
197 |
# the base class for all appobjects ############################################ |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
198 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
199 |
class AppObject(object): |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
200 |
"""This is the base class for CubicWeb application objects which are |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
201 |
selected according to a context (usually at least a request and a result |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
202 |
set). |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
203 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
204 |
Concrete application objects classes are designed to be loaded by the |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
205 |
vregistry and should be accessed through it, not by direct instantiation. |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
206 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
207 |
The following attributes should be set on concret appobject classes: |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
208 |
:__registry__: |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
209 |
name of the registry for this object (string like 'views', |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
210 |
'templates'...) |
2829
054a8805da52
turn id into __id__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2825
diff
changeset
|
211 |
:__id__: |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
212 |
object's identifier in the registry (string like 'main', |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
213 |
'primary', 'folder_box') |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
214 |
:__select__: |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
215 |
class'selector |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
216 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
217 |
Moreover, the `__abstract__` attribute may be set to True to indicate |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
218 |
that a appobject is abstract and should not be registered. |
1524 | 219 |
|
2825 | 220 |
At selection time, the following attributes are set on the instance: |
221 |
||
2847
c2ee28f4d4b1
use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2833
diff
changeset
|
222 |
:_cw: |
2825 | 223 |
current request |
224 |
:cw_extra_kwargs: |
|
225 |
other received arguments |
|
0 | 226 |
|
2825 | 227 |
only if rset is found in arguments (in which case rset/row/col will be |
228 |
removed from cwextra_kwargs): |
|
229 |
||
230 |
:cw_rset: |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
231 |
context result set or None |
2825 | 232 |
:cw_row: |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
233 |
if a result set is set and the context is about a particular cell in the |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
234 |
result set, and not the result set as a whole, specify the row number we |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
235 |
are interested in, else None |
2825 | 236 |
:cw_col: |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
237 |
if a result set is set and the context is about a particular cell in the |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
238 |
result set, and not the result set as a whole, specify the col number we |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
239 |
are interested in, else None |
0 | 240 |
""" |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
241 |
__registry__ = None |
2829
054a8805da52
turn id into __id__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2825
diff
changeset
|
242 |
__id__ = None |
805
6e99feeba28b
set a default selector on base app objects class
sylvain.thenault@logilab.fr
parents:
802
diff
changeset
|
243 |
__select__ = yes() |
0 | 244 |
|
245 |
@classmethod |
|
2820
66b31686d92b
rename registered to __registered__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2819
diff
changeset
|
246 |
def __registered__(cls, registry): |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
247 |
"""called by the registry when the appobject has been registered. |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
248 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
249 |
It must return the object that will be actually registered (this may be |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
250 |
the right hook to create an instance for example). By default the |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
251 |
appobject is returned without any transformation. |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
252 |
""" |
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
253 |
pdefs = getattr(cls, 'cw_property_defs', {}) |
2802
2251b4aee54a
should still call .items
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2799
diff
changeset
|
254 |
for propid, pdef in pdefs.items(): |
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
255 |
pdef = pdef.copy() # may be shared |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
256 |
pdef['default'] = getattr(cls, propid, pdef['default']) |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
257 |
pdef['sitewide'] = getattr(cls, 'site_wide', pdef.get('sitewide')) |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
258 |
registry.vreg.register_property(cls._cwpropkey(propid), **pdef) |
0 | 259 |
return cls |
1524 | 260 |
|
2822
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
261 |
def __init__(self, req, **extra): |
2656
a93ae0f6c0ad
R [base classes] only AppObject remaning, no more AppRsetObject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
262 |
super(AppObject, self).__init__() |
2847
c2ee28f4d4b1
use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2833
diff
changeset
|
263 |
self._cw = req |
2822
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
264 |
try: |
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
265 |
self.cw_rset = extra.pop('rset') |
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
266 |
self.cw_row = extra.pop('row', None) |
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
267 |
self.cw_col = extra.pop('col', None) |
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
268 |
except KeyError: |
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
269 |
pass |
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
270 |
self.cw_extra_kwargs = extra |
1524 | 271 |
|
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
272 |
# persistent class properties ############################################## |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
273 |
# |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
274 |
# optional `cw_property_defs` dict on a class defines available persistent |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
275 |
# properties for this class: |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
276 |
# |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
277 |
# * key: id of the property (the actual CWProperty key is build using |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
278 |
# <registry name>.<obj id>.<property id> |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
279 |
# * value: tuple (property type, vocabfunc, default value, property description) |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
280 |
# possible types are those used by `logilab.common.configuration` |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
281 |
# |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
282 |
# notice that when it exists multiple objects with the same id (adaptation, |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
283 |
# overriding) only the first encountered definition is considered, so those |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
284 |
# objects can't try to have different default values for instance. |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
285 |
# |
2818
326375561412
propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2811
diff
changeset
|
286 |
# you can then access to a property value using self.cw_propval, where self |
326375561412
propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2811
diff
changeset
|
287 |
# is an instance of class |
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
288 |
|
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
289 |
@classmethod |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
290 |
def _cwpropkey(cls, propid): |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
291 |
"""return cw property key for the property of the given id for this |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
292 |
class |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
293 |
""" |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
294 |
return '%s.%s.%s' % (cls.__registry__, cls.id, propid) |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
295 |
|
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
296 |
def cw_propval(self, propid): |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
297 |
"""return cw property value associated to key |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
298 |
|
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
299 |
<cls.__registry__>.<cls.id>.<propid> |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
300 |
""" |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
301 |
return self.req.property_value(self._cwpropkey(propid)) |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
302 |
|
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2789
diff
changeset
|
303 |
# deprecated ############################################################### |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2789
diff
changeset
|
304 |
|
2811
e1f3b8e7f19a
fix bw compat properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2804
diff
changeset
|
305 |
@property |
2885
0f8084bf2a21
[deprecation] nicer messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2847
diff
changeset
|
306 |
@deprecated('[3.5] use self._cw.vreg') |
2811
e1f3b8e7f19a
fix bw compat properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2804
diff
changeset
|
307 |
def vreg(self): |
2847
c2ee28f4d4b1
use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2833
diff
changeset
|
308 |
return self._cw.vreg |
2822
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
309 |
|
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
310 |
@property |
2885
0f8084bf2a21
[deprecation] nicer messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2847
diff
changeset
|
311 |
@deprecated('[3.5] use self._cw.vreg.schema') |
2822
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
312 |
def schema(self): |
2847
c2ee28f4d4b1
use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2833
diff
changeset
|
313 |
return self._cw.vreg.schema |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2789
diff
changeset
|
314 |
|
2811
e1f3b8e7f19a
fix bw compat properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2804
diff
changeset
|
315 |
@property |
2885
0f8084bf2a21
[deprecation] nicer messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2847
diff
changeset
|
316 |
@deprecated('[3.5] use self._cw.vreg.config') |
2822
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
317 |
def config(self): |
2847
c2ee28f4d4b1
use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2833
diff
changeset
|
318 |
return self._cw.vreg.config |
2822
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
319 |
|
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
320 |
@property |
2885
0f8084bf2a21
[deprecation] nicer messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2847
diff
changeset
|
321 |
@deprecated('[3.5] use self._cw') |
2822
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
322 |
def req(self): |
2847
c2ee28f4d4b1
use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2833
diff
changeset
|
323 |
return self._cw |
2822
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
324 |
|
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
325 |
@property |
2885
0f8084bf2a21
[deprecation] nicer messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2847
diff
changeset
|
326 |
@deprecated('[3.5] use self.cw_rset') |
2822
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
327 |
def rset(self): |
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
328 |
return self.cw_rset |
2811
e1f3b8e7f19a
fix bw compat properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2804
diff
changeset
|
329 |
|
e1f3b8e7f19a
fix bw compat properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2804
diff
changeset
|
330 |
@property |
2885
0f8084bf2a21
[deprecation] nicer messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2847
diff
changeset
|
331 |
@deprecated('[3.5] use self.cw_row') |
2822
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
332 |
def row(self): |
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
333 |
return self.cw_row |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2789
diff
changeset
|
334 |
|
2822
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
335 |
@property |
2885
0f8084bf2a21
[deprecation] nicer messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2847
diff
changeset
|
336 |
@deprecated('[3.5] use self.cw_col') |
2822
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
337 |
def col(self): |
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
338 |
return self.cw_col |
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
339 |
|
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
340 |
@property |
2885
0f8084bf2a21
[deprecation] nicer messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2847
diff
changeset
|
341 |
@deprecated('[3.5] use self.cw_extra_kwargs') |
2822
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
342 |
def extra_kwargs(self): |
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
343 |
return self.cw_extra_kwargs |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2789
diff
changeset
|
344 |
|
2885
0f8084bf2a21
[deprecation] nicer messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2847
diff
changeset
|
345 |
@deprecated('[3.5] use self._cw.view') |
2822
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
346 |
def view(self, *args, **kwargs): |
2847
c2ee28f4d4b1
use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2833
diff
changeset
|
347 |
return self._cw.view(*args, **kwargs) |
2822
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
348 |
|
2885
0f8084bf2a21
[deprecation] nicer messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2847
diff
changeset
|
349 |
@deprecated('[3.5] use self._cw.varmaker') |
2822
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
350 |
def initialize_varmaker(self): |
2847
c2ee28f4d4b1
use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2833
diff
changeset
|
351 |
self.varmaker = self._cw.varmaker |
2796
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2795
diff
changeset
|
352 |
|
2885
0f8084bf2a21
[deprecation] nicer messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2847
diff
changeset
|
353 |
@deprecated('[3.5] use self._cw.get_cache') |
2822
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
354 |
def get_cache(self, cachename): |
2847
c2ee28f4d4b1
use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2833
diff
changeset
|
355 |
return self._cw.get_cache(cachename) |
2822
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
356 |
|
2885
0f8084bf2a21
[deprecation] nicer messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2847
diff
changeset
|
357 |
@deprecated('[3.5] use self._cw.build_url') |
2798
9c650701cb17
stop using controller class attribute, allowing to deprecate appobject.build_url in favor of req.build_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2796
diff
changeset
|
358 |
def build_url(self, *args, **kwargs): |
2847
c2ee28f4d4b1
use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2833
diff
changeset
|
359 |
return self._cw.build_url(*args, **kwargs) |
2798
9c650701cb17
stop using controller class attribute, allowing to deprecate appobject.build_url in favor of req.build_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2796
diff
changeset
|
360 |
|
2885
0f8084bf2a21
[deprecation] nicer messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2847
diff
changeset
|
361 |
@deprecated('[3.5] use self.cw_rset.limited_rql') |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2789
diff
changeset
|
362 |
def limited_rql(self): |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2789
diff
changeset
|
363 |
return self.rset.limited_rql() |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2789
diff
changeset
|
364 |
|
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2789
diff
changeset
|
365 |
@deprecated('[3.5] use self.rset.complete_entity(row,col) instead') |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2789
diff
changeset
|
366 |
def complete_entity(self, row, col=0, skip_bytes=True): |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2789
diff
changeset
|
367 |
return self.rset.complete_entity(row, col, skip_bytes) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2789
diff
changeset
|
368 |
|
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2789
diff
changeset
|
369 |
@deprecated('[3.5] use self.rset.get_entity(row,col) instead') |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2789
diff
changeset
|
370 |
def entity(self, row, col=0): |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2789
diff
changeset
|
371 |
return self.rset.get_entity(row, col) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2789
diff
changeset
|
372 |
|
2885
0f8084bf2a21
[deprecation] nicer messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2847
diff
changeset
|
373 |
@deprecated('[3.5] use self._cw.user_rql_callback') |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2789
diff
changeset
|
374 |
def user_rql_callback(self, args, msg=None): |
2847
c2ee28f4d4b1
use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2833
diff
changeset
|
375 |
return self._cw.user_rql_callback(args, msg) |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2789
diff
changeset
|
376 |
|
2885
0f8084bf2a21
[deprecation] nicer messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2847
diff
changeset
|
377 |
@deprecated('[3.5] use self._cw.user_callback') |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2789
diff
changeset
|
378 |
def user_callback(self, cb, args, msg=None, nonify=False): |
2847
c2ee28f4d4b1
use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2833
diff
changeset
|
379 |
return self._cw.user_callback(cb, args, msg, nonify) |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2789
diff
changeset
|
380 |
|
2885
0f8084bf2a21
[deprecation] nicer messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2847
diff
changeset
|
381 |
@deprecated('[3.5] use self._cw.format_date') |
0 | 382 |
def format_date(self, date, date_format=None, time=False): |
2847
c2ee28f4d4b1
use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2833
diff
changeset
|
383 |
return self._cw.format_date(date, date_format, time) |
0 | 384 |
|
2885
0f8084bf2a21
[deprecation] nicer messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2847
diff
changeset
|
385 |
@deprecated('[3.5] use self._cw.format_timoe') |
0 | 386 |
def format_time(self, time): |
2847
c2ee28f4d4b1
use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2833
diff
changeset
|
387 |
return self._cw.format_time(time) |
0 | 388 |
|
2885
0f8084bf2a21
[deprecation] nicer messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2847
diff
changeset
|
389 |
@deprecated('[3.5] use self._cw.format_float') |
0 | 390 |
def format_float(self, num): |
2847
c2ee28f4d4b1
use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2833
diff
changeset
|
391 |
return self._cw.format_float(num) |
1524 | 392 |
|
2885
0f8084bf2a21
[deprecation] nicer messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2847
diff
changeset
|
393 |
@deprecated('[3.5] use self._cw.parse_datetime') |
1984
8d571df6012a
move parse_datetime on appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
394 |
def parse_datetime(self, value, etype='Datetime'): |
2847
c2ee28f4d4b1
use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2833
diff
changeset
|
395 |
return self._cw.parse_datetime(value, etype) |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
396 |
|
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
397 |
@deprecated('[3.5] use self.cw_propval') |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
398 |
def propval(self, propid): |
2847
c2ee28f4d4b1
use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2833
diff
changeset
|
399 |
return self._cw.property_value(self._cwpropkey(propid)) |
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
400 |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
401 |
set_log_methods(AppObject, getLogger('cubicweb.appobject')) |