[doc] fix doc and tutorials about hooks and operations oldstable
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>
Fri, 29 Apr 2011 19:28:20 +0200
brancholdstable
changeset 7286 a0d3ea01f4bf
parent 7269 de8ae247bb04
child 7287 601ad29268ab
[doc] fix doc and tutorials about hooks and operations
doc/book/en/tutorials/advanced/part02_security.rst
server/hook.py
--- a/doc/book/en/tutorials/advanced/part02_security.rst	Thu Apr 28 15:29:12 2011 +0200
+++ b/doc/book/en/tutorials/advanced/part02_security.rst	Fri Apr 29 19:28:20 2011 +0200
@@ -190,9 +190,10 @@
     from cubicweb.selectors import is_instance
     from cubicweb.server import hook
 
-    class SetVisibilityOp(hook.Operation):
+    class SetVisibilityOp(hook.DataOperationMixIn, hook.Operation):
+
 	def precommit_event(self):
-	    for eid in self.session.transaction_data.pop('pending_visibility'):
+	    for eid in self.get_data():
 		entity = self.session.entity_from_eid(eid)
 		if entity.visibility == 'parent':
 		    entity.set_attributes(visibility=u'authenticated')
@@ -201,9 +202,9 @@
 	__regid__ = 'sytweb.setvisibility'
 	__select__ = hook.Hook.__select__ & is_instance('Folder', 'File', 'Comment')
 	events = ('after_add_entity',)
+
 	def __call__(self):
-	    hook.set_operation(self._cw, 'pending_visibility', self.entity.eid,
-			       SetVisibilityOp)
+	    SetVisibilityOp.get_instance(self._cw).add_data(self.entity.eid)
 
     class SetParentVisibilityHook(hook.Hook):
 	__regid__ = 'sytweb.setparentvisibility'
@@ -240,7 +241,7 @@
   - `self.entity` is the newly added entity on 'after_add_entity' events
 
   - `self.eidfrom` / `self.eidto` are the eid of the subject / object entity on
-    'after_add_relatiohn' events (you may also get the relation type using
+    'after_add_relation' events (you may also get the relation type using
     `self.rtype`)
 
 The `parent` visibility value is used to tell "propagate using parent security"
@@ -381,7 +382,7 @@
 test instance. The second one will be much quicker:
 
 .. sourcecode:: bash
-    
+
     $ pytest unittest_sytweb.py
     ========================  unittest_sytweb.py  ========================
     .
--- a/server/hook.py	Thu Apr 28 15:29:12 2011 +0200
+++ b/server/hook.py	Fri Apr 29 19:28:20 2011 +0200
@@ -801,9 +801,9 @@
     by redefining :meth:`_build_container` and :meth:`add_data`
 
     More optional parameters can be given to the `get_instance` operation, that
-    will be given to the operation constructer (though those parameters should
-    not vary accross different calls to this method for a same operation for
-    obvious reason).
+    will be given to the operation constructor (for obvious reasons those
+    parameters should not vary accross different calls to this method for a
+    given operation).
 
     .. Note::
         For sanity reason `get_data` will reset the operation, so that once