Sujet précédent

5.9. forms — Forms used by openPLM

Sujet suivant

5.11. mail — Tools to send mails

Cette page

Autres langues

5.10. lifecycle — Utilities to manipulate lifecycle

This module contains a class that can be used to simplify the usage of Lifecycle and LifecycleStates.

Voir aussi

Lifecycle.to_states_list()
Method to convert a Lifecycle into a LifecycleList
Lifecycle.from_lifecyclelist().
Method to convert a LifecycleList into a Lifecycle

Example:

_lifecycles_list = [
    ("draft", "official", "deprecated"),
    ("draft", "official"),
]

lifecycles = dict()
for cycles in _lifecycles_list:
    name = "->".join(cycles) 
    lifecycles[name] = LifecycleList(name, "official", *cycles)
class plmapp.lifecycle.LifecycleList(name, official_state, *args)[source]

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

name of the lifecycle

official_state

name of the official state (must be in the list of states)

next_state(state)[source]

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
previous_state(state)[source]

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