Update deprecated code: FlaskForm.

This commit is contained in:
Edward Betts 2018-05-31 12:18:28 +01:00
parent 0037c52255
commit b57df6df6c

View file

@ -1,4 +1,4 @@
from flask_wtf import Form from flask_wtf import FlaskForm
from wtforms.fields import StringField, PasswordField, BooleanField, HiddenField, TextAreaField, FileField, IntegerField from wtforms.fields import StringField, PasswordField, BooleanField, HiddenField, TextAreaField, FileField, IntegerField
from wtforms.validators import InputRequired, Email, Length, ValidationError, Regexp, NoneOf, Optional from wtforms.validators import InputRequired, Email, Length, ValidationError, Regexp, NoneOf, Optional
from .model import User, LoginError, re_username, reserved_name, user_exists from .model import User, LoginError, re_username, reserved_name, user_exists
@ -6,7 +6,7 @@ from .model import User, LoginError, re_username, reserved_name, user_exists
PASSWORD_LEN = 64 PASSWORD_LEN = 64
EMAIL_LEN = 64 EMAIL_LEN = 64
class SignupForm(Form): class SignupForm(FlaskForm):
username = StringField('username', username = StringField('username',
[InputRequired(), [InputRequired(),
Regexp(re_username), Regexp(re_username),
@ -28,7 +28,7 @@ class SignupForm(Form):
if user_exists(User.email, field.data): if user_exists(User.email, field.data):
raise ValidationError('In use by another account') raise ValidationError('In use by another account')
class LoginForm(Form): class LoginForm(FlaskForm):
user_or_email = StringField('username or e-mail address', user_or_email = StringField('username or e-mail address',
[InputRequired(), Length(min=3, max=EMAIL_LEN)], [InputRequired(), Length(min=3, max=EMAIL_LEN)],
[lambda name: name and name.replace(' ', '_')]) [lambda name: name and name.replace(' ', '_')])
@ -38,7 +38,7 @@ class LoginForm(Form):
next = HiddenField('next') next = HiddenField('next')
def validate(self): def validate(self):
rv = Form.validate(self) rv = FlaskForm.validate(self)
if not rv: if not rv:
return False return False
@ -50,33 +50,33 @@ class LoginForm(Form):
self.user_or_email.errors.append(e.msg) self.user_or_email.errors.append(e.msg)
return False return False
class ForgotPasswordForm(Form): class ForgotPasswordForm(FlaskForm):
user_or_email = StringField('username or e-mail address', user_or_email = StringField('username or e-mail address',
[InputRequired(), Length(max=EMAIL_LEN)]) [InputRequired(), Length(max=EMAIL_LEN)])
class PasswordForm(Form): class PasswordForm(FlaskForm):
password = PasswordField('new password', password = PasswordField('new password',
[InputRequired(), Length(min=4, max=PASSWORD_LEN)]) [InputRequired(), Length(min=4, max=PASSWORD_LEN)])
class AccountSettingsForm(Form): class AccountSettingsForm(FlaskForm):
full_name = StringField('full name', [Length(max=64)]) full_name = StringField('full name', [Length(max=64)])
email = StringField('e-mail address', email = StringField('e-mail address',
[InputRequired(), Email(), [InputRequired(), Email(),
Length(min=5, max=EMAIL_LEN)]) Length(min=5, max=EMAIL_LEN)])
class ChangePasswordForm(Form): class ChangePasswordForm(FlaskForm):
old_password = PasswordField('current password', old_password = PasswordField('current password',
[InputRequired(), Length(max=PASSWORD_LEN)]) [InputRequired(), Length(max=PASSWORD_LEN)])
new_password = PasswordField('new password', new_password = PasswordField('new password',
[InputRequired(), Length(max=PASSWORD_LEN)]) [InputRequired(), Length(max=PASSWORD_LEN)])
class SourceDocForm(Form): class SourceDocForm(FlaskForm):
text = TextAreaField('text', [InputRequired()]) text = TextAreaField('text', [InputRequired()])
db_price_per_character = IntegerField('price per character', [Optional()]) db_price_per_character = IntegerField('price per character', [Optional()])
db_document_price = IntegerField('document price', [Optional()]) db_document_price = IntegerField('document price', [Optional()])
class ItemForm(Form): class ItemForm(FlaskForm):
text = TextAreaField('text', [InputRequired()]) text = TextAreaField('text', [InputRequired()])
class UploadSourceDocForm(Form): class UploadSourceDocForm(FlaskForm):
sourcedoc_file = FileField('SourceDoc', [Regexp(r'^[^/\\]+\.txt$')]) sourcedoc_file = FileField('SourceDoc', [Regexp(r'^[^/\\]+\.txt$')])