from flask_babel import lazy_gettext as _ from flask_wtf import FlaskForm from wtforms import PasswordField, StringField, BooleanField from wtforms.ext.dateutil.fields import DateTimeField from wtforms.validators import DataRequired, Email, ValidationError from wtforms.widgets import TextArea class RegistrationForm(FlaskForm): username = StringField(_('Username'), validators=[DataRequired()]) email = StringField(_('Email address'), validators=[Email()]) password = PasswordField(_('Password'), validators=[DataRequired()]) password_retype = PasswordField(_('Password, once more'), validators=[DataRequired()]) def validate_password_retype(self, field): if field.data != self.password.data: raise ValidationError(_('The two passwords must match!')) class EventForm(FlaskForm): title = StringField(_('Title'), validators=[DataRequired()]) time_zone = StringField(_('Time zone'), validators=[DataRequired()]) start_time = DateTimeField(_('Start time'), validators=[DataRequired()]) end_time = DateTimeField(_('End time'), validators=[DataRequired()]) all_day = BooleanField(_('All day')) description = StringField(_('Description'), widget=TextArea()) def validate_end_time(self, field): if field.data < self.start_time.data: raise ValidationError(_('End time must be later than start time!'))