diff --git a/SpiffWorkflow/workflow.py b/SpiffWorkflow/workflow.py index 8a8dd7f76..cac799192 100644 --- a/SpiffWorkflow/workflow.py +++ b/SpiffWorkflow/workflow.py @@ -167,8 +167,10 @@ def get_task(self, id): :rtype: Task :returns: The task with the given id. """ - tasks = [task for task in self.get_tasks() if task.id == id] - return tasks[0] if len(tasks) == 1 else None + for task in self.get_tasks_iterator(): + if task.id == id: + return task + return None def get_tasks_from_spec_name(self, name): """ @@ -179,7 +181,7 @@ def get_tasks_from_spec_name(self, name): :rtype: Task :return: The task that relates to the spec with the given name. """ - return [task for task in self.get_tasks() + return [task for task in self.get_tasks_iterator() if task.task_spec.name == name] def get_tasks(self, state=Task.ANY_MASK): @@ -193,6 +195,17 @@ def get_tasks(self, state=Task.ANY_MASK): """ return [t for t in Task.Iterator(self.task_tree, state)] + def get_tasks_iterator(self, state=Task.ANY_MASK): + """ + Returns a iterator of Task objects with the given state. + + :type state: integer + :param state: A bitmask of states. + :rtype: Task.Iterator + :returns: A list of tasks. + """ + return Task.Iterator(self.task_tree, state) + def complete_task_from_id(self, task_id): """ Runs the task with the given id.