equal
deleted
inserted
replaced
133 alternative method to schedule an operation from a hook, using the |
133 alternative method to schedule an operation from a hook, using the |
134 :func:`get_instance` class method. |
134 :func:`get_instance` class method. |
135 |
135 |
136 .. sourcecode:: python |
136 .. sourcecode:: python |
137 |
137 |
138 from cubicweb.server.hook import set_operation |
|
139 |
|
140 class CheckSubsidiaryCycleHook(Hook): |
138 class CheckSubsidiaryCycleHook(Hook): |
141 __regid__ = 'check_no_subsidiary_cycle' |
139 __regid__ = 'check_no_subsidiary_cycle' |
142 events = ('after_add_relation',) |
140 events = ('after_add_relation',) |
143 __select__ = Hook.__select__ & match_rtype('subsidiary_of') |
141 __select__ = Hook.__select__ & match_rtype('subsidiary_of') |
144 |
142 |
150 def precommit_event(self): |
148 def precommit_event(self): |
151 for eid in self.get_data(): |
149 for eid in self.get_data(): |
152 check_cycle(self.session, eid, self.rtype) |
150 check_cycle(self.session, eid, self.rtype) |
153 |
151 |
154 |
152 |
155 Here, we call :func:`set_operation` so that we will simply accumulate eids of |
153 Here, we call :func:`add_data` so that we will simply accumulate eids of |
156 entities to check at the end in a single `CheckSubsidiaryCycleOp` |
154 entities to check at the end in a single `CheckSubsidiaryCycleOp` |
157 operation. Values are stored in a set associated to the |
155 operation. Values are stored in a set associated to the |
158 'subsidiary_cycle_detection' transaction data key. The set initialization and |
156 'subsidiary_cycle_detection' transaction data key. The set initialization and |
159 operation creation are handled nicely by :func:`set_operation`. |
157 operation creation are handled nicely by :func:`add_data`. |
160 |
158 |
161 A more realistic example can be found in the advanced tutorial chapter |
159 A more realistic example can be found in the advanced tutorial chapter |
162 :ref:`adv_tuto_security_propagation`. |
160 :ref:`adv_tuto_security_propagation`. |
163 |
161 |
164 |
162 |