This module contains a class that can be used to simplify the usage of Lifecycle and LifecycleStates.
See also
Example:
_lifecycles_list = [
("draft", "official", "deprecated"),
("draft", "official"),
]
lifecycles = dict()
for cycles in _lifecycles_list:
name = "->".join(cycles)
lifecycles[name] = LifecycleList(name, "official", *cycles)
Bases: list
Object which represents a lifecycle as a list of string.
This class inherits from list, so you can use all list methods.
For example:
>>> cycle = LifecycleList("MyCycle", "b")
>>> cycle.extend(["a", "b", "c"])
>>> cycle[0]
'a'
name of the lifecycle
name of the official state (must be in the list of states)
Returns the next state of state
Raises ValueError if state is not in the list and IndexError if state is the last state.
Example:
>>> cycle = LifecycleList("MyCycle", "b", "a", "b", "c", "d")
>>> cycle.next_state("b")
'c'
>>> cycle.next_state("d")
Traceback (most recent call last):
...
IndexError: list index out of range
>>> cycle.next_state("z")
Traceback (most recent call last):
...
ValueError: list.index(x): x not in list
Returns the previous state of state
Raises ValueError if state is not in the list and IndexError if state is the first state.
Example:
>>> cycle = LifecycleList("MyCycle", "b", "a", "b", "c", "d")
>>> cycle.previous_state("b")
'a'
>>> cycle.previous_state("a")
Traceback (most recent call last):
...
IndexError
>>> cycle.previous_state("z")
Traceback (most recent call last):
...
ValueError: list.index(x): x not in list