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. """ data = json.loads(request.data) path = Path(app.config['base_path'])/unicode(data['name']) # Setup default configuration config = app.config['default_config'] # Overlay user-supplied values, if existant user_config = data.get('config', None) if user_config is not None: config = config.with_overlay(user_config) workflow = Workflow(config=config, path=path, step=data.get('step', None), step_done=data.get('step_done', None)) try: workflow.id = persistence.save_workflow(workflow) except persistence.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'})
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. """ data = json.loads(request.data) path = Path(app.config['base_path']) / unicode(data['name']) # Setup default configuration config = app.config['default_config'] # Overlay user-supplied values, if existant user_config = data.get('config', None) if user_config is not None: config = config.with_overlay(user_config) workflow = Workflow(config=config, path=path, step=data.get('step', None), step_done=data.get('step_done', None)) try: workflow.id = persistence.save_workflow(workflow) except persistence.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'})