__init__.py
changeset 2689 44f041222d0f
parent 2683 52b1a86c1913
child 2705 30bcdbd92820
--- a/__init__.py	Tue Aug 04 18:44:24 2009 +0200
+++ b/__init__.py	Tue Aug 04 18:58:38 2009 +0200
@@ -348,3 +348,18 @@
                 callback(context, *args, **kwargs)
 
 CW_EVENT_MANAGER = CubicWebEventManager()
+
+def onevent(event):
+    """decorator to ease event / callback binding
+
+    >>> from cubicweb import onevent
+    >>> @onevent('before-source-reload')
+    ... def mycallback():
+    ...     print 'hello'
+    ...
+    >>>
+    """
+    def _decorator(func):
+        CW_EVENT_MANAGER.bind(event, func)
+        return func
+    return _decorator