Advertisement
alecd3v

Untitled

Feb 11th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. class UpdateProfileForm(Form):
  2. username = StringField('Username', validators=[Optional()])
  3. password = PasswordField('Password', validators=[Optional(), Regexp("^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,15}$",
  4. message='Password must be between 8-15 characters, with at least 1 lower or upper and 1 number')])
  5.  
  6. password_repeat = PasswordField('Repeat password', validators=[EqualTo('password')])
  7. first_name = StringField('First name', validators=[Optional()])
  8. last_name = StringField('Last name', validators=[Optional()])
  9. country = SelectField('Country', choices=countrylist, validators=[Optional()])
  10. university = StringField('University', validators=[Optional()])
  11. description = StringField('My description', widget=TextArea(), validators=[Length( max=1024)])
  12. img = FileField('Profile picture', validators=[Optional()])
  13.  
  14. def validate_username(self, username):
  15. user = User.query.filter_by(username=username.data).first()
  16. if user is not None:
  17. raise ValidationError('Username already exists')
  18.  
  19. def validate_birth_date(self, birth_date):
  20. birth_date_as_datetime = datetime.combine(birth_date.data, datetime.min.time())
  21. years = date_as_float(datetime.now()) - date_as_float(birth_date_as_datetime)
  22. if years < 18:
  23. raise ValidationError('The user must be at least 16 years old')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement