254 return sorted([x for x in self.possible_objects(*args, **kwargs) |
254 return sorted([x for x in self.possible_objects(*args, **kwargs) |
255 if x.cw_propval('visible')], |
255 if x.cw_propval('visible')], |
256 key=lambda x: x.cw_propval('order')) |
256 key=lambda x: x.cw_propval('order')) |
257 |
257 |
258 |
258 |
|
259 def related_appobject(obj, appobjectattr='__appobject__'): |
|
260 """ adapts any object to a potential appobject bound to it |
|
261 through the __appobject__ attribute |
|
262 """ |
|
263 return getattr(obj, appobjectattr, obj) |
|
264 |
259 |
265 |
260 class ETypeRegistry(CWRegistry): |
266 class ETypeRegistry(CWRegistry): |
261 |
267 |
262 def clear_caches(self): |
268 def clear_caches(self): |
263 clear_cache(self, 'etype_class') |
269 clear_cache(self, 'etype_class') |
270 super(ETypeRegistry, self).initialization_completed() |
276 super(ETypeRegistry, self).initialization_completed() |
271 # clear etype cache if you don't want to run into deep weirdness |
277 # clear etype cache if you don't want to run into deep weirdness |
272 self.clear_caches() |
278 self.clear_caches() |
273 |
279 |
274 def register(self, obj, **kwargs): |
280 def register(self, obj, **kwargs): |
|
281 obj = related_appobject(obj) |
275 oid = kwargs.get('oid') or obj.__regid__ |
282 oid = kwargs.get('oid') or obj.__regid__ |
276 if oid != 'Any' and not oid in self.schema: |
283 if oid != 'Any' and not oid in self.schema: |
277 self.error('don\'t register %s, %s type not defined in the ' |
284 self.error('don\'t register %s, %s type not defined in the ' |
278 'schema', obj, oid) |
285 'schema', obj, oid) |
279 return |
286 return |
535 def values(self): |
542 def values(self): |
536 return [value for key, value in self.items()] |
543 return [value for key, value in self.items()] |
537 def itervalues(self): |
544 def itervalues(self): |
538 return (value for key, value in self.items()) |
545 return (value for key, value in self.items()) |
539 |
546 |
|
547 def load_module(self, module): |
|
548 """ variation from the base implementation: |
|
549 apply related_appobject to the automatically registered objects |
|
550 """ |
|
551 self.info('loading %s from %s', module.__name__, module.__file__) |
|
552 if hasattr(module, 'registration_callback'): |
|
553 module.registration_callback(self) |
|
554 return |
|
555 for objname, obj in vars(module).iteritems(): |
|
556 if objname.startswith('_'): |
|
557 continue |
|
558 self._load_ancestors_then_object(module.__name__, |
|
559 related_appobject(obj)) |
|
560 |
540 def reset(self): |
561 def reset(self): |
541 CW_EVENT_MANAGER.emit('before-registry-reset', self) |
562 CW_EVENT_MANAGER.emit('before-registry-reset', self) |
542 super(CWRegistryStore, self).reset() |
563 super(CWRegistryStore, self).reset() |
543 self._needs_iface = {} |
564 self._needs_iface = {} |
544 self._needs_appobject = {} |
565 self._needs_appobject = {} |
549 self['propertydefs'] = {} |
570 self['propertydefs'] = {} |
550 self['propertyvalues'] = self.eprop_values = {} |
571 self['propertyvalues'] = self.eprop_values = {} |
551 for key, propdef in self.config.cwproperty_definitions(): |
572 for key, propdef in self.config.cwproperty_definitions(): |
552 self.register_property(key, **propdef) |
573 self.register_property(key, **propdef) |
553 CW_EVENT_MANAGER.emit('after-registry-reset', self) |
574 CW_EVENT_MANAGER.emit('after-registry-reset', self) |
|
575 |
|
576 def register_all(self, objects, modname, butclasses=()): |
|
577 butclasses = set(related_appobject(obj) |
|
578 for obj in butclasses) |
|
579 objects = [related_appobject(obj) for obj in objects] |
|
580 super(CWRegistryStore, self).register_all(objects, modname, butclasses) |
|
581 |
|
582 def register_and_replace(self, obj, replaced): |
|
583 obj = related_appobject(obj) |
|
584 replaced = related_appobject(replaced) |
|
585 super(CWRegistryStore, self).register_and_replace(obj, replaced) |
554 |
586 |
555 def set_schema(self, schema): |
587 def set_schema(self, schema): |
556 """set instance'schema and load application objects""" |
588 """set instance'schema and load application objects""" |
557 self._set_schema(schema) |
589 self._set_schema(schema) |
558 # now we can load application's web objects |
590 # now we can load application's web objects |
622 `obj.__regid__` if not specified. |
654 `obj.__regid__` if not specified. |
623 |
655 |
624 If `clear` is true, all objects with the same identifier will be |
656 If `clear` is true, all objects with the same identifier will be |
625 previously unregistered. |
657 previously unregistered. |
626 """ |
658 """ |
|
659 obj = related_appobject(obj) |
627 super(CWRegistryStore, self).register(obj, *args, **kwargs) |
660 super(CWRegistryStore, self).register(obj, *args, **kwargs) |
628 # XXX bw compat |
661 # XXX bw compat |
629 ifaces = use_interfaces(obj) |
662 ifaces = use_interfaces(obj) |
630 if ifaces: |
663 if ifaces: |
631 if not obj.__name__.endswith('Adapter') and \ |
664 if not obj.__name__.endswith('Adapter') and \ |