Created
March 30, 2020 19:48
-
-
Save Porter97/6162b7d7092121d3c9ffb4477708b39d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask_login import current_user | |
from flask_wtf import FlaskForm | |
from wtforms import StringField, TextAreaField | |
from wtforms.validators import Length, Regexp | |
from wtforms import ValidationError | |
from ..models import User | |
class EditProfileForm(FlaskForm): | |
class Meta: | |
csrf = False | |
name = StringField('name', validators=[Length(0, 64)]) | |
username = StringField('username', validators=[Length(1, 64), | |
Regexp('^[A-Za-z][A-Za-z0-9_.]*$', 0, | |
'Usernames must have only letters, numbers, dots or ' | |
'underscores')]) | |
about_me = TextAreaField('about_me') | |
def validate_username(self, field): | |
if field.data and field.data != current_user.username: | |
if User.query.filter_by(username=field.data).first(): | |
raise ValidationError('Username already in use.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment