author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 08 Feb 2010 10:06:40 +0100 | |
branch | stable |
changeset 4489 | 63128e8b9af9 |
parent 4486 | 9a4ef69bdef7 |
child 4490 | d45cde54d464 |
permissions | -rw-r--r-- |
0 | 1 |
"""extend the generic VRegistry with some cubicweb specific stuff |
2 |
||
3 |
:organization: Logilab |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3951
diff
changeset
|
4 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 5 |
: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:
1923
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
1769
fb91d2b8a441
fix some rtags pb on i18n catalog generation
sylvain.thenault@logilab.fr
parents:
1752
diff
changeset
|
9 |
_ = unicode |
0 | 10 |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
11 |
from logilab.common.decorators import cached, clear_cache, monkeypatch |
2613
5e19c2bb370e
R [all] logilab.common 0.44 provides only deprecated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2476
diff
changeset
|
12 |
from logilab.common.deprecation import deprecated |
2684
c84691380dd4
[autoreload] remove all modules under vregistry_path() from sys.modules before reloading
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2669
diff
changeset
|
13 |
from logilab.common.modutils import cleanup_sys_modules |
0 | 14 |
|
15 |
from rql import RQLHelper |
|
16 |
||
2651
3ad936634d2a
[registry] when a source file is changed, reset and reload the whole registry
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2613
diff
changeset
|
17 |
from cubicweb import (ETYPE_NAME_MAP, Binary, UnknownProperty, UnknownEid, |
2655 | 18 |
ObjectNotFound, NoSelectableObject, RegistryNotFound, |
3057
f4ba5a251ab7
generic rtag cleaing method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3055
diff
changeset
|
19 |
RegistryOutOfDate, CW_EVENT_MANAGER, onevent) |
2658
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
20 |
from cubicweb.utils import dump_class |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
21 |
from cubicweb.vregistry import VRegistry, Registry |
1769
fb91d2b8a441
fix some rtags pb on i18n catalog generation
sylvain.thenault@logilab.fr
parents:
1752
diff
changeset
|
22 |
from cubicweb.rtags import RTAGS |
0 | 23 |
|
24 |
||
3057
f4ba5a251ab7
generic rtag cleaing method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3055
diff
changeset
|
25 |
@onevent('before-registry-reload') |
f4ba5a251ab7
generic rtag cleaing method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3055
diff
changeset
|
26 |
def clear_rtag_objects(): |
f4ba5a251ab7
generic rtag cleaing method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3055
diff
changeset
|
27 |
for rtag in RTAGS: |
f4ba5a251ab7
generic rtag cleaing method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3055
diff
changeset
|
28 |
rtag.clear() |
f4ba5a251ab7
generic rtag cleaing method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3055
diff
changeset
|
29 |
|
f4ba5a251ab7
generic rtag cleaing method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3055
diff
changeset
|
30 |
|
776 | 31 |
def use_interfaces(obj): |
3719 | 32 |
"""return interfaces used by the given object by searching for implements |
1132 | 33 |
selectors, with a bw compat fallback to accepts_interfaces attribute |
34 |
""" |
|
776 | 35 |
from cubicweb.selectors import implements |
36 |
try: |
|
37 |
# XXX deprecated |
|
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
38 |
return sorted(obj.accepts_interfaces) |
776 | 39 |
except AttributeError: |
40 |
try: |
|
41 |
impl = obj.__select__.search_selector(implements) |
|
42 |
if impl: |
|
43 |
return sorted(impl.expected_ifaces) |
|
44 |
except AttributeError: |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2655
diff
changeset
|
45 |
pass # old-style appobject classes with no accepts_interfaces |
1044
3672a7c86784
print message to help debugging selector on error
sylvain.thenault@logilab.fr
parents:
1037
diff
changeset
|
46 |
except: |
3672a7c86784
print message to help debugging selector on error
sylvain.thenault@logilab.fr
parents:
1037
diff
changeset
|
47 |
print 'bad selector %s on %s' % (obj.__select__, obj) |
3672a7c86784
print message to help debugging selector on error
sylvain.thenault@logilab.fr
parents:
1037
diff
changeset
|
48 |
raise |
776 | 49 |
return () |
0 | 50 |
|
51 |
||
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
52 |
class CWRegistry(Registry): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
53 |
def __init__(self, vreg): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
54 |
super(CWRegistry, self).__init__(vreg.config) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
55 |
self.vreg = vreg |
2927
d249dd9000d9
use a property for schema, avoid bad schema reference
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2914
diff
changeset
|
56 |
|
d249dd9000d9
use a property for schema, avoid bad schema reference
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2914
diff
changeset
|
57 |
@property |
d249dd9000d9
use a property for schema, avoid bad schema reference
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2914
diff
changeset
|
58 |
def schema(self): |
d249dd9000d9
use a property for schema, avoid bad schema reference
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2914
diff
changeset
|
59 |
return self.vreg.schema |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
60 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
61 |
def initialization_completed(self): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
62 |
# call vreg_initialization_completed on appobjects and print |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
63 |
# registry content |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
64 |
for appobjects in self.itervalues(): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
65 |
for appobject in appobjects: |
4486
9a4ef69bdef7
reminder, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4485
diff
changeset
|
66 |
# XXX kill vreg_initialization_completed |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
67 |
appobject.vreg_initialization_completed() |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
68 |
|
3704
ddb10568f5f8
a way to distinguish __init__ vs render arguments
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3702
diff
changeset
|
69 |
def render(self, __oid, req, __fallback_oid=None, rset=None, initargs=None, |
ddb10568f5f8
a way to distinguish __init__ vs render arguments
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3702
diff
changeset
|
70 |
**kwargs): |
ddb10568f5f8
a way to distinguish __init__ vs render arguments
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3702
diff
changeset
|
71 |
"""Select object with the given id (`__oid`) then render it. If the |
ddb10568f5f8
a way to distinguish __init__ vs render arguments
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3702
diff
changeset
|
72 |
object isn't selectable, try to select fallback object if |
ddb10568f5f8
a way to distinguish __init__ vs render arguments
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3702
diff
changeset
|
73 |
`__fallback_oid` is specified. |
ddb10568f5f8
a way to distinguish __init__ vs render arguments
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3702
diff
changeset
|
74 |
|
ddb10568f5f8
a way to distinguish __init__ vs render arguments
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3702
diff
changeset
|
75 |
If specified `initargs` is expected to be a dictionnary containing |
ddb10568f5f8
a way to distinguish __init__ vs render arguments
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3702
diff
changeset
|
76 |
arguments that should be given to selection (hence to object's __init__ |
ddb10568f5f8
a way to distinguish __init__ vs render arguments
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3702
diff
changeset
|
77 |
as well), but not to render(). Other arbitrary keyword arguments will be |
ddb10568f5f8
a way to distinguish __init__ vs render arguments
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3702
diff
changeset
|
78 |
given to selection *and* to render(), and so should be handled by |
ddb10568f5f8
a way to distinguish __init__ vs render arguments
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3702
diff
changeset
|
79 |
object's call or cell_call method.. |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
80 |
""" |
3704
ddb10568f5f8
a way to distinguish __init__ vs render arguments
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3702
diff
changeset
|
81 |
if initargs is None: |
ddb10568f5f8
a way to distinguish __init__ vs render arguments
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3702
diff
changeset
|
82 |
initargs = kwargs |
ddb10568f5f8
a way to distinguish __init__ vs render arguments
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3702
diff
changeset
|
83 |
else: |
3706 | 84 |
initargs.update(kwargs) |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
85 |
try: |
3704
ddb10568f5f8
a way to distinguish __init__ vs render arguments
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3702
diff
changeset
|
86 |
obj = self.select(__oid, req, rset=rset, **initargs) |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
87 |
except NoSelectableObject: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
88 |
if __fallback_oid is None: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
89 |
raise |
3704
ddb10568f5f8
a way to distinguish __init__ vs render arguments
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3702
diff
changeset
|
90 |
obj = self.select(__fallback_oid, req, rset=rset, **initargs) |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
91 |
return obj.render(**kwargs) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
92 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
93 |
def select_vobject(self, oid, *args, **kwargs): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
94 |
selected = self.select_object(oid, *args, **kwargs) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
95 |
if selected and selected.propval('visible'): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
96 |
return selected |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
97 |
return None |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
98 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
99 |
def possible_vobjects(self, *args, **kwargs): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
100 |
"""return an ordered list of possible app objects in a given registry, |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
101 |
supposing they support the 'visible' and 'order' properties (as most |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
102 |
visualizable objects) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
103 |
""" |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
104 |
return sorted([x for x in self.possible_objects(*args, **kwargs) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
105 |
if x.propval('visible')], |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
106 |
key=lambda x: x.propval('order')) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
107 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
108 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
109 |
VRegistry.REGISTRY_FACTORY[None] = CWRegistry |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
110 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
111 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
112 |
class ETypeRegistry(CWRegistry): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
113 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
114 |
def initialization_completed(self): |
2658
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
115 |
"""on registration completed, clear etype_class internal cache |
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
116 |
""" |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
117 |
super(ETypeRegistry, self).initialization_completed() |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
118 |
# clear etype cache if you don't want to run into deep weirdness |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
119 |
clear_cache(self, 'etype_class') |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
120 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
121 |
def register(self, obj, **kwargs): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
122 |
oid = kwargs.get('oid') or obj.id |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
123 |
if oid != 'Any' and not oid in self.schema: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
124 |
self.error('don\'t register %s, %s type not defined in the ' |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
125 |
'schema', obj, obj.id) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
126 |
return |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
127 |
kwargs['clear'] = True |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
128 |
super(ETypeRegistry, self).register(obj, **kwargs) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
129 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
130 |
@cached |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
131 |
def etype_class(self, etype): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
132 |
"""return an entity class for the given entity type. |
2658
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
133 |
|
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
134 |
Try to find out a specific class for this kind of entity or default to a |
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
135 |
dump of the nearest parent class (in yams inheritance) registered. |
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
136 |
|
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
137 |
Fall back to 'Any' if not yams parent class found. |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
138 |
""" |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
139 |
etype = str(etype) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
140 |
if etype == 'Any': |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
141 |
return self.select('Any', 'Any') |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
142 |
eschema = self.schema.eschema(etype) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
143 |
baseschemas = [eschema] + eschema.ancestors() |
2658
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
144 |
# browse ancestors from most specific to most generic and try to find an |
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
145 |
# associated custom entity class |
3172
9341ab8f1d1a
[vreg] we must ensure that parent classes are initialiazed first
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3057
diff
changeset
|
146 |
cls = None |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
147 |
for baseschema in baseschemas: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
148 |
try: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
149 |
btype = ETYPE_NAME_MAP[baseschema] |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
150 |
except KeyError: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
151 |
btype = str(baseschema) |
3172
9341ab8f1d1a
[vreg] we must ensure that parent classes are initialiazed first
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3057
diff
changeset
|
152 |
if cls is None: |
9341ab8f1d1a
[vreg] we must ensure that parent classes are initialiazed first
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3057
diff
changeset
|
153 |
try: |
9341ab8f1d1a
[vreg] we must ensure that parent classes are initialiazed first
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3057
diff
changeset
|
154 |
objects = self[btype] |
9341ab8f1d1a
[vreg] we must ensure that parent classes are initialiazed first
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3057
diff
changeset
|
155 |
assert len(objects) == 1, objects |
3205
dc67e9431f34
fix entity classes inheritance (repair cw.test.unittest_entity)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3184
diff
changeset
|
156 |
if btype == etype: |
dc67e9431f34
fix entity classes inheritance (repair cw.test.unittest_entity)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3184
diff
changeset
|
157 |
cls = objects[0] |
dc67e9431f34
fix entity classes inheritance (repair cw.test.unittest_entity)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3184
diff
changeset
|
158 |
else: |
dc67e9431f34
fix entity classes inheritance (repair cw.test.unittest_entity)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3184
diff
changeset
|
159 |
cls = self.etype_class(btype) |
3172
9341ab8f1d1a
[vreg] we must ensure that parent classes are initialiazed first
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3057
diff
changeset
|
160 |
except ObjectNotFound: |
3205
dc67e9431f34
fix entity classes inheritance (repair cw.test.unittest_entity)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3184
diff
changeset
|
161 |
continue |
3172
9341ab8f1d1a
[vreg] we must ensure that parent classes are initialiazed first
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3057
diff
changeset
|
162 |
else: |
9341ab8f1d1a
[vreg] we must ensure that parent classes are initialiazed first
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3057
diff
changeset
|
163 |
# ensure parent classes are built first |
9341ab8f1d1a
[vreg] we must ensure that parent classes are initialiazed first
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3057
diff
changeset
|
164 |
self.etype_class(btype) |
9341ab8f1d1a
[vreg] we must ensure that parent classes are initialiazed first
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3057
diff
changeset
|
165 |
if cls is None: |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
166 |
# no entity class for any of the ancestors, fallback to the default |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
167 |
# one |
2658
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
168 |
objects = self['Any'] |
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
169 |
assert len(objects) == 1, objects |
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
170 |
cls = objects[0] |
3032
f0ae6a5aba3e
integrate fix made for shingouz, let's see if it breaks something
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2927
diff
changeset
|
171 |
# make a copy event if cls.id == etype, else we may have pb for client |
f0ae6a5aba3e
integrate fix made for shingouz, let's see if it breaks something
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2927
diff
changeset
|
172 |
# application using multiple connections to different repositories (eg |
f0ae6a5aba3e
integrate fix made for shingouz, let's see if it breaks something
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2927
diff
changeset
|
173 |
# shingouz) |
2658
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
174 |
cls = dump_class(cls, etype) |
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
175 |
cls.id = etype |
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
176 |
cls.__initialize__() |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
177 |
return cls |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
178 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
179 |
VRegistry.REGISTRY_FACTORY['etypes'] = ETypeRegistry |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
180 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
181 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
182 |
class ViewsRegistry(CWRegistry): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
183 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
184 |
def main_template(self, req, oid='main-template', **kwargs): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
185 |
"""display query by calling the given template (default to main), |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
186 |
and returning the output as a string instead of requiring the [w]rite |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
187 |
method as argument |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
188 |
""" |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
189 |
res = self.render(oid, req, **kwargs) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
190 |
if isinstance(res, unicode): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
191 |
return res.encode(req.encoding) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
192 |
assert isinstance(res, str) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
193 |
return res |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
194 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
195 |
def possible_views(self, req, rset=None, **kwargs): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
196 |
"""return an iterator on possible views for this result set |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
197 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
198 |
views returned are classes, not instances |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
199 |
""" |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
200 |
for vid, views in self.items(): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
201 |
if vid[0] == '_': |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
202 |
continue |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
203 |
try: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
204 |
view = self.select_best(views, req, rset=rset, **kwargs) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
205 |
if view.linkable(): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
206 |
yield view |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
207 |
except NoSelectableObject: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
208 |
continue |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
209 |
except Exception: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
210 |
self.exception('error while trying to select %s view for %s', |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
211 |
vid, rset) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
212 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
213 |
VRegistry.REGISTRY_FACTORY['views'] = ViewsRegistry |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
214 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
215 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
216 |
class ActionsRegistry(CWRegistry): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
217 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
218 |
def possible_actions(self, req, rset=None, **kwargs): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
219 |
if rset is None: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
220 |
actions = self.possible_vobjects(req, rset=rset, **kwargs) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
221 |
else: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
222 |
actions = rset.possible_actions(**kwargs) # cached implementation |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
223 |
result = {} |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
224 |
for action in actions: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
225 |
result.setdefault(action.category, []).append(action) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
226 |
return result |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
227 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
228 |
VRegistry.REGISTRY_FACTORY['actions'] = ActionsRegistry |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
229 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
230 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
231 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
232 |
class CubicWebVRegistry(VRegistry): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2389
diff
changeset
|
233 |
"""Central registry for the cubicweb instance, extending the generic |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
234 |
VRegistry with some cubicweb specific stuff. |
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
235 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2389
diff
changeset
|
236 |
This is one of the central object in cubicweb instance, coupling |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
237 |
dynamically loaded objects with the schema and the configuration objects. |
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
238 |
|
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
239 |
It specializes the VRegistry by adding some convenience methods to access to |
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
240 |
stored objects. Currently we have the following registries of objects known |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2389
diff
changeset
|
241 |
by the web instance (library may use some others additional registries): |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
242 |
|
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
243 |
* etypes |
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
244 |
* views |
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
245 |
* components |
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
246 |
* actions |
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
247 |
* forms |
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
248 |
* formrenderers |
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
249 |
* controllers, which are directly plugged into the application |
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
250 |
object to handle request publishing XXX to merge with views |
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
251 |
* contentnavigation XXX to merge with components? to kill? |
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
252 |
""" |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
253 |
|
169
0e031b66cb0b
don't systematically init_log, it may breaks client log configuration
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
254 |
def __init__(self, config, debug=None, initlog=True): |
0e031b66cb0b
don't systematically init_log, it may breaks client log configuration
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
255 |
if initlog: |
0e031b66cb0b
don't systematically init_log, it may breaks client log configuration
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
256 |
# first init log service |
0e031b66cb0b
don't systematically init_log, it may breaks client log configuration
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
257 |
config.init_log(debug=debug) |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
258 |
super(CubicWebVRegistry, self).__init__(config) |
0 | 259 |
self.schema = None |
2906
677fa98659a8
fix cw properties initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2761
diff
changeset
|
260 |
self.initialized = False |
0 | 261 |
self.reset() |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
262 |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
263 |
def setdefault(self, regid): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
264 |
try: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
265 |
return self[regid] |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
266 |
except RegistryNotFound: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
267 |
self[regid] = self.registry_class(regid)(self) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
268 |
return self[regid] |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
269 |
|
0 | 270 |
def items(self): |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
271 |
return [item for item in super(CubicWebVRegistry, self).items() |
0 | 272 |
if not item[0] in ('propertydefs', 'propertyvalues')] |
2669
cab66dfe0db6
to avoid confusions, implements iteritems/itervalues as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2659
diff
changeset
|
273 |
def iteritems(self): |
cab66dfe0db6
to avoid confusions, implements iteritems/itervalues as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2659
diff
changeset
|
274 |
return (item for item in super(CubicWebVRegistry, self).iteritems() |
cab66dfe0db6
to avoid confusions, implements iteritems/itervalues as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2659
diff
changeset
|
275 |
if not item[0] in ('propertydefs', 'propertyvalues')) |
0 | 276 |
|
277 |
def values(self): |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
278 |
return [value for key, value in self.items()] |
2669
cab66dfe0db6
to avoid confusions, implements iteritems/itervalues as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2659
diff
changeset
|
279 |
def itervalues(self): |
cab66dfe0db6
to avoid confusions, implements iteritems/itervalues as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2659
diff
changeset
|
280 |
return (value for key, value in self.items()) |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
281 |
|
2760
30063071aee0
fix reloading, new .reset prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2705
diff
changeset
|
282 |
def reset(self, path=None, force_reload=None): |
30063071aee0
fix reloading, new .reset prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2705
diff
changeset
|
283 |
super(CubicWebVRegistry, self).reset(path, force_reload) |
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
284 |
self._needs_iface = {} |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
285 |
# two special registries, propertydefs which care all the property |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
286 |
# definitions, and propertyvals which contains values for those |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
287 |
# properties |
2906
677fa98659a8
fix cw properties initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2761
diff
changeset
|
288 |
if not self.initialized: |
677fa98659a8
fix cw properties initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2761
diff
changeset
|
289 |
self['propertydefs'] = {} |
677fa98659a8
fix cw properties initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2761
diff
changeset
|
290 |
self['propertyvalues'] = self.eprop_values = {} |
677fa98659a8
fix cw properties initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2761
diff
changeset
|
291 |
for key, propdef in self.config.eproperty_definitions(): |
677fa98659a8
fix cw properties initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2761
diff
changeset
|
292 |
self.register_property(key, **propdef) |
2760
30063071aee0
fix reloading, new .reset prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2705
diff
changeset
|
293 |
if path is not None and force_reload: |
30063071aee0
fix reloading, new .reset prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2705
diff
changeset
|
294 |
cleanup_sys_modules(path) |
30063071aee0
fix reloading, new .reset prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2705
diff
changeset
|
295 |
cubes = self.config.cubes() |
30063071aee0
fix reloading, new .reset prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2705
diff
changeset
|
296 |
# if the fs code use some cubes not yet registered into the instance |
30063071aee0
fix reloading, new .reset prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2705
diff
changeset
|
297 |
# we should cleanup sys.modules for those as well to avoid potential |
30063071aee0
fix reloading, new .reset prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2705
diff
changeset
|
298 |
# bad class reference pb after reloading |
30063071aee0
fix reloading, new .reset prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2705
diff
changeset
|
299 |
cfg = self.config |
30063071aee0
fix reloading, new .reset prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2705
diff
changeset
|
300 |
for cube in cfg.expand_cubes(cubes, with_recommends=True): |
30063071aee0
fix reloading, new .reset prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2705
diff
changeset
|
301 |
if not cube in cubes: |
30063071aee0
fix reloading, new .reset prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2705
diff
changeset
|
302 |
cpath = cfg.build_vregistry_cube_path([cfg.cube_dir(cube)]) |
30063071aee0
fix reloading, new .reset prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2705
diff
changeset
|
303 |
cleanup_sys_modules(cpath) |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
304 |
|
0 | 305 |
def set_schema(self, schema): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2389
diff
changeset
|
306 |
"""set instance'schema and load application objects""" |
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
307 |
self._set_schema(schema) |
0 | 308 |
# now we can load application's web objects |
2761
7c583d02917b
[vreg] explicit reset, no need to reload appobjects module on reloading because of schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2760
diff
changeset
|
309 |
searchpath = self.config.vregistry_path() |
7c583d02917b
[vreg] explicit reset, no need to reload appobjects module on reloading because of schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2760
diff
changeset
|
310 |
self.reset(searchpath, force_reload=False) |
7c583d02917b
[vreg] explicit reset, no need to reload appobjects module on reloading because of schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2760
diff
changeset
|
311 |
self.register_objects(searchpath, force_reload=False) |
2273
daf6e178659f
new case_insensitive_etypes resource on the cubicweb registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2223
diff
changeset
|
312 |
# map lowered entity type names to their actual name |
daf6e178659f
new case_insensitive_etypes resource on the cubicweb registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2223
diff
changeset
|
313 |
self.case_insensitive_etypes = {} |
3692
54aa8d13aab4
clear eschema caches on schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3641
diff
changeset
|
314 |
for eschema in self.schema.entities(): |
54aa8d13aab4
clear eschema caches on schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3641
diff
changeset
|
315 |
etype = str(eschema) |
2273
daf6e178659f
new case_insensitive_etypes resource on the cubicweb registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2223
diff
changeset
|
316 |
self.case_insensitive_etypes[etype.lower()] = etype |
3692
54aa8d13aab4
clear eschema caches on schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3641
diff
changeset
|
317 |
clear_cache(eschema, 'ordered_relations') |
54aa8d13aab4
clear eschema caches on schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3641
diff
changeset
|
318 |
clear_cache(eschema, 'meta_attributes') |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
319 |
|
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
320 |
def _set_schema(self, schema): |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
321 |
"""set instance'schema""" |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
322 |
self.schema = schema |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
323 |
clear_cache(self, 'rqlhelper') |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
324 |
|
0 | 325 |
def update_schema(self, schema): |
326 |
"""update .schema attribute on registered objects, necessary for some |
|
327 |
tests |
|
328 |
""" |
|
329 |
self.schema = schema |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
330 |
for registry, regcontent in self.items(): |
0 | 331 |
for objects in regcontent.values(): |
332 |
for obj in objects: |
|
333 |
obj.schema = schema |
|
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
334 |
|
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
335 |
def register_if_interface_found(self, obj, ifaces, **kwargs): |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
336 |
"""register an object but remove it if no entity class implements one of |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
337 |
the given interfaces |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
338 |
""" |
785 | 339 |
self.register(obj, **kwargs) |
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
340 |
if not isinstance(ifaces, (tuple, list)): |
785 | 341 |
self._needs_iface[obj] = (ifaces,) |
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
342 |
else: |
785 | 343 |
self._needs_iface[obj] = ifaces |
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
344 |
|
3055
06814d57514f
[vreg] keep positional arg compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2927
diff
changeset
|
345 |
def register(self, obj, *args, **kwargs): |
06814d57514f
[vreg] keep positional arg compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2927
diff
changeset
|
346 |
super(CubicWebVRegistry, self).register(obj, *args, **kwargs) |
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
347 |
# XXX bw compat |
777
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
776
diff
changeset
|
348 |
ifaces = use_interfaces(obj) |
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
349 |
if ifaces: |
785 | 350 |
self._needs_iface[obj] = ifaces |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
351 |
|
0 | 352 |
def register_objects(self, path, force_reload=None): |
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
353 |
"""overriden to remove objects requiring a missing interface""" |
2760
30063071aee0
fix reloading, new .reset prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2705
diff
changeset
|
354 |
if force_reload is None: |
3641
cf30e4498674
fix debug attribute conflict on configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
355 |
force_reload = self.config.debugmode |
2651
3ad936634d2a
[registry] when a source file is changed, reset and reload the whole registry
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2613
diff
changeset
|
356 |
try: |
3ad936634d2a
[registry] when a source file is changed, reset and reload the whole registry
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2613
diff
changeset
|
357 |
self._register_objects(path, force_reload) |
3ad936634d2a
[registry] when a source file is changed, reset and reload the whole registry
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2613
diff
changeset
|
358 |
except RegistryOutOfDate: |
2705
30bcdbd92820
[events] renamed source-reload into registry-reload to avoid potential confusions with datasources
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2685
diff
changeset
|
359 |
CW_EVENT_MANAGER.emit('before-registry-reload') |
2651
3ad936634d2a
[registry] when a source file is changed, reset and reload the whole registry
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2613
diff
changeset
|
360 |
# modification detected, reset and reload |
2760
30063071aee0
fix reloading, new .reset prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2705
diff
changeset
|
361 |
self.reset(path, force_reload) |
2651
3ad936634d2a
[registry] when a source file is changed, reset and reload the whole registry
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2613
diff
changeset
|
362 |
self._register_objects(path, force_reload) |
2705
30bcdbd92820
[events] renamed source-reload into registry-reload to avoid potential confusions with datasources
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2685
diff
changeset
|
363 |
CW_EVENT_MANAGER.emit('after-registry-reload') |
2651
3ad936634d2a
[registry] when a source file is changed, reset and reload the whole registry
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2613
diff
changeset
|
364 |
|
3ad936634d2a
[registry] when a source file is changed, reset and reload the whole registry
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2613
diff
changeset
|
365 |
def _register_objects(self, path, force_reload=None): |
3ad936634d2a
[registry] when a source file is changed, reset and reload the whole registry
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2613
diff
changeset
|
366 |
"""overriden to remove objects requiring a missing interface""" |
2025
010a4b0fe855
fix lookup of files to load when using CW_CUBES_PATH
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1985
diff
changeset
|
367 |
extrapath = {} |
010a4b0fe855
fix lookup of files to load when using CW_CUBES_PATH
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1985
diff
changeset
|
368 |
for cubesdir in self.config.cubes_search_path(): |
010a4b0fe855
fix lookup of files to load when using CW_CUBES_PATH
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1985
diff
changeset
|
369 |
if cubesdir != self.config.CUBES_DIR: |
010a4b0fe855
fix lookup of files to load when using CW_CUBES_PATH
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1985
diff
changeset
|
370 |
extrapath[cubesdir] = 'cubes' |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
371 |
if super(CubicWebVRegistry, self).register_objects(path, force_reload, |
2025
010a4b0fe855
fix lookup of files to load when using CW_CUBES_PATH
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1985
diff
changeset
|
372 |
extrapath): |
1638 | 373 |
self.initialization_completed() |
1769
fb91d2b8a441
fix some rtags pb on i18n catalog generation
sylvain.thenault@logilab.fr
parents:
1752
diff
changeset
|
374 |
# don't check rtags if we don't want to cleanup_interface_sobjects |
1752
4b0b912ff5b7
fix rtags initialization: do it at the registry level to avoid multiple initialization of the same rtag
sylvain.thenault@logilab.fr
parents:
1723
diff
changeset
|
375 |
for rtag in RTAGS: |
1769
fb91d2b8a441
fix some rtags pb on i18n catalog generation
sylvain.thenault@logilab.fr
parents:
1752
diff
changeset
|
376 |
rtag.init(self.schema, |
fb91d2b8a441
fix some rtags pb on i18n catalog generation
sylvain.thenault@logilab.fr
parents:
1752
diff
changeset
|
377 |
check=self.config.cleanup_interface_sobjects) |
0 | 378 |
|
1638 | 379 |
def initialization_completed(self): |
4486
9a4ef69bdef7
reminder, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4485
diff
changeset
|
380 |
for regname, reg in self.iteritems(): |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
381 |
self.debug('available in registry %s: %s', regname, sorted(reg)) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
382 |
reg.initialization_completed() |
4485
5f99eb0b99f7
initialize property once initialization has been fully completed, close #666573
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
383 |
for appobjects in reg.itervalues(): |
5f99eb0b99f7
initialize property once initialization has been fully completed, close #666573
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
384 |
for appobjectcls in appobjects: |
5f99eb0b99f7
initialize property once initialization has been fully completed, close #666573
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
385 |
appobjectcls.register_properties() |
1638 | 386 |
# we may want to keep interface dependent objects (e.g.for i18n |
387 |
# catalog generation) |
|
388 |
if self.config.cleanup_interface_sobjects: |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2655
diff
changeset
|
389 |
# remove appobjects that don't support any available interface |
1638 | 390 |
implemented_interfaces = set() |
391 |
if 'Any' in self.get('etypes', ()): |
|
392 |
for etype in self.schema.entities(): |
|
3702
29cce43d6af2
skip final type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3692
diff
changeset
|
393 |
if etype.final: |
29cce43d6af2
skip final type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3692
diff
changeset
|
394 |
continue |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
395 |
cls = self['etypes'].etype_class(etype) |
1638 | 396 |
for iface in cls.__implements__: |
397 |
implemented_interfaces.update(iface.__mro__) |
|
398 |
implemented_interfaces.update(cls.__mro__) |
|
399 |
for obj, ifaces in self._needs_iface.items(): |
|
400 |
ifaces = frozenset(isinstance(iface, basestring) |
|
401 |
and iface in self.schema |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
402 |
and self['etypes'].etype_class(iface) |
1638 | 403 |
or iface |
404 |
for iface in ifaces) |
|
405 |
if not ('Any' in ifaces or ifaces & implemented_interfaces): |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2655
diff
changeset
|
406 |
self.debug('kicking appobject %s (no implemented ' |
1638 | 407 |
'interface among %s)', obj, ifaces) |
408 |
self.unregister(obj) |
|
409 |
# clear needs_iface so we don't try to remove some not-anymore-in |
|
410 |
# objects on automatic reloading |
|
411 |
self._needs_iface.clear() |
|
412 |
||
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
413 |
# rql parsing utilities #################################################### |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
414 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
415 |
@property |
0 | 416 |
@cached |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
417 |
def rqlhelper(self): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
418 |
return RQLHelper(self.schema, |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
419 |
special_relations={'eid': 'uid', 'has_text': 'fti'}) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
420 |
|
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
421 |
def solutions(self, req, rqlst, args): |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
422 |
def type_from_eid(eid, req=req): |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
423 |
return req.describe(eid)[0] |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
424 |
self.rqlhelper.compute_solutions(rqlst, {'eid': type_from_eid}, args) |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
425 |
|
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
426 |
def parse(self, req, rql, args=None): |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
427 |
rqlst = self.rqlhelper.parse(rql) |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
428 |
try: |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
429 |
self.solutions(req, rqlst, args) |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
430 |
except UnknownEid: |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
431 |
for select in rqlst.children: |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
432 |
select.solutions = [] |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
433 |
return rqlst |
0 | 434 |
|
435 |
# properties handling ##################################################### |
|
436 |
||
437 |
def user_property_keys(self, withsitewide=False): |
|
438 |
if withsitewide: |
|
2223
59588e2d5cd1
close #343467, no sources sections in site properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
439 |
return sorted(k for k in self['propertydefs'] |
59588e2d5cd1
close #343467, no sources sections in site properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
440 |
if not k.startswith('sources.')) |
0 | 441 |
return sorted(k for k, kd in self['propertydefs'].iteritems() |
2223
59588e2d5cd1
close #343467, no sources sections in site properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
442 |
if not kd['sitewide'] and not k.startswith('sources.')) |
0 | 443 |
|
444 |
def register_property(self, key, type, help, default=None, vocabulary=None, |
|
445 |
sitewide=False): |
|
446 |
"""register a given property""" |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
447 |
properties = self['propertydefs'] |
0 | 448 |
assert type in YAMS_TO_PY |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
449 |
properties[key] = {'type': type, 'vocabulary': vocabulary, |
0 | 450 |
'default': default, 'help': help, |
451 |
'sitewide': sitewide} |
|
452 |
||
453 |
def property_info(self, key): |
|
454 |
"""return dictionary containing description associated to the given |
|
455 |
property key (including type, defaut value, help and a site wide |
|
456 |
boolean) |
|
457 |
""" |
|
458 |
try: |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
459 |
return self['propertydefs'][key] |
0 | 460 |
except KeyError: |
461 |
if key.startswith('system.version.'): |
|
462 |
soft = key.split('.')[-1] |
|
463 |
return {'type': 'String', 'sitewide': True, |
|
464 |
'default': None, 'vocabulary': None, |
|
465 |
'help': _('%s software version of the database') % soft} |
|
466 |
raise UnknownProperty('unregistered property %r' % key) |
|
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
467 |
|
0 | 468 |
def property_value(self, key): |
469 |
try: |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
470 |
return self['propertyvalues'][key] |
0 | 471 |
except KeyError: |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
472 |
return self['propertydefs'][key]['default'] |
0 | 473 |
|
474 |
def typed_value(self, key, value): |
|
475 |
"""value is an unicode string, return it correctly typed. Let potential |
|
476 |
type error propagates. |
|
477 |
""" |
|
478 |
pdef = self.property_info(key) |
|
479 |
try: |
|
480 |
value = YAMS_TO_PY[pdef['type']](value) |
|
481 |
except (TypeError, ValueError): |
|
482 |
raise ValueError(_('bad value')) |
|
483 |
vocab = pdef['vocabulary'] |
|
484 |
if vocab is not None: |
|
485 |
if callable(vocab): |
|
486 |
vocab = vocab(key, None) # XXX need a req object |
|
487 |
if not value in vocab: |
|
488 |
raise ValueError(_('unauthorized value')) |
|
489 |
return value |
|
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
490 |
|
0 | 491 |
def init_properties(self, propvalues): |
492 |
"""init the property values registry using the given set of couple (key, value) |
|
493 |
""" |
|
494 |
self.initialized = True |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
495 |
values = self['propertyvalues'] |
0 | 496 |
for key, val in propvalues: |
497 |
try: |
|
498 |
values[key] = self.typed_value(key, val) |
|
3951
b64c73bdb37b
fix name error if ValueError is raised
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3719
diff
changeset
|
499 |
except ValueError, ex: |
0 | 500 |
self.warning('%s (you should probably delete that property ' |
501 |
'from the database)', ex) |
|
502 |
except UnknownProperty, ex: |
|
503 |
self.warning('%s (you should probably delete that property ' |
|
504 |
'from the database)', ex) |
|
505 |
||
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
506 |
# deprecated code #################################################### |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
507 |
|
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
508 |
@deprecated('[3.4] use vreg["etypes"].etype_class(etype)') |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
509 |
def etype_class(self, etype): |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
510 |
return self["etypes"].etype_class(etype) |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
511 |
|
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
512 |
@deprecated('[3.4] use vreg["views"].main_template(*args, **kwargs)') |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
513 |
def main_template(self, req, oid='main-template', **context): |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
514 |
return self["views"].main_template(req, oid, **context) |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
515 |
|
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
516 |
@deprecated('[3.4] use vreg[registry].possible_vobjects(*args, **kwargs)') |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
517 |
def possible_vobjects(self, registry, *args, **kwargs): |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
518 |
return self[registry].possible_vobjects(*args, **kwargs) |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
519 |
|
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
520 |
@deprecated('[3.4] use vreg["actions"].possible_actions(*args, **kwargs)') |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
521 |
def possible_actions(self, req, rset=None, **kwargs): |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
522 |
return self["actions"].possible_actions(req, rest=rset, **kwargs) |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
523 |
|
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
524 |
@deprecated('[3.4] use vreg["boxes"].select_object(...)') |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
525 |
def select_box(self, oid, *args, **kwargs): |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
526 |
return self['boxes'].select_object(oid, *args, **kwargs) |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
527 |
|
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
528 |
@deprecated('[3.4] use vreg["components"].select_object(...)') |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
529 |
def select_component(self, cid, *args, **kwargs): |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
530 |
return self['components'].select_object(cid, *args, **kwargs) |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
531 |
|
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
532 |
@deprecated('[3.4] use vreg["actions"].select_object(...)') |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
533 |
def select_action(self, oid, *args, **kwargs): |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
534 |
return self['actions'].select_object(oid, *args, **kwargs) |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
535 |
|
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
536 |
@deprecated('[3.4] use vreg["views"].select(...)') |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
537 |
def select_view(self, __vid, req, rset=None, **kwargs): |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
538 |
return self['views'].select(__vid, req, rset=rset, **kwargs) |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
539 |
|
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
540 |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
823
diff
changeset
|
541 |
from datetime import datetime, date, time, timedelta |
0 | 542 |
|
543 |
YAMS_TO_PY = { |
|
544 |
'Boolean': bool, |
|
545 |
'String' : unicode, |
|
546 |
'Password': str, |
|
547 |
'Bytes': Binary, |
|
548 |
'Int': int, |
|
549 |
'Float': float, |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
823
diff
changeset
|
550 |
'Date': date, |
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
823
diff
changeset
|
551 |
'Datetime': datetime, |
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
823
diff
changeset
|
552 |
'Time': time, |
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
823
diff
changeset
|
553 |
'Interval': timedelta, |
0 | 554 |
} |
555 |