def create_actor(jwt): body = request.json name = body.get('name', None) age = body.get('age', None) gender = body.get('gender', None) # Abort 400 if the name in the request matches any of the saved actor names if name in list(map(Actors.get_name, Actors.query.all())): abort( 400, 'This name is already taken. Please provide a new name and try again.' ) # Abort 400 if any fields are missing if any(arg is None for arg in [name, age, gender]) or '' in [name, age, gender]: abort(400, 'name, age and gender are required fields.') # Create and insert a new actor new_actor = Actors(name=name, age=age, gender=gender) new_actor.insert() # Return the newly created actor return jsonify({ 'success': True, 'actors': [Actors.query.get(new_actor.id).format()] })
def create_actors(jwt): name = request.get_json()['name'] age = request.get_json()['age'] gender = request.get_json()['gender'] actor = Actors(name=name, age=age, gender=gender) if actor: actor.insert() result = {"success": "True", "actors": actor.format()} return jsonify(result) else: abort(404)
def actor_delete(payload, actor_id): error = False try: get_actor = Actors.query.filter_by(id=actor_id).first() Actors.delete(get_actor) except: error = True print(sys.exc_info()) finally: if error: abort(404) else: return jsonify({'success': True, "id": get_actor.id})
def create_actor(payload): error = False name = request.get_json()['name'] age = request.get_json()['age'] try: added_actor = Actors(name=name, age=age) Actors.insert(added_actor) except (TypeError, ValueError, KeyError): error = True print(sys.exc_info()) finally: if error: abort(422) else: return jsonify({'success': True})
def create_actors(*args, **kwargs): try: body = request.get_json() new_name = body.get('name') new_age = body.get('age') new_gender = body.get('gender') actors = Actors(name=new_name, age=new_age, gender=new_gender) actors.insert() return jsonify({ "success": True, "message": "Actor Successfully Added!", "actors": actors.format() }) except AttributeError: abort(422)