from flask_wtf import FlaskForm from flask_wtf.file import FileField, FileRequired, FileAllowed from wtforms import StringField, PasswordField, BooleanField, DateField, SelectField, IntegerField from wtforms.validators import InputRequired, Email, Length, EqualTo, Optional from datetime import date, timedelta from .validators import value class LoginForm(FlaskForm): username = StringField('Username', validators=[InputRequired(), Length(min=4, max=15)]) password = PasswordField('Password', validators=[InputRequired(), Length(min=6, max=30, message='The password must be between 6 and 20 characters long.')]) remember = BooleanField('Remember Log In', render_kw={'checked': True}) class RegistrationForm(FlaskForm): username = StringField('Username', validators=[InputRequired(), Length(min=4, max=15)]) email = StringField('Email Address', validators=[InputRequired(), Email(message='You must enter a valid email address.'), Length(max=50)]) password = PasswordField('Password', validators=[InputRequired(), Length(min=6, max=30, message='The password must be between 6 and 20 characters long.')]) password_reenter = PasswordField('Re-Enter Password', validators=[InputRequired(), Length(min=6, max=30, message='The password must be between 6 and 20 characters long.'), EqualTo('password', message='Passwords do not match.')]) class ResetPasswordForm(FlaskForm): username = StringField('Username', validators=[InputRequired(), Length(min=4, max=15)]) email = StringField('Email Address', validators=[InputRequired(), Email(message='You must enter a valid email address.'), Length(max=50)]) class UpdatePasswordForm(FlaskForm): password = PasswordField('Password', validators=[InputRequired(), Length(min=6, max=30, message='The password must be between 6 and 20 characters long.')]) password_reenter = PasswordField('Re-Enter Password', validators=[InputRequired(), Length(min=6, max=30, message='The password must be between 6 and 20 characters long.'), EqualTo('password', message='Passwords do not match.')]) class CreateUserForm(FlaskForm): username = StringField('Username', validators=[InputRequired(), Length(min=4, max=15)]) email = StringField('Email Address', validators=[InputRequired(), Email(message='You must enter a valid email address.'), Length(max=50)]) password = PasswordField('Password (Optional)', validators=[Optional(),Length(min=6, max=30, message='The password must be between 6 and 20 characters long.')]) class DeleteUserForm(FlaskForm): password = PasswordField('Confirm Your Password', validators=[InputRequired(), Length(min=6, max=30, message='The password must be between 6 and 20 characters long.')]) notify = BooleanField('Notify deletion by email', render_kw={'checked': True}) class UpdateUserForm(FlaskForm): user_password = PasswordField('Confirm Your Password', validators=[InputRequired(), Length(min=6, max=30, message='The password must be between 6 and 20 characters long.')]) email = StringField('Email Address', validators=[Optional(), Email(message='You must enter a valid email address.'), Length(max=50)]) password = PasswordField('Change Password', validators=[Optional(),Length(min=6, max=30, message='The password must be between 6 and 20 characters long.')]) password_reenter = PasswordField('Re-Enter New Password', validators=[EqualTo('password', message='Passwords do not match.')]) notify = BooleanField('Notify changes by email', render_kw={'checked': True}) class UpdateAccountForm(FlaskForm): password_confirm = PasswordField('Current Password', validators=[InputRequired(), Length(min=6, max=30, message='The password must be between 6 and 20 characters long.')]) email = StringField('Email Address', validators=[Optional(), Email(message='You must enter a valid email address.'), Length(max=50)]) password = PasswordField('Change Password', validators=[Optional(),Length(min=6, max=30, message='The password must be between 6 and 20 characters long.')]) password_reenter = PasswordField('Re-Enter New Password', validators=[EqualTo('password', message='Passwords do not match.')]) class CreateTest(FlaskForm): start_date = DateField('Start Date', format="%Y-%m-%d", validators=[InputRequired()], default = date.today() ) expiry_date = DateField('Expiry Date', format="%Y-%m-%d", validators=[InputRequired()], default = date.today() + timedelta(days=1) ) time_limit = SelectField('Time Limit') dataset = SelectField('Question Dataset') class UploadDataForm(FlaskForm): data_file = FileField('Data File', validators=[FileRequired(), FileAllowed(['json'])]) default = BooleanField('Make Default', render_kw={'checked': True}) class AddTimeAdjustment(FlaskForm): time = IntegerField('Extra Time (Minutes)', validators=[InputRequired(), value(max=60)])