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