459 """make initial state be a default state""" |
459 """make initial state be a default state""" |
460 |
460 |
461 def precommit_event(self): |
461 def precommit_event(self): |
462 session = self.session |
462 session = self.session |
463 entity = self.entity |
463 entity = self.entity |
464 rset = session.execute('Any S WHERE ET initial_state S, ET name %(name)s', |
|
465 {'name': str(entity.e_schema)}) |
|
466 # if there is an initial state and the entity's state is not set, |
464 # if there is an initial state and the entity's state is not set, |
467 # use the initial state as a default state |
465 # use the initial state as a default state |
468 pendingeids = session.transaction_data.get('pendingeids', ()) |
466 pendingeids = session.transaction_data.get('pendingeids', ()) |
469 if rset and not entity.eid in pendingeids and not entity.in_state: |
467 if not entity.eid in pendingeids and not entity.in_state: |
470 session.unsafe_execute('SET X in_state S WHERE X eid %(x)s, S eid %(s)s', |
468 rset = session.execute('Any S WHERE ET initial_state S, ET name %(name)s', |
471 {'x' : entity.eid, 's' : rset[0][0]}, 'x') |
469 {'name': entity.id}) |
|
470 if rset: |
|
471 session.add_relation(entity.eid, 'in_state', rset[0][0]) |
472 |
472 |
473 |
473 |
474 def set_initial_state_after_add(session, entity): |
474 def set_initial_state_after_add(session, entity): |
475 SetInitialStateOp(session, entity=entity) |
475 SetInitialStateOp(session, entity=entity) |
476 |
476 |