'Import a workflow contained in an installed tool shed repository into Galaxy.'

@web.expose
@web.require_admin
def import_workflow(self, trans, workflow_name, repository_id, **kwd):

    message = str(escape(kwd.get('message', '')))
    status = kwd.get('status', 'done')
    if workflow_name:
        workflow_name = encoding_util.tool_shed_decode(workflow_name)
        repository = repository_util.get_tool_shed_repository_by_id(trans.app, repository_id)
        if repository:
            (workflow, status, message) = workflow_util.import_workflow(trans, repository, workflow_name)
            if workflow:
                workflow_name = encoding_util.tool_shed_encode(str(workflow.name))
            else:
                message += ('Unable    to    locate    a    workflow    named    <b>%s</b>    within    the    installed    tool    shed    repository    named    <b>%s</b>' % (escape(str(workflow_name)), escape(str(repository.name))))
                status = 'error'
        else:
            message = ('Invalid    repository    id    <b>%s</b>    received.' % str(repository_id))
            status = 'error'
    else:
        message = 'The    value    of    workflow_name    is    required,    but    was    not    received.'
        status = 'error'
    return trans.response.send_redirect(web.url_for(controller='admin_toolshed', action='view_workflow', workflow_name=workflow_name, repository_id=repository_id, message=message, status=status))
