def patch_despatch_fsmt(document_id): success = False inputs = FsmtJsonInputs(request) if not inputs.validate(): response = jsonify(success=False, errors=inputs.errors), 400 else: data = request.get_json() document = dao.Despatch(pool) if data['curr_fsmt'] == 'COMMITTED': success = document.commit(document_id) response = jsonify(success=success, message="document commited"), 200 elif data['curr_fsmt'] == 'DECOMMITTED': success = document.decommit(document_id) response = jsonify(success=success, message="document decommited"), 200 else: return jsonify(success=success, errors="incorrect fsmt"), 400 if not success: response = jsonify(success=False, errors=document.errors), 400 if not response: response = jsonify(success=success, message="unexpected error"), 400 return response
def patch_despatches_body(document_id): data = request.get_json() if data: d = dao.Despatch(pool) d.from_dict(data) d.reinit(document_id) return jsonify(str(document_id)) else: return '', 400
def del_despatch(document_id): document = dao.Despatch(pool) success = document.delete(document_id) if success: response = ('', 204) else: response = jsonify(success=False, errors=document.errors), 400 return response
def post_despatch(): success = False document_id = None inputs = OutboundDocumentJsonInputs(request) if not inputs.validate(): response = jsonify(success=success, errors=inputs.errors), 400 return response else: data = request.get_json() document = dao.Despatch(pool) document.from_dict(data) document_id = document.init() if document_id: success = True response = jsonify( success=success, message="document id=[{0}] created".format(document_id)), 200 else: response = jsonify(success=success, errors=document.errors), 400 return response
def get_despatch(document_id): document = dao.Despatch(pool, document_id) return jsonify(document.to_dict())