Move recovery functionality for getting perticular workflow versions into StoredWorkflow

This commit is contained in:
mvdbeek
2018-09-09 19:24:53 +02:00
parent 9d5146017c
commit f49da14e45
2 changed files with 13 additions and 11 deletions
+6 -11
View File
@@ -377,6 +377,8 @@ class WorkflowContentsManager(UsesAnnotations):
option describes the workflow in a context more tied to the current Galaxy instance and includes
fields like 'url' and 'url' and actual unencoded step ids instead of 'order_index'.
"""
if version == '':
version = None
if version is not None:
version = int(version)
if style == "editor":
@@ -394,7 +396,7 @@ class WorkflowContentsManager(UsesAnnotations):
"""
Builds workflow dictionary used by run workflow form
"""
workflow = stored.latest_workflow if version is None else stored.workflows[version]
workflow = stored.get_internal_version(version)
if len(workflow.steps) == 0:
raise exceptions.MessageException('Workflow cannot be run because it does not have any steps.')
if attach_ordered_steps(workflow, workflow.steps):
@@ -478,11 +480,7 @@ class WorkflowContentsManager(UsesAnnotations):
return self._resource_mapper_function(trans=trans, stored_workflow=stored, workflow=workflow)
def _workflow_to_dict_editor(self, trans, stored, version=None):
if version is None:
workflow = stored.latest_workflow
else:
version = int(version)
workflow = stored.workflows[version]
workflow = stored.get_internal_version(version)
# Pack workflow data into a dictionary and return
data = {}
data['name'] = workflow.name
@@ -594,10 +592,7 @@ class WorkflowContentsManager(UsesAnnotations):
"""
if workflow is None:
assert stored is not None
if version is None:
workflow = stored.latest_workflow
else:
workflow = stored.workflows[version]
workflow = stored.get_internal_version(version)
annotation_str = ""
tag_str = ""
@@ -767,7 +762,7 @@ class WorkflowContentsManager(UsesAnnotations):
encode = self.app.security.encode_id
sa_session = self.app.model.context
item = stored.to_dict(view='element', value_mapper={'id': encode})
workflow = stored.latest_workflow if version == None else stored.workflows[version]
workflow = stored.get_internal_version(version)
item['url'] = url_for('workflow', id=item['id'])
item['owner'] = stored.user.username
inputs = {}
+7
View File
@@ -3906,6 +3906,13 @@ class StoredWorkflow(HasTags, Dictifiable):
self.latest_workflow_id = None
self.workflows = []
def get_internal_version(self, version):
if version is None:
return self.latest_workflow
if len(self.workflows) <= version:
raise Exception("Version does not exist")
return list(reversed(self.workflows))[version]
def copy_tags_from(self, target_user, source_workflow):
# Override to only copy owner tags.
for src_swta in source_workflow.owner_tags: