Esempio n. 1
0
 def get_next(cls, role, action, order_c_state, c_state):
     try:
         order_state_to_match = state_machine_match_regex(order_c_state)
         osm = cls.objects.get(
             operator_role=role,
             action=action,
             order_current_state__regex=order_state_to_match,
             current_state=c_state,
         )
         return osm.next_state, osm.post_action
     except MultipleObjectsReturned, mor:
         # TODO:make a custom exception
         raise Exception("Multiple states returned!")
Esempio n. 2
0
 def get_role_actions(cls, order_c_state, c_state):
     """Get which roles can do what actions when the order and item are in certain states
     """
     order_state_to_match = state_machine_match_regex(order_c_state)
     osms = cls.objects.filter(order_current_state__regex=order_state_to_match, current_state=c_state).values_list(
         "operator_role", "action"
     )
     roles = list(set([osm[0] for osm in osms]))
     role_actions = {}
     for r in roles:
         role_actions[r] = []
         for s in osms:
             if s[0] == r:
                 if s[1] not in role_actions[r]:
                     role_actions[r].append(s[1])
     return role_actions