Commit 62bd763f authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

kill register_appobject_class method, simplifying autoregistration. Update...

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.
parent d45cde54d464
......@@ -291,11 +291,6 @@ registered.',
this option is set to yes",
'group': 'email', 'inputlevel': 2,
}),
('disable-appobjects',
{'type' : 'csv', 'default': (),
'help': 'comma separated list of identifiers of application objects (<registry>.<oid>) to disable',
'group': 'appobjects', 'inputlevel': 2,
}),
)
# static and class methods used to get instance independant resources ##
......
......@@ -107,7 +107,7 @@ class InterfaceTC(CubicWebTC):
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 @@ class SpecializedEntityClassesTC(CubicWebTC):
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)
......
......@@ -115,7 +115,7 @@ class GAEBasedTC(TestCase):
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
......
......@@ -39,7 +39,7 @@ class RelationTagsTC(TestCase):
# __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)
......
......@@ -111,7 +111,7 @@ class MatchUserGroupsTC(CubicWebTC):
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:
......
......@@ -51,7 +51,7 @@ class VRegistryTC(TestCase):
__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
......
......@@ -408,52 +408,48 @@ class VRegistry(dict):
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'))
......
......@@ -52,7 +52,7 @@ class ManualCubicWebTCs(AutoPopulateTest):
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)
......
......@@ -299,7 +299,7 @@ class VRegistryTC(ViewSelectorTC):
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 @@ class RQLActionTC(ViewSelectorTC):
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()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment