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.
 
 
 
 
 

46 lines
2.1 KiB

from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, SubmitField, TextAreaField, DateTimeField, BooleanField, HiddenField
from wtforms.validators import DataRequired, EqualTo, ValidationError, Length
from app.models import Player
from pytz import timezone
class LoginForm(FlaskForm):
username = StringField('Username', validators=[DataRequired()])
password = PasswordField('Password', validators=[DataRequired()])
remember_me = BooleanField('Remember Me', default=True)
submit = SubmitField('Sign In')
class RegistrationForm(FlaskForm):
username = StringField('Username', validators=[DataRequired(), Length(min=0, max=64)])
password = PasswordField('Password', validators=[DataRequired(), Length(min=0, max=128)])
password2 = PasswordField(
'Repeat Password', validators=[DataRequired(), EqualTo('password')])
submit = SubmitField('Register')
def validate_username(self, username):
player = Player.query.filter_by(name=username.data).first()
if player is not None:
raise ValidationError('Please use a different username.')
class CreateGameForm(FlaskForm):
game_name = StringField('Game Name', validators=[DataRequired(), 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('Register')
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