def add_exercise(id): if 'user_id' not in session: return redirect('/') day = WorkoutDay.get(id) if session.get('user_id') != day.workout.user_id: return redirect('/') prior_data = None if request.method == 'POST': exercise = request.form.get('exercise') sets = request.form.get('sets') reps = request.form.get('reps') exerciseName = request.form.get('exerciseName') results = Exercise.add(day.id, exercise, reps, sets, exerciseName) if results is not None: return redirect(f'/workouts/{day.workout_id}/days/{day.id}') prior_data = { 'exercise': { 'value': exercise, 'error': None }, 'sets': { 'value': sets, 'error': None }, 'reps': { 'value': reps, 'error': None }, 'exerciseName': { 'value': exerciseName, 'error': None } } exercises = Exercise.all_for(id) return render_template('add_exercise.html', workout_id=day.workout_id, id=day.id, prior_data=prior_data, exercises=exercises)
def post_exercise(day_id): if request.method == 'OPTIONS': return Response() user_id = session.get('user_id', None) if user_id is None: return jsonify({'success': False}), 403 day = WorkoutDay.get(day_id) if user_id != day.workout.user.id: return jsonify({'success': False}), 403 data = request.get_json() exer_id = data.get('exercise') name = data.get('name') reps = data.get('reps') sets = data.get('sets') ex = Exercise.add(day.id, exer_id, sets, reps, name) if ex is None: return jsonify({'success': False}), 403 return jsonify({'success': True})