class ChangeUserDetailsForm(Form): birthday = BirthdayField(_("Birthday"), format="%d %m %Y", validators=[Optional()], widget=SelectBirthdayWidget()) gender = SelectField(_("Gender"), default="None", choices=[("None", ""), ("Male", _("Male")), ("Female", _("Female"))]) location = StringField(_("Location"), validators=[Optional()]) website = StringField(_("Website"), validators=[Optional(), URL()]) avatar = StringField(_("Avatar"), validators=[Optional(), URL()]) signature = TextAreaField(_("Forum Signature"), validators=[Optional()]) notes = TextAreaField(_("Notes"), validators=[Optional(), Length(min=0, max=5000)]) submit = SubmitField(_("Save")) def validate_birthday(self, field): if field.data is None: return True def validate_avatar(self, field): if field.data is not None: error, status = check_image(field.data) if error is not None: raise ValidationError(error) return status
class NewReminderForm(FlaskForm): subject = StringField(_("Subject"), validators=[DataRequired(), Length(min=6, max=100)]) content = TextAreaField(_("Content"), validators=[ Optional(), Length(min=0, max=500)]) delta = SelectField('Notification time', choices=appointment_times, validators=[DataRequired()]) time = BirthdayField(_("Time"), format="%d %m %Y %H:%M", validators=[ DataRequired()]) timezone = SelectField( 'Time zone', choices=_timezones(), validators=[DataRequired()]) submit = SubmitField(_("Save")) def save(self,user_id=None): data = self.data data.pop('submit', None) data.pop('csrf_token', None) remi = Reminder(**data) remi.time = arrow.get(remi.time, remi.timezone).to('utc').naive if user_id: return remi.save(user_id) #add else: return remi.save() #edit
class ChangeUserDetailsForm(FlaskBBForm): birthday = BirthdayField(_("Birthday"), format="%d %m %Y", validators=[Optional()]) gender = StringField(_("Gender"), validators=[Optional()]) location = StringField(_("Location"), validators=[Optional()]) website = StringField(_("Website"), validators=[Optional(), URL()]) avatar = StringField(_("Avatar"), validators=[Optional(), URL()]) signature = TextAreaField(_("Forum Signature"), validators=[Optional()]) notes = TextAreaField(_("Notes"), validators=[Optional(), Length(min=0, max=5000)]) submit = SubmitField(_("Save")) def validate_birthday(self, field): if field.data is None: return True def as_change(self): return UserDetailsChange( birthday=self.birthday.data, gender=self.gender.data, location=self.location.data, website=self.website.data, avatar=self.avatar.data, signature=self.signature.data, notes=self.notes.data, )
class PetForm(FlaskForm): petname = StringField(_("Pet name"), validators=[is_username,Length(min=0, max=100)]) breed = StringField(_("Pet Breed"), validators=[Optional(),is_username,Length(min=0, max=100)]) birthday = BirthdayField(_("Birthday"), format="%d %m %Y", validators=[ Optional()]) gender = SelectField(_("Gender"), default="None", choices=[ ("None", ""), ("Male", _("Male")), ("Female", _("Female"))]) avatar = StringField(_("Avatar"), validators=[ Optional()]) info = TextAreaField(_("Notes"), validators=[ Optional(), Length(min=0, max=5000)]) submit = SubmitField(_("Save")) def validate_birthday(self, field): if field.data is None: return True def save(self,owner=None): data = self.data data.pop('submit', None) data.pop('csrf_token', None) pet = Pet(**data) if owner: return pet.save(owner) #add pet else: return pet.save() #edit pet
class UserForm(FlaskForm): username = StringField( _("Username"), validators=[ DataRequired(message=_("A valid username is required.")), is_username ]) email = StringField( _("Email address"), validators=[ DataRequired(message=_("A valid email address is required.")), Email(message=_("Invalid email address.")) ]) password = PasswordField("Password", validators=[DataRequired()]) birthday = BirthdayField(_("Birthday"), format="%d %m %Y", validators=[Optional()]) gender = SelectField(_("Gender"), default="None", choices=[("None", ""), ("Male", _("Male")), ("Female", _("Female"))]) location = StringField(_("Location"), validators=[Optional()]) website = StringField(_("Website"), validators=[Optional(), URL()]) avatar = StringField(_("Avatar"), validators=[Optional(), URL()]) signature = TextAreaField(_("Forum signature"), validators=[Optional()]) notes = TextAreaField(_("Notes"), validators=[Optional(), Length(min=0, max=5000)]) activated = BooleanField(_("Is active?"), validators=[Optional()]) primary_group = QuerySelectField(_("Primary group"), query_factory=select_primary_group, get_label="name") secondary_groups = QuerySelectMultipleField( _("Secondary groups"), # TODO: Template rendering errors "NoneType is not callable" # without this, figure out why. query_factory=select_primary_group, get_label="name") submit = SubmitField(_("Save")) def validate_username(self, field): if hasattr(self, "user"): user = User.query.filter( db.and_(User.username.like(field.data.lower()), db.not_(User.id == self.user.id))).first() else: user = User.query.filter(User.username.like( field.data.lower())).first() if user: raise ValidationError(_("This username is already taken.")) def validate_email(self, field): if hasattr(self, "user"): user = User.query.filter( db.and_(User.email.like(field.data.lower()), db.not_(User.id == self.user.id))).first() else: user = User.query.filter(User.email.like( field.data.lower())).first() if user: raise ValidationError(_("This email address is already taken.")) def validate_avatar(self, field): if field.data is not None: error, status = check_image(field.data) if error is not None: raise ValidationError(error) return status def save(self): data = self.data data.pop('submit', None) data.pop('csrf_token', None) user = User(**data) return user.save()
class UserForm(Form): username = StringField( _("Username"), validators=[ DataRequired(message=_("A Username is required.")), is_username ]) email = StringField( _("E-Mail Address"), validators=[ DataRequired(message=_("A E-Mail Address is required.")), Email(message=_("Invalid E-Mail Address.")) ]) password = PasswordField("Password", validators=[Optional()]) birthday = BirthdayField(_("Birthday"), format="%d %m %Y", widget=SelectBirthdayWidget(), validators=[Optional()]) gender = SelectField(_("Gender"), default="None", choices=[("None", ""), ("Male", _("Male")), ("Female", _("Female"))]) location = StringField(_("Location"), validators=[Optional()]) website = StringField(_("Website"), validators=[Optional(), URL()]) avatar = StringField(_("Avatar"), validators=[Optional(), URL()]) signature = TextAreaField(_("Forum Signature"), validators=[Optional(), Length(min=0, max=250)]) notes = TextAreaField(_("Notes"), validators=[Optional(), Length(min=0, max=5000)]) primary_group = QuerySelectField(_("Primary Group"), query_factory=select_primary_group, get_label="name") secondary_groups = QuerySelectMultipleField( _("Secondary Groups"), # TODO: Template rendering errors "NoneType is not callable" # without this, figure out why. query_factory=select_primary_group, get_label="name") submit = SubmitField(_("Save")) def validate_username(self, field): if hasattr(self, "user"): user = User.query.filter( db.and_(User.username.like(field.data), db.not_(User.id == self.user.id))).first() else: user = User.query.filter(User.username.like(field.data)).first() if user: raise ValidationError(_("This Username is already taken.")) def validate_email(self, field): if hasattr(self, "user"): user = User.query.filter( db.and_(User.email.like(field.data), db.not_(User.id == self.user.id))).first() else: user = User.query.filter(User.email.like(field.data)).first() if user: raise ValidationError(_("This E-Mail Address is already taken.")) def save(self): user = User(**self.data) return user.save()
class F(Form): birthday = BirthdayField(format='%d %m %Y')