class LoginForm(Form): email = TextField( u'登录邮箱', validators=[required(message=u'必填'), email(message=u'不是有效的邮箱地址')]) password = PasswordField(u'密码', validators=[required(message=u'必填')]) next = HiddenField()
class SignupForm(Form): next = HiddenField() username = TextField(_("Username"), validators=[ required(message=_("Username required")), is_username]) password = PasswordField(_("Password"), validators=[ required(message=_("Password required"))]) password_again = PasswordField(_("Password again"), validators=[ equal_to("password", message=\ _("Passwords don't match"))]) email = TextField(_("Email address"), validators=[ required(message=_("Email address required")), email(message=_("A valid email address is required"))]) recaptcha = RecaptchaField(_("Copy the words appearing below")) submit = SubmitField(_("Signup")) def validate_username(self, field): user = User.query.filter(User.username.like(field.data)).first() if user: raise ValidationError, gettext("This username is taken") def validate_email(self, field): user = User.query.filter(User.email.like(field.data)).first() if user: raise ValidationError, gettext("This email is taken")
class RecoverPasswordForm(Form): email = TextField( "Your email address", validators=[email(message=_("A valid email address is required"))]) submit = SubmitField(_("Find password"))
class CashForm(Form): alipay = TextField( u"支付宝账户", validators=[required(message=u"请填写支付宝邮箱地址"), email(message=u"邮箱格式错误")]) money = TextField(u"提现金额", validators=[required(message=u"请填写您要提现的金额"), is_num]) submit = SubmitField(u"提交") hidden = HiddenField()
class RegisterForm(Form): email = TextField( u'登录邮箱', validators=[required(message=u'必填'), email(message=u'不是有效的邮箱地址')]) password = PasswordField(u'密码', validators=[required(message=u'必填')]) confirm_password = PasswordField(u'确认密码', validators=[ equal_to('password', message=u'密码不一致'), required(message=u'必填') ]) agree_term = TextField(u'条款确认', validators=[required(message=u'必选')])
class ContactForm(Form): name = TextField(_("Your name"), validators=[required(message=_('Your name is required'))]) email = TextField(_("Your email address"), validators=[ required(message=_("Email address required")), email(message=_("A valid email address is required")) ]) subject = TextField(_("Subject"), validators=[required(message=_("Subject required"))]) message = TextAreaField( _("Message"), validators=[required(message=_("Message required"))]) submit = SubmitField(_("Send"))
class LinkForm(Form): name = TextField(_("Site name"), validators=[required(message=_("Name required"))]) link = TextField(_("link"), validators=[url(message=_("A valid url is required"))]) email = TextField( _("Email"), validators=[email(message=_("A valid email is required"))]) logo = TextField( _("Logo"), validators=[optional(), url(message=_("A valid url is required"))]) description = TextAreaField(_("Description")) submit = SubmitField(_("Save"))
class CommentForm(Form): email = TextField(_("Email"), validators=[ required(message=_("Email required")), email(message=_("A valid email address is required")) ]) nickname = TextField(_("Nickname"), validators=[required(message=_("Nickname required"))]) website = TextField( _("Website"), validators=[optional(), url(message=_("A valid url is required"))]) comment = TextAreaField( _("Comment"), validators=[required(message=_("Comment required"))]) submit = SubmitField(_("Add comment")) cancel = SubmitField(_("Cancel"))
class SignupForm(Form): nickname = TextField( _("Nickname"), validators=[required(message=_("Nickname required")), is_username]) email = TextField(_("Email address"), validators=[ required(message=_("Email address required")), email(message=_("A valid email address is required")) ]) next = HiddenField() submit = SubmitField(_("Create profile")) def validate_nickname(self, field): user = User.query.filter_by( nickname=field.data and field.data.strip()).first() if user: raise ValidationError, gettext("This nickname is taken") def validate_email(self, field): user = User.query.filter_by( email=field.data and field.data.strip()).first() if user: raise ValidationError, gettext("This email is taken")
class EditAccountForm(Form): username = TextField("Username", validators=[ required(_("Username is required")), is_username]) email = TextField(_("Your email address"), validators=[ required(message=_("Email address required")), email(message=_("A valid email address is required"))]) receive_email = BooleanField(_("Receive private emails from friends")) email_alerts = BooleanField(_("Receive an email when somebody replies " "to your post or comment")) submit = SubmitField(_("Save")) def __init__(self, user, *args, **kwargs): self.user = user kwargs['obj'] = self.user super(EditAccountForm, self).__init__(*args, **kwargs) def validate_username(self, field): user = User.query.filter(db.and_( User.username.like(field.data), db.not_(User.id==self.user.id))).first() if user: raise ValidationError, gettext("This username is taken") def validate_email(self, field): user = User.query.filter(db.and_( User.email.like(field.data), db.not_(User.id==self.user.id))).first() if user: raise ValidationError, gettext("This email is taken")