def create_workout(): form = WorkoutForm() print(form.data) if form.validate_on_submit(): workout = Workout( user_id=form.data['user_id'], title=form.data['title'], subtitle=form.data['subtitle'], description=form.data['description'] ) db.session.add(workout) db.session.commit() return workout.to_dict()
def create_workout(): fields = json.loads(request.form['exercises']) form = WorkoutForm() form['csrf_token'].data = request.cookies['csrf_token'] while len(form.exercises) > 0: form.exercises.pop_entry() for field in fields: w_e_form = WorkoutsExercisesForm() w_e_form.exercise_id = field['exercise_id'] w_e_form.sets = field['sets'] w_e_form.repetitions = field['repetitions'] form.exercises.append_entry(w_e_form) if form.validate_on_submit(): exercises = [] workout = Workout( workout_name=form.data['workout_name'], created_by=current_user.id ) db.session.add(workout) db.session.flush() obj = workout.to_dict() obj['exercises'] = exercises for idx, field in enumerate(form.exercises): workout_exercise = Workouts_Exercises( workout_id=workout.id, exercise_id=field.exercise_id.data, sets=field.sets.data, repetitions=field.repetitions.data, created_at=datetime.date.today(), updated_at=datetime.date.today(), ) db.session.add(workout_exercise) db.session.flush() exercise = workout_exercise.exercise exercise_dict = exercise.to_dict() workout_exercise_dict = workout_exercise.to_dict() exercise_dict['sets'] = workout_exercise_dict['sets'] exercise_dict['repetitions'] = workout_exercise_dict['repetitions'] exercises.append(exercise_dict) db.session.commit() return jsonify(obj) return {'errors': validation_errors_to_error_messages(form.errors)}
def second(exercise_name, athlete_id): if (exercise_name == "BenchPress01" or exercise_name == "DeadLift01"): form = RepsWeightForm() page = 'repsweight.html' elif (exercise_name == "Burpies01"): form = RepsForm() page = 'reps.html' elif (exercise_name == "LatPullDown01"): form = RepsAccelForm() page = 'repsaccel.html' dateString = datetime.now().strftime("%d-%b-%Y") if form.validate_on_submit(): print(f"Pain area data is [{form.pain_area.data}]") if (exercise_name == "BenchPress01" or exercise_name == "DeadLift01"): prm_string = f'[{form.reps.name},{form.weight.name},{form.rpe.name},{form.pain_area.name}]' entry_string = f'[{form.reps.data},{form.weight.data},{form.rpe.data},{form.pain_area.data}]' elif (exercise_name == "Burpies01"): prm_string = f'[{form.reps.name},{form.rpe.name},{form.pain_area.name}]' entry_string = f'[{form.reps.data},{form.rpe.data},{form.pain_area.data}]' elif (exercise_name == "LatPullDown01"): prm_string = f'[{form.reps.name},{form.acceleration.data},{form.rpe.name},{form.pain_area.name}]' entry_string = f'[{form.reps.data},{form.acceleration.data},{form.rpe.data},{form.pain_area.data}]' new_entry = Workout(athlete_id=athlete_id, exercise_name=exercise_name, parameters=prm_string, entries=entry_string, timestamp=datetime.utcnow(), team_id=current_user.id) db.session.add(new_entry) db.session.commit() return redirect(url_for('workout')) return render_template(page, title="Exercise Entry Form", date=dateString, form=form)
def post(self): """API endpoint for creating a workout :return: status code 405 - invalid JSON or invalid request type :return: status code 400 - unsupported Content-Type :return: status code 201 - successful submission """ # Ensure post's Content-Type is supported if request.is_json: # Ensure data is a valid JSON json_request = request.get_json(silent=True) if json_request: workout, errors = Workout.load(json_request) if errors: current_app.logger.info( 'Error deserializing json to Workout [{}]'.format( json_request)) return make_response(jsonify(errors), 405) workout.user_id = g.current_user.id workout.save() current_app.logger.info('Created new workout [{}]'.format( workout.id)) return workout.dump().data, 201 current_app.logger.info('Invalid JSON') return make_response(jsonify(error="Invalid Json!"), 405) current_app.logger.info('Unsupported Content-Type') return make_response(jsonify(error="Unsupported Content-Type!"), 400)
def create_workout(current_user): # if not current_user.admin: # return 'User not allowed to create workout.', 403 post_data = request.form title = post_data.get('title') location = post_data.get('location') best_times = post_data.get('best_times') duration = post_data.get('duration') materials = post_data.get('materials') difficulty = post_data.get('difficulty') people_count = post_data.get('people_count') instructions = post_data.get('instructions') status = post_data.get('status') file = request.files['file'] filename = secure_filename(file.filename) # Gen GUUID File Name fileExt = filename.split('.')[-1] autoGenFileName = uuid.uuid4() newFileName = str(autoGenFileName) + '.' + fileExt try: os.environ["POSTGRES_URL"] file.save(os.path.join(app.config['UPLOAD_FOLDER'], newFileName)) except: # S3 Bucket s3 = boto3.client("s3", aws_access_key_id=os.environ["AWS_ACCESS_KEY"], aws_secret_access_key=os.environ["AWS_SECRET_KEY"]) bucket_resource = s3 file.save(newFileName) bucket_resource.upload_file(Bucket="getup-192", Filename=newFileName, Key=newFileName) workout = Workout(title=title, location=location, best_times=best_times, duration=duration, materials=materials, difficulty=difficulty, people_count=people_count, instructions=instructions, status=status, image=newFileName) db.session.add(workout) current_user.workouts.append(workout) db.session.commit() return jsonify({'message': "New workout created."})
def seed_workouts(): dayOff = Workout( user_id=1, title="Day Off", subtitle="Take the day off. You deserve it!", description= "Sit on the couch. Eat potato chips. Question your life choices!", likes=2000) db.session.add(dayOff) db.session.commit()
def seed_workouts(): beach_workout = Workout(name='teahupoo', description='sample description for workout', workout_photos='https://stabmag.com/', time=10001, workout_date=db.func.now(), user_id=1, route_id=1) peak_workout = Workout(name='twin peaks', description='sample description for workout', workout_photos='https://cdn-assets.alltrails.com' + '/static-map/production/at-map/18276524/' + 'trail-us-utah-broads-fork-twin-' + 'peaks-at-map-18276524-1537887906' + '-1200x630-3-6.jpg', time=20002, workout_date=db.func.now(), user_id=1, route_id=2) db.session.add(beach_workout) db.session.add(peak_workout) db.session.commit()
def seed_users_workouts(n): for i in range(n): user = User( username=fake.user_name(), email=fake.ascii_email(), password=f'password{i+1}', ) workout = Workout(workout_name=fake.word(), created_by=random.randint(1, n)) db.session.add(user) db.session.add(workout) workout.users.append(user) demo = User(username='******', email='*****@*****.**', password='******') db.session.add(demo) db.session.commit()
def get(self, limit, offset): """API endpoint for getting a list of workouts :param limit: limit number of workouts to retrieve :param offset: offset query from the top :return: status code 200 - sucessful retrieval """ workout_list = (Workout.query.all()) workouts, errors = Workout.dump_list(workout_list) if errors: # This should never happen... # TODO sort out internal errrs... send to sentry + log info. return make_response(jsonify(error='Internal Server Error'), 500) return workouts, 200
def create_workout(current_user): if not current_user.admin: abort(403, 'User not allowed to create workout.') post_data = request.form title = post_data.get('title') location = post_data.get('location') best_times = post_data.get('best_times') duration = post_data.get('duration') materials = post_data.get('materials') difficulty = post_data.get('difficulty') people_count = post_data.get('people_count') instructions = post_data.get('instructions') status = post_data.get('status') file = request.files['file'] filename = secure_filename(file.filename) # Gen GUUID File Name fileExt = filename.split('.')[-1] autoGenFileName = uuid.uuid4() newFileName = str(autoGenFileName) + '.' + fileExt file.save(os.path.join(app.config['UPLOAD_FOLDER'], newFileName)) workout = Workout(title=title, location=location, best_times=best_times, duration=duration, materials=materials, difficulty=difficulty, people_count=people_count, instructions=instructions, status=status, image=newFileName) db.session.add(workout) current_user.workouts.append(workout) db.session.commit() return jsonify({'message': "New workout created."})
def add_workout(self, json_dict): workout = Workout(owner=json_dict['owner'], name=json_dict['name']) db.session.add(workout) exercises = json_dict["exercises"] for element in exercises: exercise = Exercise(description = element["description"], workouts = workout) db.session.add(exercise) db.session.commit() print(workout.exercises.all()) json = { 'id': workout.id, 'owner': workout.owner, 'name': workout.name } return json
def seed_workouts(): base_dir = os.path.dirname(__file__) # Read GPX files from the 'gpx_files' directory run_1: TextIO = open(os.path.join(base_dir, 'gpx_files', 'run_1.gpx')) run_2: TextIO = open(os.path.join(base_dir, 'gpx_files', 'boulder.gpx')) # Find a user demo_user = User.query.filter_by(username='******').first() # Create workout objects workout_1 = Workout.create_workout_from_gpx( run_1, "First Run", demo_user.id) track_1 = Track.create_track_from_gpx_track( run_2, "Boulder Skyline", demo_user.id) # Commit the session db.session.add(workout_1) db.session.add(track_1) db.session.commit()
def get_workout_from_dom(dom: str) -> WorkoutSchema: soup = BeautifulSoup(dom, 'html.parser') all_dom_rounds = soup.select('.card') rounds = [] for dom_round in all_dom_rounds: dom_exercises = dom_round.find_all('a') exercises = [] for dom_exercise in dom_exercises: exercises.append( Exercise(title=dom_exercise.find('h6').string, quantity=dom_exercise.find('p').string)) rounds.append( Round( title=dom_round.find('h5').string, exercises=exercises, )) return Workout( title=soup.find('h3').string, rounds=rounds, )
def add_custom_workout(): data = request.json print(data) errors = [] workout_photos = data['workout_photos'] time = data['time'] custom_workout = Workout( name=data['name'], description=data['description'], workout_photos=f'{workout_photos}', time=f'{time}', # workout_date=data['workout_date'], user_id=data['user_id'], route_id=data['route_id'], ) if errors: return jsonify(errors) db.session.add(custom_workout) db.session.commit() return jsonify(data)
def form_save(): if request.method == 'GET': return redirect(url_for('index')) week = request.form.get('week') training_type = request.form.get('training_type') main_move = request.form.get('mm') main_move_reps = request.form.get('mm_reps') main_move_sets = request.form.get('mm_sets') main_move_rpe = request.form.get('mm_rpee') main_move_weight = request.form.get('mm_weig') assa_move = request.form.get('ae_a') assa_move_reps = request.form.get('ae_a_reps') assa_move_sets = request.form.get('ae_a_sets') assa_move_rpe = request.form.get('ae_a_rpee') assa_move_weight = request.form.get('ae_a_weig') assb1_move = request.form.get('ae_b1') assb1_move_reps = request.form.get('ae_b1_reps') assb1_move_sets = request.form.get('ae_b1_sets') assb1_move_rpe = request.form.get('ae_b1_rpee') assb1_move_weight = request.form.get('ae_b1_weig') assb2_move = request.form.get('ae_b2') assb2_move_reps = request.form.get('ae_b2_reps') assb2_move_sets = request.form.get('ae_b2_sets') assb2_move_rpe = request.form.get('ae_b2_rpee') assb2_move_weight = request.form.get('ae_b2_weig') assc1_move = request.form.get('ae_c1') assc1_move_reps = request.form.get('ae_c1_reps') assc1_move_sets = request.form.get('ae_c1_sets') assc1_move_rpe = request.form.get('ae_c1_rpee') assc1_move_weight = request.form.get('ae_c1_weig') assc2_move = request.form.get('ae_c2') assc2_move_reps = request.form.get('ae_c2_reps') assc2_move_sets = request.form.get('ae_c2_sets') assc2_move_rpe = request.form.get('ae_c2_rpee') assc2_move_weight = request.form.get('ae_c2_weig') note = request.form.get('daynotes') user_id = current_user.id w = Workout(main_move=main_move, main_move_reps=main_move_reps, main_move_sets=main_move_sets, main_move_rpe=main_move_rpe, main_move_weight=main_move_weight, assa_move=assa_move, assa_move_reps=assa_move_reps, assa_move_sets=assa_move_sets, assa_move_rpe=assa_move_rpe, assa_move_weight=assa_move_weight, assb1_move=assb1_move, assb1_move_sets=assb1_move_sets, assb1_move_reps=assb1_move_reps, assb1_move_rpe=assb1_move_rpe, assb1_move_weight=assb1_move_weight, assb2_move=assb2_move, assb2_move_sets=assb2_move_sets, assb2_move_reps=assb2_move_reps, assb2_move_rpe=assb2_move_rpe, assb2_move_weight=assb2_move_weight, assc1_move=assc1_move, assc1_move_sets=assc1_move_sets, assc1_move_reps=assc1_move_reps, assc1_move_rpe=assc1_move_rpe, assc1_move_weight=assc1_move_weight, assc2_move=assc2_move, assc2_move_sets=assc2_move_sets, assc2_move_reps=assc2_move_reps, assc2_move_rpe=assc2_move_rpe, assc2_move_weight=assc2_move_weight, note=note, user_id=user_id, week=week, training_type=training_type) db.session.add(w) db.session.commit() flash('Workout has been saved') return render_template('index.html')