--- a/server/hooksmanager.py Thu May 14 10:24:56 2009 +0200
+++ b/server/hooksmanager.py Thu May 14 11:38:40 2009 +0200
@@ -28,7 +28,7 @@
"""
__docformat__ = "restructuredtext en"
-ENTITIES_HOOKS = ('before_add_entity', 'after_add_entity',
+ENTITIES_HOOKS = ('before_add_entity', 'after_add_entity',
'before_update_entity', 'after_update_entity',
'before_delete_entity', 'after_delete_entity')
RELATIONS_HOOKS = ('before_add_relation', 'after_add_relation' ,
@@ -42,7 +42,7 @@
"""handle hooks registration and calls
"""
verification_hooks_activated = True
-
+
def __init__(self, schema):
self.set_schema(schema)
@@ -50,20 +50,20 @@
self._hooks = {}
self.schema = schema
self._init_hooks(schema)
-
+
def register_hooks(self, hooks):
"""register a dictionary of hooks :
-
+
{'event': {'entity or relation type': [callbacks list]}}
"""
for event, subevents in hooks.items():
for subevent, callbacks in subevents.items():
for callback in callbacks:
self.register_hook(callback, event, subevent)
-
+
def register_hook(self, function, event, etype=''):
"""register a function to call when <event> occurs
-
+
<etype> is an entity/relation type or an empty string.
If etype is the empty string, the function will be called at each
event, else the function will be called only when event occurs on an
@@ -76,14 +76,14 @@
self._hooks[event][etype].append(function)
self.debug('registered hook %s on %s (%s)', event, etype or 'any',
function.func_name)
-
+
except KeyError:
self.error('can\'t register hook %s on %s (%s)',
event, etype or 'any', function.func_name)
-
+
def unregister_hook(self, function, event, etype=''):
"""register a function to call when <event> occurs
-
+
<etype> is an entity/relation type or an empty string.
If etype is the empty string, the function will be called at each
event, else the function will be called only when event occurs on an
@@ -109,7 +109,7 @@
for hook in self._hooks[__event][__type]:
#print '[%s]'%__type, hook.__name__
hook(*args, **kwargs)
-
+
def _init_hooks(self, schema):
"""initialize the hooks map"""
for hook_event in ENTITIES_HOOKS:
@@ -164,7 +164,7 @@
self.unregister_hook(uniquecstrcheck_before_modification, 'before_update_entity', '')
# self.unregister_hook(tidy_html_fields('before_add_entity'), 'before_add_entity', '')
# self.unregister_hook(tidy_html_fields('before_update_entity'), 'before_update_entity', '')
-
+
def reactivate_verification_hooks(self):
from cubicweb.server.hooks import (cardinalitycheck_after_add_entity,
cardinalitycheck_before_del_relation,
@@ -179,7 +179,7 @@
self.register_hook(uniquecstrcheck_before_modification, 'before_update_entity', '')
# self.register_hook(tidy_html_fields('before_add_entity'), 'before_add_entity', '')
# self.register_hook(tidy_html_fields('before_update_entity'), 'before_update_entity', '')
-
+
from cubicweb.selectors import yes
from cubicweb.appobject import AppObject
@@ -199,16 +199,16 @@
events = None
accepts = None
enabled = True
-
+
def __init__(self, event=None):
super(Hook, self).__init__()
self.event = event
-
+
@classmethod
def registered(cls, vreg):
super(Hook, cls).registered(vreg)
return cls()
-
+
@classmethod
def register_to(cls):
if not cls.enabled:
@@ -232,7 +232,7 @@
continue
yield event, str(eetype)
done.add((event, eetype))
-
+
def make_callback(self, event):
if len(self.events) == 1:
@@ -241,7 +241,7 @@
def call(self):
raise NotImplementedError
-
+
class SystemHook(Hook):
accepts = ('',)