Ejemplo n.º 1
0
def create_workflow():
    """ Create a new workflow.

    Returns the newly created workflow as a JSON object.
    """
    if request.content_type == 'application/zip':
        zfile = zipfile.ZipFile(StringIO.StringIO(request.data))
        zfile.extractall(path=app.config['base_path'])
        wfname = os.path.dirname(zfile.filelist[0].filename)
        workflow = Workflow(path=os.path.join(app.config['base_path'], wfname))
        from spreads.workflow import on_created
        on_created.send(workflow, workflow=workflow)
    else:
        data = json.loads(request.data)

        if data.get('config'):
            config = app.config['default_config'].with_overlay(
                data.get('config'))
        else:
            config = app.config['default_config']

        metadata = data.get('metadata', {})

        try:
            workflow = Workflow.create(location=app.config['base_path'],
                                       config=config,
                                       metadata=metadata)
        except ValidationError as e:
            return make_response(json.dumps(dict(errors=e.errors)), 400,
                                 {'Content-Type': 'application/json'})
    return make_response(json.dumps(workflow),
                         200, {'Content-Type': 'application/json'})
Ejemplo n.º 2
0
def create_workflow():
    """ Create a new workflow.

    :reqheader Accept:      :mimetype:`application/json`
    :<json object config:   Configuration for new workflow
    :<json object metadata: Metadata for new workflow

    :resheader Content-Type:    :mimetype:`application/json`
    :status 200:                When everything was OK.
    :status 400:                When validation of configuration or metadata
                                failed.
    """
    data = json.loads(request.data)

    if data.get('config'):
        config = app.config['default_config'].with_overlay(
            data.get('config'))
    else:
        config = app.config['default_config']

    metadata = data.get('metadata', {})

    workflow = Workflow.create(location=app.config['base_path'],
                               config=config,
                               metadata=metadata)
    return make_response(json.dumps(workflow),
                         200, {'Content-Type': 'application/json'})
Ejemplo n.º 3
0
def create_workflow():
    """ Create a new workflow.

    Returns the newly created workflow as a JSON object.
    """
    data = json.loads(request.data)

    if data.get('config'):
        config = app.config['default_config'].with_overlay(
            data.get('config'))
    else:
        config = app.config['default_config']

    metadata = data.get('metadata', {})

    workflow = Workflow.create(location=app.config['base_path'],
                               config=config,
                               metadata=metadata)
    return make_response(json.dumps(workflow),
                         200, {'Content-Type': 'application/json'})
Ejemplo n.º 4
0
def create_workflow():
    """ Create a new workflow.

    Payload should be a JSON object. The only required attribute is 'name' for
    the desired workflow name. Optionally, 'config' can be set to a
    configuration object in the form "plugin_name: { setting: value, ...}".

    Returns the newly created workflow as a JSON object.
    """
    if request.content_type == 'application/zip':
        zfile = zipfile.ZipFile(StringIO.StringIO(request.data))
        zfile.extractall(path=app.config['base_path'])
        wfname = os.path.dirname(zfile.filelist[0].filename)
        workflow = Workflow(path=os.path.join(app.config['base_path'], wfname))
        from spreads.workflow import on_created
        on_created.send(workflow, workflow=workflow)
    else:
        data = json.loads(request.data)

        if data.get('config'):
            config = app.config['default_config'].with_overlay(
                data.get('config'))
        else:
            config = app.config['default_config']

        metadata = data.get('metadata', {})

        try:
            workflow = Workflow.create(location=app.config['base_path'],
                                       name=unicode(data['name']),
                                       config=config,
                                       metadata=metadata)
        except ValidationError as e:
            return make_response(json.dumps(dict(errors=e.errors)), 400,
                                 {'Content-Type': 'application/json'})
    return make_response(json.dumps(workflow),
                         200, {'Content-Type': 'application/json'})