def book(): # Set BookForm so we can send it's data to the template for rendering. form = BookForm() if form.validate_on_submit(): # Save form data to special Flask session. This # persists data for the entire client's session # with the server. session['first_name'] = form.first_name.data session['last_name'] = form.last_name.data session['publisher'] = form.publisher.data session['book_title'] = form.book_title.data session['year'] = form.year.data # Reset the form field to blank. form.first_name.data = '' form.last_name.data = '' form.publisher.data = '' form.book_title.data = '' form.year.data = '' # redirect after form submit. return redirect(url_for('book')) # Set the key we will be testing for. key = 'year' # See if the key exists already, if it does, then send the session data # to the template. if key in session: return render_template("book.html", first_name=session['first_name'], last_name=session['last_name'], publisher=session['publisher'], book_title=session['book_title'], year=session['year'], form=form) # If it doesn't exist, render the template without sending the session data. else: return render_template("book.html", form=form)
def tennis4(): if CID!=0: form=BookForm() with sqlite3.connect('Locus.db')as db: c=db.cursor() check="SELECT * FROM Booking" for row in c.execute(check): if row[3]==str(form.date.data) and row[2]==16: flash(f'The facility is already booked for that date','danger') return redirect(url_for('tennis4')) if form.validate_on_submit(): with sqlite3.connect('Locus.db')as db: c=db.cursor() c.execute("INSERT INTO Booking(ClientID, FacilityID, Date) VALUES(?,?,?)", (CID, 16, form.date.data)) global FID FID=16 global BDate BDate=form.date.data return redirect(url_for('confirmation')) if form.date.errors: flash(f'Enter date in dd/mm/yy format', 'danger') return render_template('tennis(4).html', form=form) else: return redirect(url_for('login'))