'Get a StoredWorkflow from the database by id, verifying ownership.'

def get_stored_workflow(self, trans, id, check_ownership=True, check_accessible=False):

    try:
        workflow = trans.sa_session.query(trans.model.StoredWorkflow).get(trans.security.decode_id(id))
    except TypeError:
        workflow = None
    if (not workflow):
        error('Workflow    not    found')
    else:
        self.security_check(trans, workflow, check_ownership, check_accessible)
        if (not workflow.slug):
            self.create_item_slug(trans.sa_session, workflow)
            trans.sa_session.flush()
    return workflow
