45 |
45 |
46 class CWRegistry(Registry): |
46 class CWRegistry(Registry): |
47 def __init__(self, vreg): |
47 def __init__(self, vreg): |
48 super(CWRegistry, self).__init__(vreg.config) |
48 super(CWRegistry, self).__init__(vreg.config) |
49 self.vreg = vreg |
49 self.vreg = vreg |
50 self.schema = vreg.schema |
50 |
|
51 @property |
|
52 def schema(self): |
|
53 return self.vreg.schema |
51 |
54 |
52 def initialization_completed(self): |
55 def initialization_completed(self): |
53 pass |
56 pass |
54 |
57 |
55 @deprecated('[3.5] select object, then use obj.render()') |
58 @deprecated('[3.6] select object, then use obj.render()') |
56 def render(self, __oid, req, __fallback_oid=None, rset=None, **kwargs): |
59 def render(self, __oid, req, __fallback_oid=None, rset=None, **kwargs): |
57 """select object, or fallback object if specified and the first one |
60 """select object, or fallback object if specified and the first one |
58 isn't selectable, then render it |
61 isn't selectable, then render it |
59 """ |
62 """ |
60 try: |
63 try: |
61 obj = self.select(__oid, req, rset=rset, **kwargs) |
64 obj = self.select(__oid, req, rset=rset, **kwargs) |
62 except NoSelectableObject: |
65 except NoSelectableObject: |
63 if __fallback_oid is None: |
66 if __fallback_oid is None: |
64 raise |
67 raise |
65 obj = self.select(__fallback_oid, req, **kwargs) |
68 obj = self.select(__fallback_oid, req, rset=rset, **kwargs) |
66 return obj.render(**kwargs) |
69 return obj.render(**kwargs) |
67 |
70 |
68 @deprecated('[3.5] use select_or_none and test for obj.cw_propval("visible")') |
71 @deprecated('[3.6] use select_or_none and test for obj.cw_propval("visible")') |
69 def select_vobject(self, oid, *args, **kwargs): |
72 def select_vobject(self, oid, *args, **kwargs): |
70 selected = self.select_or_none(oid, *args, **kwargs) |
73 selected = self.select_or_none(oid, *args, **kwargs) |
71 if selected and selected.cw_propval('visible'): |
74 if selected and selected.cw_propval('visible'): |
72 return selected |
75 return selected |
73 return None |
76 return None |
78 visualizable objects) |
81 visualizable objects) |
79 """ |
82 """ |
80 return sorted([x for x in self.possible_objects(*args, **kwargs) |
83 return sorted([x for x in self.possible_objects(*args, **kwargs) |
81 if x.cw_propval('visible')], |
84 if x.cw_propval('visible')], |
82 key=lambda x: x.cw_propval('order')) |
85 key=lambda x: x.cw_propval('order')) |
83 possible_vobjects = deprecated('[3.5] use poss_visible_objects()')(poss_visible_objects) |
86 possible_vobjects = deprecated('[3.6] use poss_visible_objects()')(poss_visible_objects) |
84 |
87 |
85 |
88 |
86 VRegistry.REGISTRY_FACTORY[None] = CWRegistry |
89 VRegistry.REGISTRY_FACTORY[None] = CWRegistry |
87 |
90 |
88 |
91 |
107 @cached |
110 @cached |
108 def parent_classes(self, etype): |
111 def parent_classes(self, etype): |
109 if etype == 'Any': |
112 if etype == 'Any': |
110 return [self.etype_class('Any')] |
113 return [self.etype_class('Any')] |
111 eschema = self.schema.eschema(etype) |
114 eschema = self.schema.eschema(etype) |
112 parents = [cls.etype_class(e.type) for e in eschema.ancestors()] |
115 parents = [self.etype_class(e.type) for e in eschema.ancestors()] |
113 parents.append(self.etype_class('Any')) |
116 parents.append(self.etype_class('Any')) |
114 return parents |
117 return parents |
115 |
118 |
116 @cached |
119 @cached |
117 def etype_class(self, etype): |
120 def etype_class(self, etype): |
234 if initlog: |
237 if initlog: |
235 # first init log service |
238 # first init log service |
236 config.init_log(debug=debug) |
239 config.init_log(debug=debug) |
237 super(CubicWebVRegistry, self).__init__(config) |
240 super(CubicWebVRegistry, self).__init__(config) |
238 self.schema = None |
241 self.schema = None |
|
242 self.initialized = False |
239 self.reset() |
243 self.reset() |
240 self.initialized = False |
|
241 |
244 |
242 def setdefault(self, regid): |
245 def setdefault(self, regid): |
243 try: |
246 try: |
244 return self[regid] |
247 return self[regid] |
245 except RegistryNotFound: |
248 except RegistryNotFound: |
262 super(CubicWebVRegistry, self).reset(path, force_reload) |
265 super(CubicWebVRegistry, self).reset(path, force_reload) |
263 self._needs_iface = {} |
266 self._needs_iface = {} |
264 # two special registries, propertydefs which care all the property |
267 # two special registries, propertydefs which care all the property |
265 # definitions, and propertyvals which contains values for those |
268 # definitions, and propertyvals which contains values for those |
266 # properties |
269 # properties |
267 self['propertydefs'] = {} |
270 if not self.initialized: |
268 self['propertyvalues'] = {} |
271 self['propertydefs'] = {} |
269 for key, propdef in self.config.eproperty_definitions(): |
272 self['propertyvalues'] = self.eprop_values = {} |
270 self.register_property(key, **propdef) |
273 for key, propdef in self.config.eproperty_definitions(): |
|
274 self.register_property(key, **propdef) |
271 if path is not None and force_reload: |
275 if path is not None and force_reload: |
272 cleanup_sys_modules(path) |
276 cleanup_sys_modules(path) |
273 cubes = self.config.cubes() |
277 cubes = self.config.cubes() |
274 # if the fs code use some cubes not yet registered into the instance |
278 # if the fs code use some cubes not yet registered into the instance |
275 # we should cleanup sys.modules for those as well to avoid potential |
279 # we should cleanup sys.modules for those as well to avoid potential |