You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
3.1 KiB
62 lines
3.1 KiB
from flask_wtf import FlaskForm |
|
from flask_wtf.file import FileField, FileAllowed, FileRequired |
|
from wtforms import StringField, SubmitField, DateTimeField, BooleanField, HiddenField, FloatField, SelectField |
|
from wtforms.validators import InputRequired, DataRequired, ValidationError, Length, NumberRange |
|
from pytz import timezone |
|
from app.models import Objective |
|
from app import Config |
|
|
|
class CreateGameForm(FlaskForm): |
|
game_name = StringField('Game Name', validators=[InputRequired(), Length(min=0, max=64)]) |
|
start_time_disabled = BooleanField('No start time') |
|
start_time = DateTimeField(id='datetimepicker_start', format="%d-%m-%Y %H:%M") |
|
end_time_disabled = BooleanField('No end time') |
|
end_time = DateTimeField(id='datetimepicker_end', format="%d-%m-%Y %H:%M") |
|
timezone = HiddenField(validators=[DataRequired()]) |
|
submit = SubmitField('Create') |
|
|
|
def validate_start_time(self, start_time): |
|
self.date_time_validator(self.start_time_disabled, start_time) |
|
|
|
def validate_end_time(self, end_time): |
|
self.date_time_validator(self.end_time_disabled, end_time) |
|
|
|
def date_time_validator(self, disabled, date_time): |
|
if disabled.data: |
|
date_time.data = None |
|
return |
|
clientzone = timezone(self.timezone.data) |
|
date_time_utc = clientzone.localize(date_time.data).astimezone(timezone('UTC')) |
|
date_time.data = date_time_utc |
|
|
|
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') |
|
|
|
def validate_objective_name(self, objective_name): |
|
if objective_name.data == '': |
|
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', choices=[('none', 'none'), ('owner', 'owner'), ('hunter', 'hunter'), ('bunny', 'bunny')], validators=[InputRequired()]) |
|
submit_add = SubmitField('Create') |
|
|
|
class UserCreateForm(FlaskForm): |
|
name = StringField('Username', validators=[InputRequired(), Length(min=0, max=64)]) |
|
role = SelectField('Player Role', choices=[('none', 'none'), ('owner', 'owner'), ('hunter', 'hunter'), ('bunny', 'bunny')], 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')
|
|
|