author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Tue, 17 Feb 2009 22:49:54 +0100 | |
branch | tls-sprint |
changeset 713 | 5adb6d8e5fa7 |
parent 666 | 8ad9885ea45a |
child 717 | 54b873918b48 |
permissions | -rw-r--r-- |
0 | 1 |
"""extend the generic VRegistry with some cubicweb specific stuff |
2 |
||
3 |
:organization: Logilab |
|
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
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 |
""" |
|
7 |
__docformat__ = "restructuredtext en" |
|
8 |
||
9 |
from warnings import warn |
|
10 |
||
11 |
from logilab.common.decorators import cached, clear_cache |
|
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
|
12 |
from logilab.common.interface import extend |
0 | 13 |
|
14 |
from rql import RQLHelper |
|
15 |
||
16 |
from cubicweb import Binary, UnknownProperty |
|
17 |
from cubicweb.vregistry import VRegistry, ObjectNotFound, NoSelectableObject |
|
18 |
||
19 |
_ = unicode |
|
20 |
||
21 |
class DummyCursorError(Exception): pass |
|
22 |
class RaiseCursor: |
|
23 |
@classmethod |
|
24 |
def execute(cls, rql, args=None, eid_key=None): |
|
25 |
raise DummyCursorError() |
|
26 |
||
27 |
||
28 |
class CubicWebRegistry(VRegistry): |
|
29 |
"""extend the generic VRegistry with some cubicweb specific stuff""" |
|
30 |
||
169
0e031b66cb0b
don't systematically init_log, it may breaks client log configuration
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
31 |
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
|
32 |
if initlog: |
0e031b66cb0b
don't systematically init_log, it may breaks client log configuration
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
33 |
# 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
|
34 |
config.init_log(debug=debug) |
0 | 35 |
super(CubicWebRegistry, self).__init__(config) |
36 |
self.schema = None |
|
37 |
self.reset() |
|
38 |
self.initialized = False |
|
39 |
||
40 |
def items(self): |
|
41 |
return [item for item in self._registries.items() |
|
42 |
if not item[0] in ('propertydefs', 'propertyvalues')] |
|
43 |
||
44 |
def values(self): |
|
45 |
return [value for key,value in self._registries.items() |
|
46 |
if not key in ('propertydefs', 'propertyvalues')] |
|
47 |
||
48 |
def reset(self): |
|
49 |
self._registries = {} |
|
50 |
self._lastmodifs = {} |
|
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
51 |
self._needs_iface = {} |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
52 |
# two special registries, propertydefs which care all the property |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
53 |
# definitions, and propertyvals which contains values for those |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
54 |
# properties |
0 | 55 |
self._registries['propertydefs'] = {} |
56 |
self._registries['propertyvalues'] = self.eprop_values = {} |
|
57 |
for key, propdef in self.config.eproperty_definitions(): |
|
58 |
self.register_property(key, **propdef) |
|
59 |
||
60 |
def set_schema(self, schema): |
|
61 |
"""set application'schema and load application objects""" |
|
62 |
self.schema = schema |
|
63 |
clear_cache(self, 'rqlhelper') |
|
64 |
# now we can load application's web objects |
|
65 |
self.register_objects(self.config.vregistry_path()) |
|
66 |
||
67 |
def update_schema(self, schema): |
|
68 |
"""update .schema attribute on registered objects, necessary for some |
|
69 |
tests |
|
70 |
""" |
|
71 |
self.schema = schema |
|
72 |
for registry, regcontent in self._registries.items(): |
|
73 |
if registry in ('propertydefs', 'propertyvalues'): |
|
74 |
continue |
|
75 |
for objects in regcontent.values(): |
|
76 |
for obj in objects: |
|
77 |
obj.schema = schema |
|
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
78 |
|
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
79 |
def register_if_interface_found(self, obj, ifaces, **kwargs): |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
80 |
"""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
|
81 |
the given interfaces |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
82 |
""" |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
83 |
if not isinstance(ifaces, (tuple, list)): |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
84 |
self._needs_iface[obj] = frozenset((ifaces,)) |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
85 |
else: |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
86 |
self._needs_iface[obj] = frozenset(ifaces) |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
87 |
self.register(obj, **kwargs) |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
88 |
|
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
89 |
def register(self, obj, **kwargs): |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
90 |
super(CubicWebRegistry, self).register(obj, **kwargs) |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
91 |
# XXX bw compat |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
92 |
ifaces = getattr(obj, 'accepts_interfaces', None) |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
93 |
if ifaces: |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
94 |
self._needs_iface[obj] = frozenset(ifaces) |
0 | 95 |
|
96 |
def register_objects(self, path, force_reload=None): |
|
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
97 |
"""overriden to remove objects requiring a missing interface""" |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
98 |
if super(CubicWebRegistry, self).register_objects(path, force_reload): |
0 | 99 |
# clear etype cache if you don't want to run into deep weirdness |
100 |
clear_cache(self, 'etype_class') |
|
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
101 |
# we may want to keep interface dependent objects (e.g.for i18n |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
102 |
# catalog generation) |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
103 |
if not self.config.cleanup_interface_sobjects: |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
104 |
return |
0 | 105 |
# remove vobjects that don't support any available interface |
106 |
interfaces = set() |
|
107 |
for classes in self.get('etypes', {}).values(): |
|
108 |
for cls in classes: |
|
109 |
interfaces.update(cls.__implements__) |
|
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
110 |
for obj, ifaces in self._needs_iface.items(): |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
111 |
if not ifaces & interfaces: |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
112 |
self.debug('kicking vobject %s (unsupported interface)', obj) |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
113 |
self.unregister(obj) |
0 | 114 |
|
115 |
def eid_rset(self, cursor, eid, etype=None): |
|
116 |
"""return a result set for the given eid without doing actual query |
|
117 |
(we have the eid, we can suppose it exists and user has access to the |
|
118 |
entity) |
|
119 |
""" |
|
120 |
msg = '.eid_rset is deprecated, use req.eid_rset' |
|
121 |
warn(msg, DeprecationWarning, stacklevel=2) |
|
122 |
try: |
|
123 |
return cursor.req.eid_rset(eid, etype) |
|
124 |
except AttributeError: |
|
125 |
# cursor is a session |
|
126 |
return cursor.eid_rset(eid, etype) |
|
127 |
||
128 |
@cached |
|
129 |
def etype_class(self, etype): |
|
130 |
"""return an entity class for the given entity type. |
|
131 |
Try to find out a specific class for this kind of entity or |
|
132 |
default to a dump of the class registered for 'Any' |
|
133 |
""" |
|
134 |
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
|
135 |
if etype == 'Any': |
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
|
136 |
return self.select(self.registry_objects('etypes', 'Any'), 'Any') |
0 | 137 |
eschema = self.schema.eschema(etype) |
138 |
baseschemas = [eschema] + eschema.ancestors() |
|
139 |
# browse ancestors from most specific to most generic and |
|
140 |
# try to find an associated custom entity class |
|
141 |
for baseschema in baseschemas: |
|
142 |
btype = str(baseschema) |
|
143 |
try: |
|
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
|
144 |
cls = self.select(self.registry_objects('etypes', btype), etype) |
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
|
145 |
break |
0 | 146 |
except ObjectNotFound: |
147 |
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
|
148 |
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
|
149 |
# 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
|
150 |
# one |
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
|
151 |
cls = self.select(self.registry_objects('etypes', 'Any'), etype) |
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
|
152 |
# add class itself to the list of implemented interfaces, as well as the |
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
|
153 |
# Any entity class so we can select according to class using the |
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
|
154 |
# `implements` selector |
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
|
155 |
extend(cls, cls) |
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
|
156 |
extend(cls, self.etype_class('Any')) |
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
|
157 |
return cls |
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
|
158 |
|
0 | 159 |
def render(self, registry, oid, req, **context): |
160 |
"""select an object in a given registry and render it |
|
161 |
||
162 |
- registry: the registry's name |
|
163 |
- oid : the view to call |
|
164 |
- req : the HTTP request |
|
165 |
""" |
|
166 |
objclss = self.registry_objects(registry, oid) |
|
167 |
try: |
|
168 |
rset = context.pop('rset') |
|
169 |
except KeyError: |
|
170 |
rset = None |
|
171 |
selected = self.select(objclss, req, rset, **context) |
|
172 |
return selected.dispatch(**context) |
|
173 |
||
174 |
def main_template(self, req, oid='main', **context): |
|
175 |
"""display query by calling the given template (default to main), |
|
176 |
and returning the output as a string instead of requiring the [w]rite |
|
177 |
method as argument |
|
178 |
""" |
|
179 |
res = self.render('templates', oid, req, **context) |
|
180 |
if isinstance(res, unicode): |
|
181 |
return res.encode(req.encoding) |
|
182 |
assert isinstance(res, str) |
|
183 |
return res |
|
184 |
||
185 |
def possible_vobjects(self, registry, *args, **kwargs): |
|
186 |
"""return an ordered list of possible app objects in a given registry, |
|
187 |
supposing they support the 'visible' and 'order' properties (as most |
|
188 |
visualizable objects) |
|
189 |
""" |
|
190 |
return [x for x in sorted(self.possible_objects(registry, *args, **kwargs), |
|
191 |
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
|
192 |
if x.propval('visible')] |
0 | 193 |
|
194 |
def possible_actions(self, req, rset, **kwargs): |
|
195 |
if rset is None: |
|
196 |
actions = self.possible_vobjects('actions', req, rset) |
|
197 |
else: |
|
198 |
actions = rset.possible_actions() # cached implementation |
|
199 |
result = {} |
|
200 |
for action in actions: |
|
201 |
result.setdefault(action.category, []).append(action) |
|
202 |
return result |
|
203 |
||
204 |
def possible_views(self, req, rset, **kwargs): |
|
205 |
"""return an iterator on possible views for this result set |
|
206 |
||
207 |
views returned are classes, not instances |
|
208 |
""" |
|
209 |
for vid, views in self.registry('views').items(): |
|
210 |
if vid[0] == '_': |
|
211 |
continue |
|
212 |
try: |
|
213 |
view = self.select(views, req, rset, **kwargs) |
|
214 |
if view.linkable(): |
|
215 |
yield view |
|
216 |
except NoSelectableObject: |
|
217 |
continue |
|
395
cce260264122
catch Exception in case there is some unexepected selector bug
sylvain.thenault@logilab.fr
parents:
355
diff
changeset
|
218 |
except Exception: |
cce260264122
catch Exception in case there is some unexepected selector bug
sylvain.thenault@logilab.fr
parents:
355
diff
changeset
|
219 |
self.exception('error while trying to list possible %s views for %s', |
cce260264122
catch Exception in case there is some unexepected selector bug
sylvain.thenault@logilab.fr
parents:
355
diff
changeset
|
220 |
vid, rset) |
cce260264122
catch Exception in case there is some unexepected selector bug
sylvain.thenault@logilab.fr
parents:
355
diff
changeset
|
221 |
|
0 | 222 |
def select_box(self, oid, *args, **kwargs): |
223 |
"""return the most specific view according to the result set""" |
|
224 |
try: |
|
225 |
return self.select_object('boxes', oid, *args, **kwargs) |
|
226 |
except NoSelectableObject: |
|
227 |
return |
|
228 |
||
229 |
def select_action(self, oid, *args, **kwargs): |
|
230 |
"""return the most specific view according to the result set""" |
|
231 |
try: |
|
232 |
return self.select_object('actions', oid, *args, **kwargs) |
|
233 |
except NoSelectableObject: |
|
234 |
return |
|
235 |
||
236 |
def select_component(self, cid, *args, **kwargs): |
|
237 |
"""return the most specific component according to the result set""" |
|
238 |
try: |
|
239 |
return self.select_object('components', cid, *args, **kwargs) |
|
240 |
except (NoSelectableObject, ObjectNotFound): |
|
241 |
return |
|
242 |
||
243 |
def select_view(self, __vid, req, rset, **kwargs): |
|
244 |
"""return the most specific view according to the result set""" |
|
245 |
views = self.registry_objects('views', __vid) |
|
246 |
return self.select(views, req, rset, **kwargs) |
|
247 |
||
248 |
||
249 |
# properties handling ##################################################### |
|
250 |
||
251 |
def user_property_keys(self, withsitewide=False): |
|
252 |
if withsitewide: |
|
253 |
return sorted(self['propertydefs']) |
|
254 |
return sorted(k for k, kd in self['propertydefs'].iteritems() |
|
255 |
if not kd['sitewide']) |
|
256 |
||
257 |
def register_property(self, key, type, help, default=None, vocabulary=None, |
|
258 |
sitewide=False): |
|
259 |
"""register a given property""" |
|
260 |
properties = self._registries['propertydefs'] |
|
261 |
assert type in YAMS_TO_PY |
|
262 |
properties[key] = {'type': type, 'vocabulary': vocabulary, |
|
263 |
'default': default, 'help': help, |
|
264 |
'sitewide': sitewide} |
|
265 |
||
266 |
def property_info(self, key): |
|
267 |
"""return dictionary containing description associated to the given |
|
268 |
property key (including type, defaut value, help and a site wide |
|
269 |
boolean) |
|
270 |
""" |
|
271 |
try: |
|
272 |
return self._registries['propertydefs'][key] |
|
273 |
except KeyError: |
|
274 |
if key.startswith('system.version.'): |
|
275 |
soft = key.split('.')[-1] |
|
276 |
return {'type': 'String', 'sitewide': True, |
|
277 |
'default': None, 'vocabulary': None, |
|
278 |
'help': _('%s software version of the database') % soft} |
|
279 |
raise UnknownProperty('unregistered property %r' % key) |
|
280 |
||
281 |
def property_value(self, key): |
|
282 |
try: |
|
283 |
return self._registries['propertyvalues'][key] |
|
284 |
except KeyError: |
|
285 |
return self._registries['propertydefs'][key]['default'] |
|
286 |
||
287 |
def typed_value(self, key, value): |
|
288 |
"""value is an unicode string, return it correctly typed. Let potential |
|
289 |
type error propagates. |
|
290 |
""" |
|
291 |
pdef = self.property_info(key) |
|
292 |
try: |
|
293 |
value = YAMS_TO_PY[pdef['type']](value) |
|
294 |
except (TypeError, ValueError): |
|
295 |
raise ValueError(_('bad value')) |
|
296 |
vocab = pdef['vocabulary'] |
|
297 |
if vocab is not None: |
|
298 |
if callable(vocab): |
|
299 |
vocab = vocab(key, None) # XXX need a req object |
|
300 |
if not value in vocab: |
|
301 |
raise ValueError(_('unauthorized value')) |
|
302 |
return value |
|
303 |
||
304 |
def init_properties(self, propvalues): |
|
305 |
"""init the property values registry using the given set of couple (key, value) |
|
306 |
""" |
|
307 |
self.initialized = True |
|
308 |
values = self._registries['propertyvalues'] |
|
309 |
for key, val in propvalues: |
|
310 |
try: |
|
311 |
values[key] = self.typed_value(key, val) |
|
312 |
except ValueError: |
|
313 |
self.warning('%s (you should probably delete that property ' |
|
314 |
'from the database)', ex) |
|
315 |
except UnknownProperty, ex: |
|
316 |
self.warning('%s (you should probably delete that property ' |
|
317 |
'from the database)', ex) |
|
318 |
||
319 |
||
320 |
def property_value_widget(self, propkey, req=None, **attrs): |
|
321 |
"""return widget according to key's type / vocab""" |
|
322 |
from cubicweb.web.widgets import StaticComboBoxWidget, widget_factory |
|
323 |
if req is None: |
|
324 |
tr = unicode |
|
325 |
else: |
|
326 |
tr = req._ |
|
327 |
try: |
|
328 |
pdef = self.property_info(propkey) |
|
329 |
except UnknownProperty, ex: |
|
330 |
self.warning('%s (you should probably delete that property ' |
|
331 |
'from the database)', ex) |
|
332 |
return widget_factory(self, 'EProperty', self.schema['value'], 'String', |
|
333 |
description=u'', **attrs) |
|
334 |
req.form['value'] = pdef['default'] # XXX hack to pass the default value |
|
335 |
vocab = pdef['vocabulary'] |
|
336 |
if vocab is not None: |
|
337 |
if callable(vocab): |
|
338 |
# list() just in case its a generator function |
|
339 |
vocabfunc = lambda e: list(vocab(propkey, req)) |
|
340 |
else: |
|
341 |
vocabfunc = lambda e: vocab |
|
342 |
w = StaticComboBoxWidget(self, 'EProperty', self.schema['value'], 'String', |
|
343 |
vocabfunc=vocabfunc, description=tr(pdef['help']), |
|
344 |
**attrs) |
|
345 |
else: |
|
346 |
w = widget_factory(self, 'EProperty', self.schema['value'], pdef['type'], |
|
347 |
description=tr(pdef['help']), **attrs) |
|
348 |
return w |
|
349 |
||
350 |
def parse(self, session, rql, args=None): |
|
351 |
rqlst = self.rqlhelper.parse(rql) |
|
352 |
def type_from_eid(eid, session=session): |
|
353 |
return session.describe(eid)[0] |
|
354 |
self.rqlhelper.compute_solutions(rqlst, {'eid': type_from_eid}, args) |
|
355 |
return rqlst |
|
356 |
||
357 |
@property |
|
358 |
@cached |
|
359 |
def rqlhelper(self): |
|
360 |
return RQLHelper(self.schema, |
|
361 |
special_relations={'eid': 'uid', 'has_text': 'fti'}) |
|
362 |
||
169
0e031b66cb0b
don't systematically init_log, it may breaks client log configuration
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
363 |
|
0 | 364 |
class MulCnxCubicWebRegistry(CubicWebRegistry): |
365 |
"""special registry to be used when an application has to deal with |
|
366 |
connections to differents repository. This class add some additional wrapper |
|
367 |
trying to hide buggy class attributes since classes are not designed to be |
|
368 |
shared. |
|
369 |
""" |
|
370 |
def etype_class(self, etype): |
|
371 |
"""return an entity class for the given entity type. |
|
372 |
Try to find out a specific class for this kind of entity or |
|
373 |
default to a dump of the class registered for 'Any' |
|
374 |
""" |
|
375 |
usercls = super(MulCnxCubicWebRegistry, self).etype_class(etype) |
|
376 |
usercls.e_schema = self.schema.eschema(etype) |
|
377 |
return usercls |
|
378 |
||
379 |
def select(self, vobjects, *args, **kwargs): |
|
380 |
"""return an instance of the most specific object according |
|
381 |
to parameters |
|
382 |
||
383 |
raise NoSelectableObject if not object apply |
|
384 |
""" |
|
385 |
for vobject in vobjects: |
|
386 |
vobject.vreg = self |
|
387 |
vobject.schema = self.schema |
|
388 |
vobject.config = self.config |
|
389 |
return super(MulCnxCubicWebRegistry, self).select(vobjects, *args, **kwargs) |
|
390 |
||
391 |
from mx.DateTime import DateTime, Time, DateTimeDelta |
|
392 |
||
393 |
YAMS_TO_PY = { |
|
394 |
'Boolean': bool, |
|
395 |
'String' : unicode, |
|
396 |
'Password': str, |
|
397 |
'Bytes': Binary, |
|
398 |
'Int': int, |
|
399 |
'Float': float, |
|
400 |
'Date': DateTime, |
|
401 |
'Datetime': DateTime, |
|
402 |
'Time': Time, |
|
403 |
'Interval': DateTimeDelta, |
|
404 |
} |
|
405 |