def edit(id):
	exercise = Exercise.query.get_or_404(id)
	bodyparts=[bodypart.id for bodypart in exercise.bodyparts]
	form = ExerciseForm(bodyparts=bodyparts)
	form.set_choices()
	form.description.data = exercise.description
	return render_template('exercises/edit.html', form=form, exercise=exercise)
def index():
	exercises = Exercise.query.order_by(Exercise.name).all()
	form = ExerciseForm(request.form)
	form.set_choices()
	if request.method == 'POST':
		if form.validate():
			new_exercise = Exercise(form.name.data, form.description.data)
			for bodypart in form.bodyparts.data:
				new_exercise.bodyparts.append(BodyPart.query.get_or_404(bodypart))
			db.session.add(new_exercise)
			db.session.commit()
			return redirect(url_for('exercises.index'))
		else:
			return render_template('exercises/new.html', form=form)
	return render_template('exercises/index.html', exercises=exercises)
Example #3
0
File: views.py Project: bigrobsf/hd
def index():
    if request.method == 'POST':
        form = ExerciseForm(request.form)
        if form.validate():
            exercise = Exercise(form.name.data)

            db.session.add(exercise)
            db.session.commit()
        else:
            return render_template('exercises/new.html', form=form)

    form = DeleteForm(request.form)
    return render_template('exercises/index.html',
                           form=form,
                           exercises=Exercise.query.order_by(
                               Exercise.id).all())
def show(id):
	exercise = Exercise.query.get_or_404(id)
	form = ExerciseForm(request.form)
	form.set_choices()
	if request.method == b"PATCH":
		if form.validate():
			exercise.name = form.name.data
			exercise.description = form.description.data
			exercise.bodyparts = []
			for bodypart in form.bodyparts.data:
				exercise.bodyparts.append(BodyPart.query.get_or_404(bodypart))
			db.session.add(exercise)
			db.session.commit()
			return redirect(url_for('exercises.index'))
		else:
			return render_template('exercises/edit.html', form=form, exercise=exercise)
	return render_template('exercises/show.html', exercise = exercise)
Example #5
0
File: views.py Project: bigrobsf/hd
def show(ex_id):
    found_exercise = Exercise.query.get_or_404(ex_id)
    if request.method == b'PATCH':
        form = ExerciseForm(request.form)
        if form.validate():
            found_exercise.name = form.name.data

            db.session.add(found_exercise)
            db.session.commit()
            return redirect(url_for('exercises.index'))
        else:
            return render_template(url_for('exercises/edit.html', form=form))

    if request.method == b'DELETE':
        form = DeleteForm(request.form)
        if form.validate():
            db.session.delete(found_exercise)
            db.session.commit()
            return redirect(url_for('exercises.index'))
        else:
            return render_template(url_for('exercises/edit.html', form=form))

    return render_template('exercises/show.html', exercise=found_exercise)
def new():
	form = ExerciseForm(request.form)
	form.set_choices()
	return render_template('exercises/new.html', form=form)
Example #7
0
File: views.py Project: bigrobsf/hd
def edit(ex_id):
    found_exercise = Exercise.query.get_or_404(ex_id)
    form = ExerciseForm(obj=found_exercise)
    return render_template('exercises/edit.html',
                           form=form,
                           exercise=found_exercise)