from flask import Flask, render_template, redirect, url_for from flask_bootstrap import Bootstrap5 from flask_wtf import FlaskForm, CSRFProtect from wtforms import StringField, SubmitField, TextAreaField, IntegerField, RadioField from wtforms.validators import InputRequired, Length, NumberRange, Optional, Regexp from vals import name_val, key_val, ensemble_val, type_val, source_val, page_val, section_val import secrets app = Flask(__name__) foo = secrets.token_urlsafe(16) app.secret_key = foo csrf = CSRFProtect(app) # With Flask-WTF, each web form is represented by a class. # "NameForm" can change; "(FlaskForm)" cannot. # See route for "/" and "index.html" to see how this is used. class FronForm(FlaskForm): mkey = StringField('Key:', \ validators=[InputRequired(), key_val]) title = StringField('Title:', \ validators=[InputRequired(), Length(3, 40)]) subtitle = StringField('Subtitle:', \ validators=[Optional(), Length(1, 60)]) composer = StringField('Composer:', \ validators=[InputRequired(), name_val]) original_composer = StringField('Original Composer:', \ validators=[name_val]) ensemble = StringField('Ensemble:', \ validators=[InputRequired(), ensemble_val]) difficulty = RadioField('Difficulty:', \ choices=[('0', 'Beginner'), ('1', 'Easy'), ('2', 'Medium'), ('3', 'Challenging'), ('4', 'Hard'), ('5', 'Virtuoso')], \ validators = [InputRequired()]) mtype = StringField('Musical Type[s]:', \ validators=[InputRequired(), type_val]) section = StringField('Section Name:', \ validators=[section_val]) source = StringField('Source (name or library):', \ validators=[InputRequired(), source_val]) document = StringField('Book or manuscript:', \ validators=[InputRequired(), Length(5, 40)]) volume = IntegerField('Volume # (if any):', \ validators = [Optional(), NumberRange(min=1, max=99)]) page = StringField('Page:', \ validators = [InputRequired(), page_val]) editor = StringField('Editor:', \ validators=[InputRequired(), Length(10, 40)]) encoder = StringField('Encoder:', \ validators=[InputRequired(), Length(10, 40)]) arranger = StringField('Arranger:', \ validators=[Optional(), Length(10, 40)]) contributor = StringField('Contributor:', \ validators=[Optional(), Length(10, 40)]) remarks = TextAreaField('Remarks:', \ validators=[Optional()]) submit = SubmitField('Submit')