from flask_wtf import FlaskForm from flask_wtf.file import FileField, FileAllowed, FileRequired from wtforms import StringField, SubmitField, FloatField, SelectField from wtforms.validators import InputRequired, DataRequired, ValidationError, Length, NumberRange from app.models import Objective from app import Config class ObjectiveForm(FlaskForm): objective_name = StringField('Objective Name', validators=[Length(min=0, max=64)]) latitude = FloatField('Latitude', validators=[DataRequired(), NumberRange(min=-90, max=90)]) longitude = FloatField('Longitude', validators=[DataRequired(), NumberRange(min=-180, max=180)]) submit = SubmitField('Save') old_name = '' def validate_objective_name(self, objective_name): if objective_name.data == '': return if objective_name.data == self.old_name: return objective = Objective.query.filter_by(name=objective_name.data).first() if objective is not None: raise ValidationError('Please use a different name.') class PlayerUpdateForm(FlaskForm): role = SelectField('Player Role', coerce=int, validators=[InputRequired()]) submit = SubmitField('Update') class PlayerAddForm(FlaskForm): name = StringField('Username', validators=[InputRequired(), Length(min=0, max=64)]) role = SelectField('Player Role', coerce=int, validators=[InputRequired()]) submit_add = SubmitField('Create') class UserCreateForm(FlaskForm): name = StringField('Username', validators=[InputRequired(), Length(min=0, max=64)]) role = SelectField('Player Role', coerce=int, validators=[InputRequired()]) submit_create = SubmitField('Create') class CatchBunnyForm(FlaskForm): bunny = SelectField('Bunny Name', coerce=int, validators=[InputRequired()]) photo = FileField('Upload Photo', validators=[FileRequired(), FileAllowed(Config.ALLOWED_PHOTO_EXTENSIONS, 'Images only!')]) submit = SubmitField('Send')