# HG changeset patch # User Sylvain Thénault # Date 1265626875 -3600 # Node ID a0f48c31b58ac8be717947a186df2d1a6193c71b # Parent d45cde54d464ddebf362dc57d8281a53dd9cfd5f kill register_appobject_class method, simplifying autoregistration. Update test accordingly (test which manually registers object should also properly call there __register__ method). Drop the disable-appobjects config file entry: no one used it since its introduction years ago. diff -r d45cde54d464 -r a0f48c31b58a cwconfig.py --- a/cwconfig.py Mon Feb 08 11:08:55 2010 +0100 +++ b/cwconfig.py Mon Feb 08 12:01:15 2010 +0100 @@ -291,11 +291,6 @@ this option is set to yes", 'group': 'email', 'inputlevel': 2, }), - ('disable-appobjects', - {'type' : 'csv', 'default': (), - 'help': 'comma separated list of identifiers of application objects (.) to disable', - 'group': 'appobjects', 'inputlevel': 2, - }), ) # static and class methods used to get instance independant resources ## diff -r d45cde54d464 -r a0f48c31b58a entities/test/unittest_base.py --- a/entities/test/unittest_base.py Mon Feb 08 11:08:55 2010 +0100 +++ b/entities/test/unittest_base.py Mon Feb 08 12:01:15 2010 +0100 @@ -107,7 +107,7 @@ class MyUser(CWUser): __implements__ = (IMileStone,) self.vreg._loadedmods[__name__] = {} - self.vreg.register_appobject_class(MyUser) + self.vreg.register(MyUser) self.vreg['etypes'].initialization_completed() MyUser_ = self.vreg['etypes'].etype_class('CWUser') # a copy is done systematically @@ -137,7 +137,7 @@ for etype in ('Company', 'Division', 'SubDivision'): class Foo(AnyEntity): __regid__ = etype - self.vreg.register_appobject_class(Foo) + self.vreg.register(Foo) eclass = self.select_eclass('SubDivision') self.failUnless(eclass.__autogenerated__) self.failIf(eclass is Foo) diff -r d45cde54d464 -r a0f48c31b58a goa/testlib.py --- a/goa/testlib.py Mon Feb 08 11:08:55 2010 +0100 +++ b/goa/testlib.py Mon Feb 08 12:01:15 2010 +0100 @@ -115,7 +115,7 @@ for module in self.LOAD_APP_MODULES: self.vreg.load_module(module) for cls in self.MODEL_CLASSES: - self.vreg.load_object(cls) + self.vreg.register(cls) self.session_manager = self.vreg.select('components', 'sessionmanager') if need_ds_init: # create default groups and create entities according to the schema diff -r d45cde54d464 -r a0f48c31b58a test/unittest_rtags.py --- a/test/unittest_rtags.py Mon Feb 08 11:08:55 2010 +0100 +++ b/test/unittest_rtags.py Mon Feb 08 12:01:15 2010 +0100 @@ -39,7 +39,7 @@ # __rtags__ = { # ('evaluee', 'Note', 'subject') : set(('inlineview',)), # } -# self.vreg.register_appobject_class(Personne2) +# self.vreg.register(Personne2) # rtags = Personne2.rtags # self.assertEquals(rtags.rtag('evaluee', 'Note', 'subject'), set(('inlineview', 'link'))) # self.assertEquals(rtags.is_inlined('evaluee', 'Note', 'subject'), True) diff -r d45cde54d464 -r a0f48c31b58a test/unittest_selectors.py --- a/test/unittest_selectors.py Mon Feb 08 11:08:55 2010 +0100 +++ b/test/unittest_selectors.py Mon Feb 08 12:01:15 2010 +0100 @@ -111,7 +111,7 @@ category = 'foo' __select__ = match_user_groups('owners') self.vreg._loadedmods[__name__] = {} - self.vreg.register_appobject_class(SomeAction) + self.vreg.register(SomeAction) SomeAction.__registered__(self.vreg['actions']) self.failUnless(SomeAction in self.vreg['actions']['yo'], self.vreg['actions']) try: diff -r d45cde54d464 -r a0f48c31b58a test/unittest_vregistry.py --- a/test/unittest_vregistry.py Mon Feb 08 11:08:55 2010 +0100 +++ b/test/unittest_vregistry.py Mon Feb 08 12:01:15 2010 +0100 @@ -51,7 +51,7 @@ __implements__ = (IMileStone,) self.vreg.reset() self.vreg._loadedmods[__name__] = {} - self.vreg.register_appobject_class(MyCard) + self.vreg.register(MyCard) self.vreg.register_objects([join(BASE, 'entities', '__init__.py'), join(BASE, 'web', 'views', 'iprogress.py')]) # check progressbar isn't kicked diff -r d45cde54d464 -r a0f48c31b58a vregistry.py --- a/vregistry.py Mon Feb 08 11:08:55 2010 +0100 +++ b/vregistry.py Mon Feb 08 12:01:15 2010 +0100 @@ -408,52 +408,48 @@ self._load_ancestors_then_object(module.__name__, obj) self.debug('loaded %s', module) - def _load_ancestors_then_object(self, modname, obj): + def _load_ancestors_then_object(self, modname, appobjectcls): + """handle automatic appobject class registration: + + - first ensure parent classes are already registered + + - class with __abstract__ == True in their local dictionnary or + with a name starting starting by an underscore are not registered + + - appobject class needs to have __registry__ and __regid__ attributes + set to a non empty string to be registered. + """ # imported classes - objmodname = getattr(obj, '__module__', None) + objmodname = getattr(appobjectcls, '__module__', None) if objmodname != modname: if objmodname in self._toloadmods: self.load_file(self._toloadmods[objmodname], objmodname) return # skip non registerable object try: - if not issubclass(obj, AppObject): + if not issubclass(appobjectcls, AppObject): return except TypeError: return - clsid = classid(obj) + clsid = classid(appobjectcls) if clsid in self._loadedmods[modname]: return - self._loadedmods[modname][clsid] = obj - for parent in obj.__bases__: + self._loadedmods[modname][clsid] = appobjectcls + for parent in appobjectcls.__bases__: self._load_ancestors_then_object(modname, parent) - self.load_object(obj) - - def load_object(self, obj): + if (appobjectcls.__dict__.get('__abstract__') + or appobjectcls.__name__[0] == '_' + or not appobjectcls.__registry__ + or not class_regid(appobjectcls)): + return try: - self.register_appobject_class(obj) + self.register(appobjectcls) except Exception, ex: if self.config.mode in ('test', 'dev'): raise - self.exception('appobject %s registration failed: %s', obj, ex) - - # old automatic registration XXX deprecated ############################### - - def register_appobject_class(self, cls): - """handle appobject class registration + self.exception('appobject %s registration failed: %s', + appobjectcls, ex) - appobject class with __abstract__ == True in their local dictionnary or - with a name starting starting by an underscore are not registered. - Also a appobject class needs to have __registry__ and id attributes set - to a non empty string to be registered. - """ - if (cls.__dict__.get('__abstract__') or cls.__name__[0] == '_' - or not cls.__registry__ or not class_regid(cls)): - return - regname = cls.__registry__ - if '%s.%s' % (regname, class_regid(cls)) in self.config['disable-appobjects']: - return - self.register(cls) # init logging set_log_methods(VRegistry, getLogger('cubicweb.vreg')) diff -r d45cde54d464 -r a0f48c31b58a web/test/test_views.py --- a/web/test/test_views.py Mon Feb 08 11:08:55 2010 +0100 +++ b/web/test/test_views.py Mon Feb 08 12:01:15 2010 +0100 @@ -52,7 +52,7 @@ def test_js_added_only_once(self): self.vreg._loadedmods[__name__] = {} - self.vreg.register_appobject_class(SomeView) + self.vreg.register(SomeView) rset = self.execute('CWUser X') source = self.view('someview', rset).source self.assertEquals(source.count('spam.js'), 1) diff -r d45cde54d464 -r a0f48c31b58a web/test/unittest_viewselector.py --- a/web/test/unittest_viewselector.py Mon Feb 08 11:08:55 2010 +0100 +++ b/web/test/unittest_viewselector.py Mon Feb 08 12:01:15 2010 +0100 @@ -299,7 +299,7 @@ class CWUserCreationForm(editforms.CreationFormView): __select__ = specified_etype_implements('CWUser') self.vreg._loadedmods[__name__] = {} - self.vreg.register_appobject_class(CWUserCreationForm) + self.vreg.register(CWUserCreationForm) req.form['etype'] = 'CWUser' self.assertIsInstance(self.vreg['views'].select('creation', req, rset=rset), CWUserCreationForm) @@ -467,7 +467,9 @@ def setUp(self): super(RQLActionTC, self).setUp() self.vreg._loadedmods[__name__] = {} - self.vreg.register_appobject_class(CWETypeRQLAction) + self.vreg.register(CWETypeRQLAction) + actionsreg = self.vreg['actions'] + actionsreg[0].__registered__(actionsreg) def tearDown(self): super(RQLActionTC, self).tearDown()