from multiprocessing import Process
from flask import Flask, render_template, redirect, url_for
from flask_bootstrap import Bootstrap5
from flask_wtf import FlaskForm, CSRFProtect
from vals import *
from form import FronForm 
from load import process_form
import secrets
# Bootstrap-Flask requires this line
app = Flask(__name__)
foo = secrets.token_urlsafe(16)
app.secret_key = foo
csrf = CSRFProtect(app)
bootstrap = Bootstrap5(app)

# all Flask routes below
@app.route('/', methods=['GET', 'POST'])
def index():
    form = FronForm()
    message = ""
    if form.btn_cancel.data:
        return redirect('https://lutemusic.org')
    if form.validate_on_submit():
        process_form(form)
    return render_template('index_fron.html',  form=form, message=message)

if __name__ == '__main__':
    server = Process(target=app.run(debug=True))
    server.start()
    server.terminate()
    server.join()
