Skip to content

Commit

Permalink
allow TaskState to handle name/value conversion for any mask
Browse files Browse the repository at this point in the history
  • Loading branch information
essweine committed Dec 3, 2023
1 parent 80f85be commit c248f23
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions SpiffWorkflow/util/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA

from functools import reduce


class TaskState:
"""Int values corresponding to `Task` states.
Expand Down Expand Up @@ -96,7 +98,7 @@ def get_name(cls, state):
TaskState.NOT_FINISHED_MASK: 'NOT_FINISHED_MASK',
TaskState.ANY_MASK: 'ANY_MASK',
})
return names.get(state)
return names.get(state) or '|'.join([ names.get(v) for v in cls._values if v & state ])

@classmethod
def get_value(cls, name):
Expand All @@ -109,7 +111,18 @@ def get_value(cls, name):
int: the value of the state
"""
values = dict(zip(cls._names, cls._values))
return values.get(name.upper())
values.update({
'FINISHED_MASK': TaskState.FINISHED_MASK,
'DEFINITE_MASK': TaskState.DEFINITE_MASK,
'PREDICTED_MASK': TaskState.PREDICTED_MASK,
'NOT_FINISHED_MASK': TaskState.NOT_FINISHED_MASK,
'ANY_MASK': TaskState.ANY_MASK,
})
names = name.upper().split('|')
if len(names) == 1:
return values.get(name.upper(), 0)
else:
return reduce(lambda x, y: x | y, [TaskState.get_value(v) for v in name.upper().split('|')])


class TaskFilter:
Expand Down

0 comments on commit c248f23

Please sign in to comment.