コード例 #1
0
ファイル: web.py プロジェクト: 5up3rD4n1/spreads
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'})
コード例 #2
0
    def post(self):
        self.fp.close()
        with zipfile.ZipFile(self.fname) as zf:
            wfname = os.path.dirname(zf.namelist()[0])
            zf.extractall(path=self.base_path)
        os.unlink(self.fname)

        workflow = Workflow(path=os.path.join(self.base_path, wfname))
        from spreads.workflow import on_created
        on_created.send(workflow, workflow=workflow)

        self.set_header('Content-Type', 'application/json')
        self.write(json.dumps(workflow, cls=util.CustomJSONEncoder))
コード例 #3
0
    def post(self):
        self.fp.close()
        with zipfile.ZipFile(self.fname) as zf:
            wfname = os.path.dirname(zf.namelist()[0])
            zf.extractall(path=self.base_path)
        os.unlink(self.fname)

        workflow = Workflow(path=os.path.join(self.base_path, wfname))
        from spreads.workflow import on_created
        on_created.send(workflow, workflow=workflow)

        self.set_header('Content-Type', 'application/json')
        self.write(json.dumps(workflow, cls=util.CustomJSONEncoder))
コード例 #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'})