Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions transitions/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,11 @@ def add_callback(self, trigger, func):

class NonTransition(Transition):

def __init__(self, conditions=None, unless=None, before=None, after=None):
def __init__(self, states=None, conditions=None, unless=None, before=None, after=None):
"""
Args:
states (string, list): State(s) in which NonTransition is can
happen
conditions (string, list): Condition(s) that must pass in order for
the transition to take place. Either a string providing the
name of a callable, or a list of callables. For the transition
Expand All @@ -186,6 +188,7 @@ def __init__(self, conditions=None, unless=None, before=None, after=None):
transition.
after (string or list): callbacks to trigger after the transition.
"""
self.states = [] if states is None else listify(states)
self.before = [] if before is None else listify(before)
self.after = [] if after is None else listify(after)

Expand All @@ -198,17 +201,17 @@ def __init__(self, conditions=None, unless=None, before=None, after=None):
self.conditions.append(Condition(u, target=False))

def execute(self, event_data):
""" Execute the transition.
""" Execute the Non Transition.
Args:
event: An instance of class EventData.
Returns: boolean indicating whether or not the transition was
Returns: boolean indicating whether or not the nontransition was
successfully executed (True if successful, False if not).
"""
machine = event_data.machine
for c in self.conditions:
if not c.check(event_data):
logger.info("Transition condition failed: %s() does not " +
"return %s. Transition halted.", c.func, c.target)
logger.info("NonTransition condition failed: %s() does not " +
"return %s. NonTransition halted.", c.func, c.target)
return False
for func in self.before:
machine.callback(getattr(event_data.model, func), event_data)
Expand Down Expand Up @@ -274,7 +277,8 @@ def add_non_transition(self, non_transition):
non_transition (NonTransition): The NonTransition instance to add to the
list.
"""
self.non_transitions.append(non_transition)
if self.machine.current_state in non_transition.states:
self.non_transitions.append(non_transition)

def trigger(self, *args, **kwargs):
""" Serially execute all transitions that match the current state,
Expand Down