server/hooks.py
branchstable
changeset 3528 77a69de16709
parent 3508 d9915224f9a5
child 3554 26e586f3c15c
--- a/server/hooks.py	Wed Sep 30 16:06:04 2009 +0200
+++ b/server/hooks.py	Wed Sep 30 16:06:52 2009 +0200
@@ -434,6 +434,18 @@
     session.add_relation(x, 'in_state', newstate)
 
 
+class FireAutotransitionOp(PreCommitOperation):
+    """try to fire auto transition after state changes"""
+
+    def precommit_event(self):
+        session = self.session
+        entity = self.entity
+        autotrs = list(entity.possible_transitions('auto'))
+        if autotrs:
+            assert len(autotrs) == 1
+            entity.fire_transition(autotrs[0])
+
+
 def before_add_trinfo(session, entity):
     """check the transition is allowed, add missing information. Expect that:
     * wf_info_for inlined relation is set
@@ -513,6 +525,8 @@
     nocheck = session.transaction_data.setdefault('skip-security', set())
     nocheck.add((entity.eid, 'from_state', fromstate.eid))
     nocheck.add((entity.eid, 'to_state', deststateeid))
+    FireAutotransitionOp(session, entity=forentity)
+
 
 def after_add_trinfo(session, entity):
     """change related entity state"""