server/hooks.py
branchstable
changeset 3528 77a69de16709
parent 3508 d9915224f9a5
child 3554 26e586f3c15c
equal deleted inserted replaced
3527:efeb16ff93f3 3528:77a69de16709
   430     # source
   430     # source
   431     if fromsource == 'system' or \
   431     if fromsource == 'system' or \
   432        not session.repo.sources_by_uri[fromsource].support_relation('in_state'):
   432        not session.repo.sources_by_uri[fromsource].support_relation('in_state'):
   433         session.delete_relation(x, 'in_state', oldstate)
   433         session.delete_relation(x, 'in_state', oldstate)
   434     session.add_relation(x, 'in_state', newstate)
   434     session.add_relation(x, 'in_state', newstate)
       
   435 
       
   436 
       
   437 class FireAutotransitionOp(PreCommitOperation):
       
   438     """try to fire auto transition after state changes"""
       
   439 
       
   440     def precommit_event(self):
       
   441         session = self.session
       
   442         entity = self.entity
       
   443         autotrs = list(entity.possible_transitions('auto'))
       
   444         if autotrs:
       
   445             assert len(autotrs) == 1
       
   446             entity.fire_transition(autotrs[0])
   435 
   447 
   436 
   448 
   437 def before_add_trinfo(session, entity):
   449 def before_add_trinfo(session, entity):
   438     """check the transition is allowed, add missing information. Expect that:
   450     """check the transition is allowed, add missing information. Expect that:
   439     * wf_info_for inlined relation is set
   451     * wf_info_for inlined relation is set
   511     entity['from_state'] = fromstate.eid
   523     entity['from_state'] = fromstate.eid
   512     entity['to_state'] = deststateeid
   524     entity['to_state'] = deststateeid
   513     nocheck = session.transaction_data.setdefault('skip-security', set())
   525     nocheck = session.transaction_data.setdefault('skip-security', set())
   514     nocheck.add((entity.eid, 'from_state', fromstate.eid))
   526     nocheck.add((entity.eid, 'from_state', fromstate.eid))
   515     nocheck.add((entity.eid, 'to_state', deststateeid))
   527     nocheck.add((entity.eid, 'to_state', deststateeid))
       
   528     FireAutotransitionOp(session, entity=forentity)
       
   529 
   516 
   530 
   517 def after_add_trinfo(session, entity):
   531 def after_add_trinfo(session, entity):
   518     """change related entity state"""
   532     """change related entity state"""
   519     _change_state(session, entity['wf_info_for'],
   533     _change_state(session, entity['wf_info_for'],
   520                   entity['from_state'], entity['to_state'])
   534                   entity['from_state'], entity['to_state'])