def add_coach(): # Add new coach body = request.get_json() name = body.get('name', None) specialty = body.get('specialty', None) try: new_coach = Coach(name=name, specialty=specialty) new_coach.insert() return jsonify({'success': True, 'coach': new_coach.format()}) except: abort(422)
def add_coachs(current_user): coach_new = Coach( nombre_equipo = request.get_json()['nombreEquipo'], nombre = request.get_json()['nombre'], apellido = request.get_json()['apellido'], fecha_nacimiento = request.get_json()['nacimiento'], rol = request.get_json()['rol'], nacionalidad = request.get_json()['nacionalidad']) try: coach_new.save() return jsonify({'result': 'OK'}) except(ValueError, KeyError, TypeError): return jsonify({'result': 'error'})
def post(self): args = coach_parser.parse_args() if 'id' not in args: highest = Coach.query.order_by(Coach.id).last() coach_id = highest + 1 else: coach_id = args['id'] coach = Coach(id=coach_id, email=args['email'], password=args['password'], first_name=args['first_name'], last_name=args['last_name']) db.session.add(coach) db.session.commit() return coach, 201
teamsite_objects[school] = TeamSite(school, year1, year2) return teamsite_objects, coachsite_objects everything = (Instantiate(2011, 2018)) teamsite = everything[ 0] # gives you a dictionary with keys = school name and values\n", # are TeamSite instances\n", keys = list((teamsite).keys()) coachsite = everything[1] #gives you object instance\n", #######Instansiate coach model########## coach_instances = [] for tup in coachsite.salaries[0]: tup2 = int(tup[2].replace('$', '').replace(',', '')) c_instance = Coach(name = tup[0] , years = tup[1] , salary = tup2,\ sal_school = tup[3]) coach_instances.append(c_instance) session.add(c_instance) #######Instansiate school model########## team_instances = [] for school_name in keys: years_ = teamsite[school_name].years winloss_ = teamsite[school_name].winloss team_points_ = teamsite[school_name].team_points opp_points_ = teamsite[school_name].opp_points for i in range(0, len(years_)): if years_[i] != '' and winloss_[i] != '' and team_points_[ i] != '' and opp_points_[i] != '': team_instance = School(name = school_name, years = years_[i], winloss = winloss_[i],\