Chapter 7

This commit is contained in:
2023-06-03 18:07:36 +02:00
parent 4dd7d11190
commit 8c1df34587
7 changed files with 85 additions and 2 deletions

View File

@@ -47,3 +47,13 @@ class EditProfileForm(FlaskForm):
username = StringField("Username", validators=[DataRequired()])
about_me = TextAreaField("About me", validators=[Length(min=0, max=140)])
submit = SubmitField("Submit")
def __init__(self, original_username, *args, **kwargs):
super(EditProfileForm, self).__init__(*args, **kwargs)
self.original_username = original_username
def validate_username(self, username):
if username.data != self.original_username:
user = User.query.filter_by(username=self.username.data).first()
if user is not None:
raise ValidationError("Please use a different username.")