server/hook.py
changeset 5160 27d4cab5db03
parent 5116 a2ce436e00ad
child 5162 6340ed9f8caf
--- a/server/hook.py	Tue Apr 06 19:08:07 2010 +0200
+++ b/server/hook.py	Tue Apr 06 19:58:04 2010 +0200
@@ -75,10 +75,7 @@
                     self.unregister(cls)
 
     def register(self, obj, **kwargs):
-        for event in obj.events:
-            if event not in ALL_HOOKS:
-                raise Exception('bad event %s on %s.%s' % (
-                    event, obj.__module__, obj.__name__))
+        obj.check_events()
         super(HooksRegistry, self).register(obj, **kwargs)
 
     def call_hooks(self, event, session=None, **kwargs):
@@ -199,10 +196,13 @@
     # XXX deprecated
     enabled = True
 
-    @classproperty
-    def __registries__(cls):
+    @classmethod
+    def check_events(cls):
         try:
-            return ['%s_hooks' % ev for ev in cls.events]
+            for event in cls.events:
+                if event not in ALL_HOOKS:
+                    raise Exception('bad event %s on %s.%s' % (
+                        event, obj.__module__, obj.__name__))
         except AttributeError:
             raise
         except TypeError:
@@ -210,6 +210,11 @@
                 cls.events, cls.__module__, cls.__name__))
 
     @classproperty
+    def __registries__(cls):
+        cls.check_events()
+        return ['%s_hooks' % ev for ev in cls.events]
+
+    @classproperty
     def __regid__(cls):
         warn('[3.6] %s.%s: please specify an id for your hook'
              % (cls.__module__, cls.__name__), DeprecationWarning)