def create(): form = WorkoutForm() if form.validate_on_submit(): flash('Your workout has been added.') # session['workout_content'] = [form.exercise1.data, form.num_sets1, form.num_reps1.data] if request.method == "POST": # save to mongodb database name = form.name.data num_rounds = form.num_rounds.data # workout_content = form.workout_content.data workout_content = { 'exercise': form.exercise1.data, 'num_sets': form.num_sets1.data, 'num_reps': form.num_reps1.data } scored = form.scored_checkbox.data formatted_date = datetime.datetime.today().strftime("%Y-%m-%d") # new_workout = Workout(name, num_rounds, workout_content, scored, formatted_date) Database.insert( 'workouts', { 'name': name, 'num_rounds': num_rounds, 'scored': scored, 'content': workout_content, 'date': formatted_date }) # placeholder - will eventually redirect somewhere else # that make sense return redirect(url_for('workouts.create')) return render_template('creation.html', form=form)
def add(): form = ExerciseForm() if form.validate_on_submit(): flash('Your workout has been added.') session['exercise_name'] = form.name.data session['exercise_description'] = form.description.data if request.method == "POST": # save to mongodb database name = form.name.data description = form.description.data # muscles = form.muscles.data video_link = form.video_link.data images = form.photo.data formatted_date = datetime.datetime.today().strftime("%Y-%m-%d") Database.insert( 'exercises', { 'name': name, 'description': description, # 'muscles': muscles, 'video_link': video_link, 'images': images, 'date': formatted_date }) return redirect(url_for('exercises.add')) return render_template('add.html', form=form)