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