def appointment_create(): """Provide HTML form to create a new appointment record.""" form = AppointmentForm(request.form) if request.method == 'POST' and form.validate(): appt = Appointment(user_id=current_user.id) form.populate_obj(appt) db.session.add(appt) db.session.commit() return redirect(url_for('appointment_list')) return render_template('appointment/edit.html', form=form)
def appointment_edit(appointment_id): """Provide HTML form to edit a given appointment.""" appt = db.session.query(Appointment).get(appointment_id) manage_errors(appt) form = AppointmentForm(request.form, appt) if request.method == 'POST' and form.validate(): form.populate_obj(appt) db.session.commit() return redirect(url_for('appointment_detail', appointment_id=appt.id)) return render_template('appointment/edit.html', form=form)
def appointment_create(): """Provide HTML form to create a new appointment record.""" form = AppointmentForm(request.form) if request.method == 'POST' and form.validate(): appt = Appointment(user_id=current_user.id) form.populate_obj(appt) db.session.add(appt) db.session.commit() # Success. Send the user back to the full appointment list. return redirect(url_for('appointment_list')) # Either first load or validation error at this point. return render_template('appointment/edit.html', form=form)
def appointment_edit(appointment_id): """Provide HTML form to edit a given appointment.""" appt = db.session.query(Appointment).get(appointment_id) if appt is None: abort(404) form = AppointmentForm(request.form, appt) if request.method == 'POST' and form.validate(): form.populate_obj(appt) db.session.commit() # Success. Send the user back to the detail view. return redirect(url_for('appointment_detail', appointment_id=appt.id)) return render_template('appointment/edit.html', form=form)
def appointment_create(): """Provide HTML form to create a new appointment.""" form = AppointmentForm(request.form) if request.method == 'POST' and form.validate(): appt = Appointment() form.populate_obj(appt) db.session.add(appt) db.session.commit() # Success. Send user back to full appointment list. return redirect(url_for('appointment_list')) # Either first load or validation error at this point. return render_template('appointment/edit.html', form=form)
def appointment_edit(appointment_id): """write the information to HTML to edit the given appointment""" appt = db.session.query(Appointment).get(appointment_id) if appt is None: abort(404) if appt.user_id != current_user.id: abort(403) form = AppointmentForm(request.form, appt) ###try to use only one parameter request.form if request.method == 'POST' and form.validate(): form.populate_obj(appt) db.session.commit() return redirect(url_for('appointment_detail', appointment_id=appt.id)) return render_template('appointment/edit.html', form=form)
def appointment_create(): """Provide HTML form to create a new appointment record.""" form = AppointmentForm(request.form) if request.method == "POST" and form.validate(): appt = Appointment(user_id=current_user.id) form.populate_obj(appt) if appt.done: current_user.total_points += appt.points db.session.add(appt) db.session.commit() # Success. Send the user back to the full appointment list. return redirect(url_for("appointment_list")) # Either first load or validation error at this point. return render_template("appointment/edit.html", form=form)
def appointment_edit(appointment_id): """Provide HTML form to edit a given appointment.""" appt = db.session.query(Appointment).get(appointment_id) if appt is None: abort(404) if appt.user_id != current_user.id: abort(403) form = AppointmentForm(request.form, appt) if request.method == "POST" and form.validate(): form.populate_obj(appt) if appt.done: current_user.total_points += appt.points db.session.commit() # Success. Send the user back to the detail view of that appointment. return redirect(url_for("appointment_detail", appointment_id=appt.id)) return render_template("appointment/edit.html", form=form)
from flask import render_template, abort, jsonify, redirect from flask import request, url_for from sched.forms import AppointmentForm from sched.models import Appointment app = Flask(__name__) app.debug = True @app.route("/") def index(): return render_template("index.html") @app.route('appointments/create', methods=['GET', 'POST']) form = AppointmentForm(request.form) if request.method == 'POST' and form.validate(): appt = Appointment() form.populate_obj(appt) db.session.add(appt) db.session.commit() return redirect(url_for('appointment_list')) return render_template('appointment/edit.html') if __name__ == "__main__": app.run()