Source code for panoptes_client.workflow
from __future__ import absolute_import, division, print_function
from builtins import str
from panoptes_client.exportable import Exportable
from panoptes_client.panoptes import PanoptesObject, LinkResolver
from panoptes_client.subject import Subject
from panoptes_client.subject_set import SubjectSet
from panoptes_client.utils import batchable
[docs]class Workflow(PanoptesObject, Exportable):
_api_slug = 'workflows'
_link_slug = 'workflows'
_edit_attributes = (
'active',
'configuration',
'display_name',
'first_task',
'mobile_friendly',
'primary_language',
'retirement',
'tasks',
{
'links': (
'project',
),
}
)
[docs] @batchable
def retire_subjects(self, subjects, reason='other'):
"""
Retires subjects in this workflow.
- **subjects** can be a list of :py:class:`Subject` instances, a list
of subject IDs, a single :py:class:`Subject` instance, or a single
subject ID.
- **reason** gives the reason the :py:class:`Subject` has been retired.
Defaults to **other**.
Examples::
workflow.retire_subjects(1234)
workflow.retire_subjects([1,2,3,4])
workflow.retire_subjects(Subject(1234))
workflow.retire_subjects([Subject(12), Subject(34)])
"""
subjects = [ s.id if isinstance(s, Subject) else s for s in subjects ]
return Workflow.http_post(
'{}/retired_subjects'.format(self.id),
json={
'subject_ids': subjects,
'retirement_reason': reason
}
)
[docs] def add_subject_sets(self, subject_sets):
"""
A wrapper around :py:meth:`.LinkCollection.add`. Equivalent to::
workflow.links.subject_sets.add(subject_sets)
"""
return self.links.subject_sets.add(subject_sets)
[docs] def remove_subject_sets(self, subject_sets):
"""
A wrapper around :py:meth:`.LinkCollection.remove`. Equivalent to::
workflow.links.subject_sets.remove(subject_sets)
"""
return self.links.subject_sets.remove(subject_sets)
@property
def versions(self):
"""
A generator which yields all :py:class:`.WorkflowVersion` instances for
this workflow.
"""
return WorkflowVersion.where(workflow=self)
LinkResolver.register(Workflow)
LinkResolver.register(Workflow, 'active_workflows', readonly=True)
from panoptes_client.workflow_version import WorkflowVersion