def client_put(): """Creates a new client""" current_user = get_current_user() data = request.get_json() if "name" not in data.keys() or "description" not in data.keys(): return jsonify({ "status": "error", "detail": "Missing name or description" }), 400 if Client.query.filter_by(name=data["name"]).first() != None: return jsonify({ "status": "error", "detail": "Client already exists" }), 400 if not_empty(data["name"]) and check_length( data["name"], 32) and check_length(data["description"], 128): new_client = Client(name=data["name"], description=data["description"], owner_id=current_user.id) new_client.gen_uid() db.session.add(new_client) db.session.commit() return jsonify({ "status": "OK", "detail": "New client {} created successfuly".format(new_client.name) }), 201 else: return jsonify({ "status": "error", "detail": "Invalid data (name empty or too long or description too long)" }), 400
def client_put(): """Creates a new client""" data = request.form if 'name' not in data.keys() or\ 'description' not in data.keys(): return jsonify({ 'status': 'error', 'detail': 'Missing name or description' }), 400 if Client.query.filter_by(name=data['name']).first() != None: return jsonify({ 'status': 'error', 'detail': 'Client already exists' }), 400 if not_empty(data['name']) and check_length( data['name'], 32) and check_length(data['description'], 128): new_client = Client(name=data['name'], description=data['description'], owner_id=current_user.id) new_client.gen_uid() db.session.add(new_client) db.session.commit() return jsonify({ 'status': 'OK', 'detail': 'New client {} created successfuly'.format(new_client.name) }), 201 else: return jsonify({ 'status': 'error', 'detail': 'Invalid data (name empty or too long or description too long)' }), 400