author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Sun, 02 Aug 2009 19:32:57 +0200 | |
changeset 2651 | 3ad936634d2a |
parent 2613 | 5e19c2bb370e |
child 2655 | 48cd71bdb5cd |
permissions | -rw-r--r-- |
0 | 1 |
"""extend the generic VRegistry with some cubicweb specific stuff |
2 |
||
3 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1923
diff
changeset
|
4 |
:copyright: 2001-2009 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 |
|
11 |
from logilab.common.decorators import cached, clear_cache |
|
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 |
0 | 13 |
|
14 |
from rql import RQLHelper |
|
15 |
||
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
|
16 |
from cubicweb import (ETYPE_NAME_MAP, Binary, UnknownProperty, UnknownEid, |
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 |
RegistryOutOfDate) |
0 | 18 |
from cubicweb.vregistry import VRegistry, ObjectNotFound, NoSelectableObject |
1769
fb91d2b8a441
fix some rtags pb on i18n catalog generation
sylvain.thenault@logilab.fr
parents:
1752
diff
changeset
|
19 |
from cubicweb.rtags import RTAGS |
0 | 20 |
|
21 |
||
776 | 22 |
def use_interfaces(obj): |
1132 | 23 |
"""return interfaces used by the given object by searchinf for implements |
24 |
selectors, with a bw compat fallback to accepts_interfaces attribute |
|
25 |
""" |
|
776 | 26 |
from cubicweb.selectors import implements |
27 |
try: |
|
28 |
# XXX deprecated |
|
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
29 |
return sorted(obj.accepts_interfaces) |
776 | 30 |
except AttributeError: |
31 |
try: |
|
32 |
impl = obj.__select__.search_selector(implements) |
|
33 |
if impl: |
|
34 |
return sorted(impl.expected_ifaces) |
|
35 |
except AttributeError: |
|
36 |
pass # old-style vobject classes with no accepts_interfaces |
|
1044
3672a7c86784
print message to help debugging selector on error
sylvain.thenault@logilab.fr
parents:
1037
diff
changeset
|
37 |
except: |
3672a7c86784
print message to help debugging selector on error
sylvain.thenault@logilab.fr
parents:
1037
diff
changeset
|
38 |
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
|
39 |
raise |
776 | 40 |
return () |
0 | 41 |
|
42 |
||
43 |
class CubicWebRegistry(VRegistry): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2389
diff
changeset
|
44 |
"""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
|
45 |
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
|
46 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2389
diff
changeset
|
47 |
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
|
48 |
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
|
49 |
|
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
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
|
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
|
54 |
* 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
|
55 |
* 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
|
56 |
* 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
|
57 |
* 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
|
58 |
* 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
|
59 |
* 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
|
60 |
* 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
|
61 |
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
|
62 |
* 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
|
63 |
""" |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
64 |
|
169
0e031b66cb0b
don't systematically init_log, it may breaks client log configuration
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
65 |
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
|
66 |
if initlog: |
0e031b66cb0b
don't systematically init_log, it may breaks client log configuration
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
67 |
# 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
|
68 |
config.init_log(debug=debug) |
0 | 69 |
super(CubicWebRegistry, self).__init__(config) |
70 |
self.schema = None |
|
71 |
self.reset() |
|
72 |
self.initialized = False |
|
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
73 |
|
0 | 74 |
def items(self): |
75 |
return [item for item in self._registries.items() |
|
76 |
if not item[0] in ('propertydefs', 'propertyvalues')] |
|
77 |
||
78 |
def values(self): |
|
1132 | 79 |
return [value for key, value in self._registries.items() |
0 | 80 |
if not key in ('propertydefs', 'propertyvalues')] |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
81 |
|
0 | 82 |
def reset(self): |
83 |
self._registries = {} |
|
84 |
self._lastmodifs = {} |
|
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
85 |
self._needs_iface = {} |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
86 |
# two special registries, propertydefs which care all the property |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
87 |
# definitions, and propertyvals which contains values for those |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
88 |
# properties |
0 | 89 |
self._registries['propertydefs'] = {} |
90 |
self._registries['propertyvalues'] = self.eprop_values = {} |
|
91 |
for key, propdef in self.config.eproperty_definitions(): |
|
92 |
self.register_property(key, **propdef) |
|
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
93 |
|
0 | 94 |
def set_schema(self, schema): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2389
diff
changeset
|
95 |
"""set instance'schema and load application objects""" |
0 | 96 |
self.schema = schema |
97 |
clear_cache(self, 'rqlhelper') |
|
98 |
# now we can load application's web objects |
|
99 |
self.register_objects(self.config.vregistry_path()) |
|
2273
daf6e178659f
new case_insensitive_etypes resource on the cubicweb registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2223
diff
changeset
|
100 |
# 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
|
101 |
self.case_insensitive_etypes = {} |
daf6e178659f
new case_insensitive_etypes resource on the cubicweb registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2223
diff
changeset
|
102 |
for etype in self.schema.entities(): |
daf6e178659f
new case_insensitive_etypes resource on the cubicweb registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2223
diff
changeset
|
103 |
etype = str(etype) |
daf6e178659f
new case_insensitive_etypes resource on the cubicweb registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2223
diff
changeset
|
104 |
self.case_insensitive_etypes[etype.lower()] = etype |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
105 |
|
0 | 106 |
def update_schema(self, schema): |
107 |
"""update .schema attribute on registered objects, necessary for some |
|
108 |
tests |
|
109 |
""" |
|
110 |
self.schema = schema |
|
111 |
for registry, regcontent in self._registries.items(): |
|
112 |
if registry in ('propertydefs', 'propertyvalues'): |
|
113 |
continue |
|
114 |
for objects in regcontent.values(): |
|
115 |
for obj in objects: |
|
116 |
obj.schema = schema |
|
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
117 |
|
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
118 |
def register_if_interface_found(self, obj, ifaces, **kwargs): |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
119 |
"""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
|
120 |
the given interfaces |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
121 |
""" |
785 | 122 |
self.register(obj, **kwargs) |
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
123 |
if not isinstance(ifaces, (tuple, list)): |
785 | 124 |
self._needs_iface[obj] = (ifaces,) |
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
125 |
else: |
785 | 126 |
self._needs_iface[obj] = ifaces |
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
127 |
|
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
128 |
def register(self, obj, **kwargs): |
717 | 129 |
if kwargs.get('registryname', obj.__registry__) == 'etypes': |
1037
1f3fae8d82b2
don't fail if vobjects reference an unexistant class
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
130 |
if obj.id != 'Any' and not obj.id in self.schema: |
1132 | 131 |
self.error('don\'t register %s, %s type not defined in the ' |
132 |
'schema', obj, obj.id) |
|
0 | 133 |
return |
717 | 134 |
kwargs['clear'] = True |
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
135 |
super(CubicWebRegistry, self).register(obj, **kwargs) |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
136 |
# XXX bw compat |
777
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
776
diff
changeset
|
137 |
ifaces = use_interfaces(obj) |
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
138 |
if ifaces: |
785 | 139 |
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
|
140 |
|
0 | 141 |
def register_objects(self, path, force_reload=None): |
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
142 |
"""overriden to remove objects requiring a missing interface""" |
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
|
143 |
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
|
144 |
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
|
145 |
except RegistryOutOfDate: |
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
|
146 |
# modification detected, reset and 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
|
147 |
self.reset() |
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
|
148 |
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
|
149 |
|
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
|
150 |
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
|
151 |
"""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
|
152 |
extrapath = {} |
010a4b0fe855
fix lookup of files to load when using CW_CUBES_PATH
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1985
diff
changeset
|
153 |
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
|
154 |
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
|
155 |
extrapath[cubesdir] = 'cubes' |
010a4b0fe855
fix lookup of files to load when using CW_CUBES_PATH
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1985
diff
changeset
|
156 |
if super(CubicWebRegistry, self).register_objects(path, force_reload, |
010a4b0fe855
fix lookup of files to load when using CW_CUBES_PATH
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1985
diff
changeset
|
157 |
extrapath): |
1638 | 158 |
self.initialization_completed() |
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
|
159 |
# call vreg_initialization_completed on appobjects and print |
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
|
160 |
# registry content |
1282
272d8ec6f308
* print vreg content once fully initialized (require move of print code from vregistry to cwvreg)
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
161 |
for registry, objects in self.items(): |
272d8ec6f308
* print vreg content once fully initialized (require move of print code from vregistry to cwvreg)
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
162 |
self.debug('available in registry %s: %s', registry, |
272d8ec6f308
* print vreg content once fully initialized (require move of print code from vregistry to cwvreg)
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
163 |
sorted(objects)) |
272d8ec6f308
* print vreg content once fully initialized (require move of print code from vregistry to cwvreg)
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
164 |
for appobjects in objects.itervalues(): |
272d8ec6f308
* print vreg content once fully initialized (require move of print code from vregistry to cwvreg)
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
165 |
for appobject in appobjects: |
272d8ec6f308
* print vreg content once fully initialized (require move of print code from vregistry to cwvreg)
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
166 |
appobject.vreg_initialization_completed() |
1769
fb91d2b8a441
fix some rtags pb on i18n catalog generation
sylvain.thenault@logilab.fr
parents:
1752
diff
changeset
|
167 |
# 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
|
168 |
for rtag in RTAGS: |
1769
fb91d2b8a441
fix some rtags pb on i18n catalog generation
sylvain.thenault@logilab.fr
parents:
1752
diff
changeset
|
169 |
rtag.init(self.schema, |
fb91d2b8a441
fix some rtags pb on i18n catalog generation
sylvain.thenault@logilab.fr
parents:
1752
diff
changeset
|
170 |
check=self.config.cleanup_interface_sobjects) |
0 | 171 |
|
1638 | 172 |
def initialization_completed(self): |
173 |
# clear etype cache if you don't want to run into deep weirdness |
|
174 |
clear_cache(self, 'etype_class') |
|
175 |
# we may want to keep interface dependent objects (e.g.for i18n |
|
176 |
# catalog generation) |
|
177 |
if self.config.cleanup_interface_sobjects: |
|
178 |
# remove vobjects that don't support any available interface |
|
179 |
implemented_interfaces = set() |
|
180 |
if 'Any' in self.get('etypes', ()): |
|
181 |
for etype in self.schema.entities(): |
|
182 |
cls = self.etype_class(etype) |
|
183 |
for iface in cls.__implements__: |
|
184 |
implemented_interfaces.update(iface.__mro__) |
|
185 |
implemented_interfaces.update(cls.__mro__) |
|
186 |
for obj, ifaces in self._needs_iface.items(): |
|
187 |
ifaces = frozenset(isinstance(iface, basestring) |
|
188 |
and iface in self.schema |
|
189 |
and self.etype_class(iface) |
|
190 |
or iface |
|
191 |
for iface in ifaces) |
|
192 |
if not ('Any' in ifaces or ifaces & implemented_interfaces): |
|
193 |
self.debug('kicking vobject %s (no implemented ' |
|
194 |
'interface among %s)', obj, ifaces) |
|
195 |
self.unregister(obj) |
|
196 |
# clear needs_iface so we don't try to remove some not-anymore-in |
|
197 |
# objects on automatic reloading |
|
198 |
self._needs_iface.clear() |
|
199 |
||
0 | 200 |
@cached |
201 |
def etype_class(self, etype): |
|
202 |
"""return an entity class for the given entity type. |
|
203 |
Try to find out a specific class for this kind of entity or |
|
204 |
default to a dump of the class registered for 'Any' |
|
205 |
""" |
|
206 |
etype = str(etype) |
|
631
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
395
diff
changeset
|
207 |
if etype == 'Any': |
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
|
208 |
return self.select('etypes', 'Any', 'Any') |
0 | 209 |
eschema = self.schema.eschema(etype) |
210 |
baseschemas = [eschema] + eschema.ancestors() |
|
211 |
# browse ancestors from most specific to most generic and |
|
212 |
# try to find an associated custom entity class |
|
213 |
for baseschema in baseschemas: |
|
1923
3802c2e37e72
handle speaking to an instance using old entity types
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1917
diff
changeset
|
214 |
try: |
3802c2e37e72
handle speaking to an instance using old entity types
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1917
diff
changeset
|
215 |
btype = ETYPE_NAME_MAP[baseschema] |
3802c2e37e72
handle speaking to an instance using old entity types
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1917
diff
changeset
|
216 |
except KeyError: |
3802c2e37e72
handle speaking to an instance using old entity types
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1917
diff
changeset
|
217 |
btype = str(baseschema) |
0 | 218 |
try: |
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
|
219 |
cls = self.select('etypes', btype, etype) |
631
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
395
diff
changeset
|
220 |
break |
0 | 221 |
except ObjectNotFound: |
222 |
pass |
|
631
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
395
diff
changeset
|
223 |
else: |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
395
diff
changeset
|
224 |
# no entity class for any of the ancestors, fallback to the default |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
395
diff
changeset
|
225 |
# one |
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
|
226 |
cls = self.select('etypes', 'Any', etype) |
631
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
395
diff
changeset
|
227 |
return cls |
0 | 228 |
|
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
|
229 |
def render(self, __oid, req, __fallback_oid=None, __registry='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
|
230 |
rset=None, **kwargs): |
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
|
231 |
"""select object, or fallback object if specified and the first one |
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
|
232 |
isn't selectable, then render it |
0 | 233 |
""" |
234 |
try: |
|
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
|
235 |
obj = self.select(__registry, __oid, req, rset=rset, **kwargs) |
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
|
236 |
except NoSelectableObject: |
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 |
if __fallback_oid is None: |
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 |
raise |
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 |
obj = self.select(__registry, __fallback_oid, req, rset=rset, |
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 |
**kwargs) |
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
|
241 |
return obj.render(**kwargs) |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
242 |
|
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
816
diff
changeset
|
243 |
def main_template(self, req, oid='main-template', **context): |
0 | 244 |
"""display query by calling the given template (default to main), |
245 |
and returning the output as a string instead of requiring the [w]rite |
|
246 |
method as argument |
|
247 |
""" |
|
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
|
248 |
res = self.render(oid, req, **context) |
0 | 249 |
if isinstance(res, unicode): |
250 |
return res.encode(req.encoding) |
|
251 |
assert isinstance(res, str) |
|
252 |
return res |
|
253 |
||
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
|
254 |
def select_vobject(self, registry, oid, *args, **kwargs): |
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
|
255 |
selected = self.select_object(registry, oid, *args, **kwargs) |
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
|
256 |
if selected and selected.propval('visible'): |
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
|
257 |
return selected |
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
|
258 |
return None |
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
|
259 |
|
0 | 260 |
def possible_vobjects(self, registry, *args, **kwargs): |
261 |
"""return an ordered list of possible app objects in a given registry, |
|
262 |
supposing they support the 'visible' and 'order' properties (as most |
|
263 |
visualizable objects) |
|
264 |
""" |
|
265 |
return [x for x in sorted(self.possible_objects(registry, *args, **kwargs), |
|
266 |
key=lambda x: x.propval('order')) |
|
213
6842c3dee34b
adding files (formely appearing in jpl) specific to cubicweb
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
169
diff
changeset
|
267 |
if x.propval('visible')] |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
268 |
|
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
|
269 |
def possible_actions(self, req, rset=None, **kwargs): |
0 | 270 |
if rset is None: |
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
|
271 |
actions = self.possible_vobjects('actions', req, rset=rset, **kwargs) |
0 | 272 |
else: |
1381
6042f1b342bb
consider kwargs in possible_actions
sylvain.thenault@logilab.fr
parents:
1254
diff
changeset
|
273 |
actions = rset.possible_actions(**kwargs) # cached implementation |
0 | 274 |
result = {} |
275 |
for action in actions: |
|
276 |
result.setdefault(action.category, []).append(action) |
|
277 |
return result |
|
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
278 |
|
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
|
279 |
def possible_views(self, req, rset=None, **kwargs): |
0 | 280 |
"""return an iterator on possible views for this result set |
281 |
||
282 |
views returned are classes, not instances |
|
283 |
""" |
|
284 |
for vid, views in self.registry('views').items(): |
|
285 |
if vid[0] == '_': |
|
286 |
continue |
|
287 |
try: |
|
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
|
288 |
view = self.select_best(views, req, rset=rset, **kwargs) |
0 | 289 |
if view.linkable(): |
290 |
yield view |
|
291 |
except NoSelectableObject: |
|
292 |
continue |
|
395
cce260264122
catch Exception in case there is some unexepected selector bug
sylvain.thenault@logilab.fr
parents:
355
diff
changeset
|
293 |
except Exception: |
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
|
294 |
self.exception('error while trying to select %s view for %s', |
395
cce260264122
catch Exception in case there is some unexepected selector bug
sylvain.thenault@logilab.fr
parents:
355
diff
changeset
|
295 |
vid, rset) |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
296 |
|
2613
5e19c2bb370e
R [all] logilab.common 0.44 provides only deprecated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2476
diff
changeset
|
297 |
@deprecated("use .select_object('boxes', ...)") |
0 | 298 |
def select_box(self, oid, *args, **kwargs): |
299 |
"""return the most specific view according to the result set""" |
|
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
|
300 |
return self.select_object('boxes', oid, *args, **kwargs) |
0 | 301 |
|
2613
5e19c2bb370e
R [all] logilab.common 0.44 provides only deprecated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2476
diff
changeset
|
302 |
@deprecated("use .select_object('components', ...)") |
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
|
303 |
def select_component(self, cid, *args, **kwargs): |
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
|
304 |
"""return the most specific component according to the result set""" |
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
|
305 |
return self.select_object('components', cid, *args, **kwargs) |
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
|
306 |
|
2613
5e19c2bb370e
R [all] logilab.common 0.44 provides only deprecated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2476
diff
changeset
|
307 |
@deprecated("use .select_object('actions', ...)") |
0 | 308 |
def select_action(self, oid, *args, **kwargs): |
309 |
"""return the most specific view according to the result set""" |
|
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
|
310 |
return self.select_object('actions', oid, *args, **kwargs) |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
311 |
|
2613
5e19c2bb370e
R [all] logilab.common 0.44 provides only deprecated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2476
diff
changeset
|
312 |
@deprecated("use .select('views', ...)") |
1985
9c1db4e06095
move view method's logic on the registry, so it's easier to call it from outside an appobject. Also make rset argument optional
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
313 |
def select_view(self, __vid, req, rset=None, **kwargs): |
0 | 314 |
"""return the most specific view according to the result set""" |
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
|
315 |
return self.select('views', __vid, req, rset=rset, **kwargs) |
0 | 316 |
|
317 |
# properties handling ##################################################### |
|
318 |
||
319 |
def user_property_keys(self, withsitewide=False): |
|
320 |
if withsitewide: |
|
2223
59588e2d5cd1
close #343467, no sources sections in site properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
321 |
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
|
322 |
if not k.startswith('sources.')) |
0 | 323 |
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
|
324 |
if not kd['sitewide'] and not k.startswith('sources.')) |
0 | 325 |
|
326 |
def register_property(self, key, type, help, default=None, vocabulary=None, |
|
327 |
sitewide=False): |
|
328 |
"""register a given property""" |
|
329 |
properties = self._registries['propertydefs'] |
|
330 |
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
|
331 |
properties[key] = {'type': type, 'vocabulary': vocabulary, |
0 | 332 |
'default': default, 'help': help, |
333 |
'sitewide': sitewide} |
|
334 |
||
335 |
def property_info(self, key): |
|
336 |
"""return dictionary containing description associated to the given |
|
337 |
property key (including type, defaut value, help and a site wide |
|
338 |
boolean) |
|
339 |
""" |
|
340 |
try: |
|
341 |
return self._registries['propertydefs'][key] |
|
342 |
except KeyError: |
|
343 |
if key.startswith('system.version.'): |
|
344 |
soft = key.split('.')[-1] |
|
345 |
return {'type': 'String', 'sitewide': True, |
|
346 |
'default': None, 'vocabulary': None, |
|
347 |
'help': _('%s software version of the database') % soft} |
|
348 |
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
|
349 |
|
0 | 350 |
def property_value(self, key): |
351 |
try: |
|
352 |
return self._registries['propertyvalues'][key] |
|
353 |
except KeyError: |
|
354 |
return self._registries['propertydefs'][key]['default'] |
|
355 |
||
356 |
def typed_value(self, key, value): |
|
357 |
"""value is an unicode string, return it correctly typed. Let potential |
|
358 |
type error propagates. |
|
359 |
""" |
|
360 |
pdef = self.property_info(key) |
|
361 |
try: |
|
362 |
value = YAMS_TO_PY[pdef['type']](value) |
|
363 |
except (TypeError, ValueError): |
|
364 |
raise ValueError(_('bad value')) |
|
365 |
vocab = pdef['vocabulary'] |
|
366 |
if vocab is not None: |
|
367 |
if callable(vocab): |
|
368 |
vocab = vocab(key, None) # XXX need a req object |
|
369 |
if not value in vocab: |
|
370 |
raise ValueError(_('unauthorized value')) |
|
371 |
return value |
|
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
372 |
|
0 | 373 |
def init_properties(self, propvalues): |
374 |
"""init the property values registry using the given set of couple (key, value) |
|
375 |
""" |
|
376 |
self.initialized = True |
|
377 |
values = self._registries['propertyvalues'] |
|
378 |
for key, val in propvalues: |
|
379 |
try: |
|
380 |
values[key] = self.typed_value(key, val) |
|
381 |
except ValueError: |
|
382 |
self.warning('%s (you should probably delete that property ' |
|
383 |
'from the database)', ex) |
|
384 |
except UnknownProperty, ex: |
|
385 |
self.warning('%s (you should probably delete that property ' |
|
386 |
'from the database)', ex) |
|
387 |
||
388 |
def parse(self, session, rql, args=None): |
|
389 |
rqlst = self.rqlhelper.parse(rql) |
|
390 |
def type_from_eid(eid, session=session): |
|
391 |
return session.describe(eid)[0] |
|
1123
a8e2838f174a
catch UnknownEid and set empty solutions on select nodes
sylvain.thenault@logilab.fr
parents:
395
diff
changeset
|
392 |
try: |
a8e2838f174a
catch UnknownEid and set empty solutions on select nodes
sylvain.thenault@logilab.fr
parents:
395
diff
changeset
|
393 |
self.rqlhelper.compute_solutions(rqlst, {'eid': type_from_eid}, args) |
a8e2838f174a
catch UnknownEid and set empty solutions on select nodes
sylvain.thenault@logilab.fr
parents:
395
diff
changeset
|
394 |
except UnknownEid: |
a8e2838f174a
catch UnknownEid and set empty solutions on select nodes
sylvain.thenault@logilab.fr
parents:
395
diff
changeset
|
395 |
for select in rqlst.children: |
a8e2838f174a
catch UnknownEid and set empty solutions on select nodes
sylvain.thenault@logilab.fr
parents:
395
diff
changeset
|
396 |
select.solutions = [] |
0 | 397 |
return rqlst |
398 |
||
399 |
@property |
|
400 |
@cached |
|
401 |
def rqlhelper(self): |
|
402 |
return RQLHelper(self.schema, |
|
403 |
special_relations={'eid': 'uid', 'has_text': 'fti'}) |
|
404 |
||
169
0e031b66cb0b
don't systematically init_log, it may breaks client log configuration
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
405 |
|
0 | 406 |
class MulCnxCubicWebRegistry(CubicWebRegistry): |
407 |
"""special registry to be used when an application has to deal with |
|
408 |
connections to differents repository. This class add some additional wrapper |
|
409 |
trying to hide buggy class attributes since classes are not designed to be |
|
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
|
410 |
shared among multiple registries. |
0 | 411 |
""" |
412 |
def etype_class(self, etype): |
|
413 |
"""return an entity class for the given entity type. |
|
414 |
Try to find out a specific class for this kind of entity or |
|
415 |
default to a dump of the class registered for 'Any' |
|
416 |
""" |
|
417 |
usercls = super(MulCnxCubicWebRegistry, self).etype_class(etype) |
|
1917
eaf6e0edc509
fix etype_class(Any) when multiple sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1769
diff
changeset
|
418 |
if etype == 'Any': |
eaf6e0edc509
fix etype_class(Any) when multiple sources
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1769
diff
changeset
|
419 |
return usercls |
0 | 420 |
usercls.e_schema = self.schema.eschema(etype) |
421 |
return usercls |
|
422 |
||
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
|
423 |
def select_best(self, vobjects, *args, **kwargs): |
0 | 424 |
"""return an instance of the most specific object according |
425 |
to parameters |
|
426 |
||
2389
c399bd6a9c38
[reledit] separate value from landing zone
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2293
diff
changeset
|
427 |
raise NoSelectableObject if no object apply |
0 | 428 |
""" |
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
|
429 |
for vobjectcls in vobjects: |
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
|
430 |
self._fix_cls_attrs(vobjectcls) |
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
|
431 |
selected = super(MulCnxCubicWebRegistry, self).select_best( |
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
|
432 |
vobjects, *args, **kwargs) |
1923
3802c2e37e72
handle speaking to an instance using old entity types
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1917
diff
changeset
|
433 |
# redo the same thing on the instance so it won't use equivalent class |
3802c2e37e72
handle speaking to an instance using old entity types
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1917
diff
changeset
|
434 |
# attributes (which may change) |
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
|
435 |
self._fix_cls_attrs(selected) |
1923
3802c2e37e72
handle speaking to an instance using old entity types
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1917
diff
changeset
|
436 |
return selected |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
437 |
|
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
|
438 |
def _fix_cls_attrs(self, vobject): |
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
|
439 |
vobject.vreg = self |
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
|
440 |
vobject.schema = self.schema |
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
|
441 |
vobject.config = self.config |
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
|
442 |
|
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
|
443 |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
823
diff
changeset
|
444 |
from datetime import datetime, date, time, timedelta |
0 | 445 |
|
446 |
YAMS_TO_PY = { |
|
447 |
'Boolean': bool, |
|
448 |
'String' : unicode, |
|
449 |
'Password': str, |
|
450 |
'Bytes': Binary, |
|
451 |
'Int': int, |
|
452 |
'Float': float, |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
823
diff
changeset
|
453 |
'Date': date, |
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
823
diff
changeset
|
454 |
'Datetime': datetime, |
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
823
diff
changeset
|
455 |
'Time': time, |
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
823
diff
changeset
|
456 |
'Interval': timedelta, |
0 | 457 |
} |
458 |