register_to needs the schema as argument
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 13 Aug 2009 10:58:29 +0200
changeset 2809 04fa75d43af4
parent 2808 497424219fb0
child 2810 550dae61eb88
register_to needs the schema as argument
server/hooksmanager.py
server/serverconfig.py
server/test/unittest_hooksmanager.py
--- a/server/hooksmanager.py	Thu Aug 13 10:57:57 2009 +0200
+++ b/server/hooksmanager.py	Thu Aug 13 10:58:29 2009 +0200
@@ -90,7 +90,7 @@
         class.
         """
         if isinstance(function_or_cls, type) and issubclass(function_or_cls, Hook):
-            for event, ertype in function_or_cls.register_to():
+            for event, ertype in function_or_cls.register_to(self.schema):
                 for hook in self._hooks[event][ertype]:
                     if getattr(hook, 'im_self', None).__class__ is function_or_cls:
                         self._hooks[event][ertype].remove(hook)
@@ -222,7 +222,7 @@
         return cls()
 
     @classmethod
-    def register_to(cls):
+    def register_to(cls, schema):
         if not cls.enabled:
             cls.warning('%s hook has been disabled', cls)
             return
@@ -241,7 +241,7 @@
                 yield event, ertype
                 done.add((event, ertype))
                 try:
-                    eschema = cls.schema.eschema(ertype)
+                    eschema = schema.eschema(ertype)
                 except KeyError:
                     # relation schema
                     pass
--- a/server/serverconfig.py	Thu Aug 13 10:57:57 2009 +0200
+++ b/server/serverconfig.py	Thu Aug 13 10:58:29 2009 +0200
@@ -263,7 +263,7 @@
         except RegistryNotFound:
             return hooks
         for hookdef in apphookdefs:
-            for event, ertype in hookdef.register_to():
+            for event, ertype in hookdef.register_to(vreg.schema):
                 if ertype == 'Any':
                     ertype = ''
                 cb = hookdef.make_callback(event)
--- a/server/test/unittest_hooksmanager.py	Thu Aug 13 10:57:57 2009 +0200
+++ b/server/test/unittest_hooksmanager.py	Thu Aug 13 10:58:29 2009 +0200
@@ -170,7 +170,7 @@
 
 class HookTC(CubicWebTC):
     def test_inheritance(self):
-        self.assertEquals(list(MyHook.register_to()),
+        self.assertEquals(list(MyHook.register_to(self.schema)),
                           zip(repeat('whatever'), ('Societe', 'Division', 'SubDivision'))
                           + zip(repeat('another'), ('Societe', 'Division', 'SubDivision')))