--- a/doc/book/en/devrepo/repo/hooks.rst Fri Sep 24 18:37:03 2010 +0200
+++ b/doc/book/en/devrepo/repo/hooks.rst Fri Sep 24 18:38:24 2010 +0200
@@ -58,6 +58,10 @@
implementing `precommit_event` and other standard methods (wholly
described in :ref:`operations_api`).
+.. hint::
+
+ It is a good practice, to write unit tests for each hook. See an example in :ref:`hook_test`
+
Events
------
@@ -241,6 +245,8 @@
.. sourcecode:: python
+ from cubicweb.server.hook import Hook, Operation, match_rtype
+
def check_cycle(self, session, eid, rtype, role='subject'):
parents = set([eid])
parent = session.entity_from_eid(eid)
@@ -300,7 +306,7 @@
class CheckSubsidiaryCycleOp(Operation):
def precommit_event(self):
- for eid in self._cw.transaction_data['subsidiary_cycle_detection']:
+ for eid in self.session.transaction_data['subsidiary_cycle_detection']:
check_cycle(self.session, eid, self.rtype)
Here, we call set_operation with a session object, a specially forged