Пример #1
0
 def test_equal_to(self):
     self.form['foo'] = DummyField('test')
     self.assertEqual(equal_to('foo')(self.form, self.form['foo']), None)
     self.assertRaises(ValidationError, equal_to('invalid_field_name'),
                       self.form, DummyField('test'))
     self.assertRaises(ValidationError, equal_to('foo'), self.form,
                       DummyField('different_value'))
Пример #2
0
def test_lazy_proxy_fixture(really_lazy_proxy):
    """
    Tests that the validators support lazy translation strings for messages.
    """
    equal_to("fieldname", message=really_lazy_proxy)
    length(min=1, message=really_lazy_proxy)
    NumberRange(1, 5, message=really_lazy_proxy)
    data_required(message=really_lazy_proxy)
    regexp(".+", message=really_lazy_proxy)
    email(message=really_lazy_proxy)
    ip_address(message=really_lazy_proxy)
    url(message=really_lazy_proxy)
Пример #3
0
class RegisterForm(Form):
    name= StringField("İsim",validators=[validators.Length(min=2,max=15),validators.DataRequired("Lütfen Bütün alanları doldurunuz.")])
    surname= StringField("Soyisim",validators=[validators.Length(min=2,max=15),validators.DataRequired("Lütfen Bütün alanları doldurunuz.")])
    email=StringField("Email Adresi",validators=[validators.Email("Email adresi geçerli değil."),validators.DataRequired("Lütfen Bütün alanları doldurunuz.")])
    password=PasswordField("Parola:",validators=[
        validators.DataRequired("Şifre alanı boş bırakılamaz..."),
        validators.equal_to(fieldname="confirm",message="girilen şifreler aynı değil!")

    ])
    confirm= PasswordField("Şifre Doğrula:",validators=[
        validators.DataRequired("Şifre alanı boş bırakılamaz..."),
        validators.equal_to(fieldname="confirm",message="girilen şifreler aynı değil!")

    ])
Пример #4
0
class RegisterForm(FlaskForm):
    user_name = StringField(label="userName", validators=[DataRequired()])
    password = PasswordField(label="passWord", validators=[DataRequired()])
    password2 = PasswordField(
        label="confirm_passWord",
        validators=[DataRequired(), equal_to("password")])
    submit = SubmitField(label="submit")
Пример #5
0
class RegisterForm(Form):

    email = TextField(u'邮箱', [validators.Required(message=u"邮箱不能为空")])
    username = TextField(u'用户名', [validators.Required(message=u"用户名不能为空")])
    nickname = TextField(u'昵称', [
        validators.Required(message=u"每个响亮的昵称怎么混?"),
        validators.length(max=4, message=u'要有咱也不能太长呀,最长4个字符')
    ])
    password = PasswordField(u'密码', [
        validators.Required(message=u"密码不能为空"),
        validators.length(max=16, message=u'要有咱也不能太长呀,最长16个字符')
    ])
    password_confirm = PasswordField(u'密码确认', [
        validators.Required(message=u"请再次输入密码"),
        validators.equal_to('password', message=u'两次输入的密码必须要一致')
    ])
    recaptcha = RecaptchaField(u'验证码', [Recaptcha(message=u'验证码不正确')])

    def validate_email(self, field):
        with session_cm() as session:
            if session.query(User).filter(User.email == field.data).first():
                raise ValueError(u"该邮箱已经存在")

    def validate_username(self, field):
        with session_cm() as session:
            pattern = re.compile(r'^\w{6,16}$')
            if pattern.match(field.data) is None:
                raise ValueError(u"用户名只能由字母、下划线、数字组成,且字符数在(6-16)之间")
            if session.query(User).filter(User.username == field.data).first():
                raise ValueError(u"该用户名已经存在")
Пример #6
0
class register_form(Form):
    username = StringField(label='Username',
                           validators=[validators.InputRequired()])
    fullName = StringField(label='Full Name',
                           validators=[validators.InputRequired()])
    reason = StringField(label='Reason for Account Creation')

    password = PasswordField(label='Password',
                             validators=[
                                 validators.InputRequired(),
                                 validators.equal_to(
                                     'confirm', message='Passwords must match')
                             ])
    email = html5.EmailField(label='Email',
                             validators=[validators.InputRequired()])
    confirm = PasswordField(label='Confirm Password',
                            validators=[validators.InputRequired()])

    institution = StringField(label='Institution')

    def validate(self):
        if not Form.validate(self):
            return False

        if db.session.query(User).filter_by(
                username=self.username.data).count() > 0:
            self.username.errors.append('User already exists')
            return False

        return True
Пример #7
0
class ChangeSetting(FlaskForm):
    """ Used for changing the username or password that is required to login on the dashboard. """
    username = StringField('Username', [validators.data_required()])
    password = PasswordField('New password',
                             [validators.equal_to(fieldname='confirm')])
    confirm = PasswordField('Confirm password')
    submit = SubmitField('Update changes')
Пример #8
0
class RegistrationForm(FlaskForm):
    username = StringField('username', validators=[DataRequired()])
    password = PasswordField('password', validators=[DataRequired()])
    confirm_password = PasswordField(
        'confirm password', validators=[DataRequired(),
                                        equal_to('password')])
    submit = SubmitField('sign-up')
Пример #9
0
class RegistrationForm(FlaskForm):
    email = StringField('Email',
                        validators=[DataRequired(),
                                    Length(1, 64),
                                    Email()])
    username = StringField(
        'Username',
        validators=[
            DataRequired(),
            Length(1, 64),
            regexp(
                '^[A-Za-z][A-Za-z0-9_.]*$', 0,
                'Usernames must have only letters, numbers, dots or '
                'underscores')
        ])  # 确保username字段的值是以字母开头的,只包含数字字母下划线
    password = PasswordField('Password',
                             validators=[
                                 DataRequired(),
                                 equal_to('password2',
                                          message='Passwords must match.')
                             ])
    password2 = PasswordField('Confirm password', validators=[DataRequired()])
    submit = SubmitField('Register')

    def validate_email(self, field):
        if User.query.filter_by(email=field.data.lower()).first():
            raise ValidationError("Email already registered.")

    def validate_username(self, field):
        if User.query.filter_by(username=field.data).first():
            raise ValidationError("Username already in use.")
Пример #10
0
class ChangePasswordForm(Form):
    old_password = PasswordField('Old password', validators=[DataRequired()])
    password = PasswordField('New password', validators=[
                             DataRequired(), equal_to('password2', message='Passwords must match')])
    password2 = PasswordField('Confirm new password',
                              validators=[DataRequired()])
    submit = SubmitField('Submit')
Пример #11
0
class registerform(Form):
    name = StringField('Name', [
        validators.data_required(),
        validators.Length(
            min=4, max=50, message="ReEnter Name Between 4 and 50 characters")
    ])
    username = StringField('Username', [
        validators.data_required(),
        validators.Length(
            min=5,
            max=30,
            message="ReEnter username Between 4 and 30 characters")
    ])
    email = StringField('Email', [
        validators.data_required(),
        validators.email(message="Enter a valid email"),
        validators.Length(
            min=4, max=50, message="ReEnter Email Between 4 and 50 characters")
    ])
    password = PasswordField('Password', [
        validators.data_required(),
        validators.Length(
            min=6,
            max=15,
            message="ReEnter Password Between 6 and 15 characters"),
        validators.equal_to('confirm_password',
                            message="Passwors do not match")
    ])
    confirm_password = PasswordField('Confirm Password', [
        validators.data_required(),
        validators.Length(
            min=5,
            max=15,
            message="ReEnter Password Between 4 and 50 characters")
    ])
Пример #12
0
class RegistrationForm(FlaskForm):
    username = StringField('Username', validators=[InputRequired()])
    email = EmailField('Email', validators=[Email()])
    password = PasswordField('Password',
                             validators=[
                                 InputRequired(),
                                 equal_to('confirm_password',
                                          'Passwords must match')
                             ])
    confirm_password = PasswordField('Confirm Password',
                                     validators=[InputRequired()])

    def validate(self):
        valid = True
        if not super().validate():
            valid = False
        if not self.username.errors:
            if Account.query.filter_by(
                    username=self.username.data).first() is not None:
                self.username.errors.append('Username taken')
                valid = False
        if not self.email.errors:
            if Account.query.filter_by(
                    email=self.email.data).first() is not None:
                self.email.errors.append('Email taken')
                valid = False
        return valid
Пример #13
0
class changepasswordForm(Form):
    password = PasswordField(PASSWORD,
                             [validators.length(min=5),
                              validators.required()])
    passwordconfirm = PasswordField(PWDCONFIRM,
                                    [validators.equal_to(PASSWORD)])

    def __init__(self, *args, **kwargs):
        self.user = args[1]
        Form.__init__(self, args[0], **kwargs)

    def validate(self):
        rv = Form.validate(self)
        if not rv:
            message = ''
            for fieldName, errorMessages in self.errors.items():
                for err in errorMessages:
                    message = message + fieldName + ': ' + err + '\n'
            flash(message, 'error')
            return False
        else:
            savvy_collection.update({EMAIL: self.user[EMAIL]}, {
                "$set": {
                    PASSWORD:
                    md5(self.password.data.rstrip().encode(
                        'utf-8')).hexdigest()
                }
            })
            return True
Пример #14
0
class SignUpForm(FlaskForm):
    first_name = StringField(
        'First Name:',
        validators=[input_required('This field is required.'),
                    length(3, 127)])
    last_name = StringField(
        'Last Name:',
        validators=[input_required('This field is required'),
                    length(3, 127)])

    password = PasswordField(
        'Password:'******'This field is required.'),
                    length(7, 127)])
    password_confirm = PasswordField(
        'Repeat Password:'******'This field is required.'),
            equal_to('password', 'Your passwords should probably be the same'),
            length(7, 127)
        ])

    email = EmailField(
        'Email:',
        validators=[input_required('This field is required.'),
                    length(7, 127)])
    email_confirm = BooleanField(
        'Sign me up for an occasional email about current and future plans',
        default=True)

    submit = SubmitField("Sign Up")
Пример #15
0
class RegistrationForm(Form):
    user = StringField('Username', [
        validators.Length(
            min=5,
            max=20,
            message=
            "Your username must be anywhere from 5 to 20 characters in length")
    ])
    password = PasswordField('Password', [
        validators.DataRequired(),
        validators.equal_to('confirmPassword',
                            message="Passwords do not match, try again")
    ])
    confirmPassword = PasswordField('Confirm Password')
    fullName = StringField('Full Name', [validators.Length(min=0, max=50)])
    email = StringField(
        'Email', [validators.Email(message="Must enter a vaild email.")])
    bio = StringField('Bio', [
        validators.Length(
            min=0,
            max=250,
            message=
            "Keep your bio short and sweet! No more than 250 characters.")
    ])
    favoriteLanguages = StringField('Favorite Languages', [
        validators.Length(
            min=0,
            max=250,
            message=
            "Keep your languages short and sweet! No more than 250 characters."
        )
    ])
Пример #16
0
class ResgiterForm(FlaskForm):
    name=StringField('name',
                     validators=[
                                validators.DataRequired("Enter name"),
                                validators.length(min=2,max=12,message="Enter %(min)d-%(max)d characters"),
                                validators.Regexp(r'([a-zA-Z\u4e00-\u9fa5])([a-zA-Z0-9\u4e00-\u9fa5]+$)',message=\
                                                 'only contains chinese,english,and not starts with number')],
                     render_kw={'placeholder': 'name,not start with number'}
                     )
    email = StringField('email',
                        validators=[
                            validators.email("Enter your email"),
                            validators.DataRequired("Enter your email")
                        ],
                        render_kw={'placeholder': 'email'})
    passwd = PasswordField('passwd',
                           validators=[
                               validators.DataRequired("Enter your passwords"),
                               validators.length(
                                   min=6,
                                   max=12,
                                   message="Enter %(min)d-%(max)d characters")
                           ],
                           render_kw={'placeholder': '6-12 charaters'})
    passwd2 = PasswordField(
        'repeatpasswd',
        validators=[validators.equal_to('passwd', "password must match")],
        render_kw={'placeholder': 'repeat passwords'})

    Captcha = IntegerField(
        'Captcha',
        validators=[validators.DataRequired("Enter Verfication")],
        render_kw={'placeholder': 'please input 6 numbers in your email'})

    submit = SubmitField('Register')
Пример #17
0
class RegisterInfoForm(Form):
    phone = StringField('Phone',
                        validators=[
                            validators.DataRequired('请输入手机号'),
                            validators.length(11, 11, '手机号不正确')
                        ])
    user_name = StringField('用户名',
                            validators=[
                                validators.DataRequired('请输入用户名'),
                                validators.length(1, 64)
                            ])
    password = StringField('密码', validators=[validators.DataRequired('请输入密码')])
    repassword = StringField('密码',
                             validators=[
                                 validators.DataRequired('请输入密码'),
                                 validators.equal_to('password', '两次输入密码不一致')
                             ])
    email = StringField('邮箱',
                        validators=[
                            validators.DataRequired('请输入邮箱'),
                            validators.email("邮箱格式不正确")
                        ])
    province_id = IntegerField('省',
                               validators=[validators.DataRequired('请选择省')])
    city_id = IntegerField('市', validators=[validators.DataRequired('请选择市')])
    area_id = IntegerField('县/区',
                           validators=[validators.DataRequired('请选择县/区')])
    school_id = IntegerField('学校',
                             validators=[validators.DataRequired('请选择学校')])
    grade_id = IntegerField('年级',
                            validators=[validators.DataRequired('请选择年级')])
Пример #18
0
class SignupForm(FlaskForm):
    email = StringField('Email',
                        validators=[validators.email(),
                                    DataRequired()])
    password = PasswordField('Password',
                             validators=[
                                 DataRequired(),
                                 validators.length(min=4),
                                 validators.equal_to(
                                     'confirm', message="Passwords must match")
                             ])
    confirm = PasswordField('Confirm Password', validators=[DataRequired()])
    store_name = StringField(
        'Store Name', validators=[DataRequired(),
                                  validators.length(min=4)])

    def validate(self):
        check_validate = super(SignupForm, self).validate()
        if not check_validate:
            return False

        user_count = User.query.filter_by(email=self.email.data).count()
        if user_count > 0:
            self.email.errors.append('That email already has an account')
            return False
        return True
Пример #19
0
class register_form(Form):
    username = StringField(label='Username',
                           validators=[validators.InputRequired()])
    password = PasswordField(label='Password',
                             validators=[
                                 validators.InputRequired(),
                                 validators.equal_to(
                                     'confirm', message='Passwords must match')
                             ])
    confirm = PasswordField(label='Confirm Password',
                            validators=[validators.InputRequired()])
    email = html5.EmailField(label='Email')
    notify = BooleanField(label='Email notifications')

    def validate(self):
        if not Form.validate(self):
            return False

        if self.notify.data and not self.email.data:
            self.notify.errors.append(
                'Cannot send notifications without a valid email address')
            return False

        if db.session.query(User).filter_by(
                username=self.username.data).count() > 0:
            self.username.errors.append('User already exists')
            return False

        return True
Пример #20
0
class RegistrationForm(FlaskForm):
    username = wtforms.StringField(
        label="Usuario",
        validators=[
            validators.DataRequired(),
            validators.Length(min=4, max=25)
        ],
    )

    first_name = wtforms.StringField(label="Nombre")

    last_name = wtforms.StringField(label="Apellido")

    email = wtforms.StringField(
        label="correo electronico",
        validators=[validators.email("Email no valido")])

    password1 = wtforms.PasswordField(
        label="Contraseña",
        validators=[
            validators.DataRequired(),
            validators.equal_to("password2", "Las contraseñas no coinciden"),
        ],
    )

    password2 = wtforms.PasswordField(label="Contraseña (confirmacion)",
                                      validators=[validators.DataRequired()])
Пример #21
0
class SignupForm(FlaskForm):
    name = StringField(
        "Adınız",
        validators=[
            validators.input_required(message="İsminizi giriniz.."),
            validators.length(min=4, max=20)
        ])
    username = StringField(
        "Kullanıcı Adı",
        validators=[
            validators.input_required(
                message="Lütfen geçerli bir kullanıcı adı giriniz.."),
            validators.length(min=4, max=20)
        ])
    email = StringField(
        "E-posta Adresi",
        validators=[
            validators.Email(
                message="Uygun formatta bir e-posta adresi giriniz..")
        ])
    password = PasswordField("Şifre",
                             validators=[
                                 validators.input_required(),
                                 validators.equal_to(
                                     fieldname="confirm",
                                     message="Şifre uyuşmuyor.."),
                                 validators.length(min=4, max=20)
                             ])
    confirm = PasswordField("Şifreyi Doğrula")
Пример #22
0
class RegisterForm(Form):
    name = StringField(
        "Ad Soyad",
        validators=[
            validators.Length(
                min=4,
                max=25,
                message="Minimum 4, Maksimum 25 Karakterr Uzunluğunda Olmalıdır"
            )
        ])
    username = StringField(
        "Kullanıcı Adı",
        validators=[
            validators.Length(
                min=5,
                max=35,
                message="Minimum 5, Maksimum 25 Karakterr Uzunluğunda Olmalıdır"
            )
        ])
    email = StringField(
        "E-Mail Adresi",
        validators=[
            validators.Email(message="Lütfen Geçerli Bir E-Mail Adresi Girin")
        ])
    password = PasswordField("Parola:",
                             validators=[
                                 validators.DataRequired(),
                                 validators.equal_to(
                                     fieldname="confirm",
                                     message="Parolanız Uyuşmuyor")
                             ])
    confirm = PasswordField("Parola Doğrula")
Пример #23
0
class RegisterForm(Form):
    username = StringField('Username', [validators.DataRequired(message="请输入用户名"), validators.Length(min=5, max=15, message="用户名长度不符合要求,请输入5-15位用户名"), usernameCheck])
    password = PasswordField('Password', [validators.DataRequired(message="请输入密码"), validators.Length(min=5, max=15, message="密码长度不符合要求, 请输入5-15位密码")])
    confirm = PasswordField('Confirm', [validators.DataRequired(message="请再次输入密码"), validators.equal_to('password', message='两次密码不匹配')])

    def __repr__(self):
        return "Username:"******", Password: "******", Confirm: " + self.confirm.data
Пример #24
0
class RegistrationForm(FlaskForm):
    username = StringField('Username',
                           validators=[DataRequired(),
                                       length(min=2, max=20)])
    email = StringField('Email', validators=[DataRequired(), email()])
    password = PasswordField('Password', validators=[DataRequired()])
    password_confirm = PasswordField(
        'Confirm Password', validators=[DataRequired(),
                                        equal_to('password')])

    submit = SubmitField('Sign Up')
    '''
    def validate_field(self, field):
        if True:
            raise  ValidationError('Validation Message')
    '''
    def validate_username(self, username):
        user = User.query.filter_by(username=username.data).first()
        if user:
            raise ValidationError(
                'This Username is already taken. Please choose another one.')

    def validate_email(self, email):
        user = User.query.filter_by(email=email.data).first()
        if user:
            raise ValidationError(
                'This Email ID is already in use. Please choose another one or try logging in.'
            )
Пример #25
0
class RegisterForm(Form):
    name = StringField('Name',
                       validators=[
                           validators.input_required(),
                           validators.length(min=3, max=30)
                       ])
    email = StringField('Email',
                        validators=[
                            validators.input_required(),
                            validators.length(min=5, max=50)
                        ])
    username = StringField('Username',
                           validators=[
                               validators.input_required(),
                               validators.length(min=5, max=20)
                           ])
    password = PasswordField('Password',
                             validators=[
                                 validators.input_required(),
                                 validators.equal_to(
                                     'confirmPassword',
                                     message='password does not match')
                             ])
    confirmPassword = PasswordField('Confrim Password',
                                    validators=[validators.input_required()])
Пример #26
0
class RegistrationForm(FlaskForm):
    username = StringField(
        'Username',
        [validators.data_required(),
         validators.length(min=2, max=15)])
    name = StringField('Name', [validators.data_required()])
    email = StringField('Email',
                        [validators.data_required(),
                         validators.email()])
    age = IntegerField('Age (in years)',
                       [validators.NumberRange(min=1, max=100)])
    gender = SelectField('Gender',
                         choices=[('Male', 'Male'), ('Female', 'Female')])
    password = PasswordField(
        'Password',
        [validators.data_required(),
         validators.length(min=6, max=20)])
    confirm_password = PasswordField(
        'Confirm Password',
        [validators.data_required(),
         validators.equal_to('password')])
    submit = SubmitField('Sign Up')

    def validate_username(self, username):
        user = Users.query.filter_by(username=username.data).first()
        if user:
            raise ValidationError('Sorry, that username is already taken')

    def validate_email(self, email):
        user = Users.query.filter_by(email=email.data).first()
        if user:
            raise ValidationError('Sorry, that email is already taken')
Пример #27
0
class PaymentForm(FlaskForm):
    creditCardNumber = StringField(
        label=('Enter Credit Card Number:'),
        validators=[
            DataRequired("Invalid Credit Card Number."),
            validate_creditCardNumber,
            validators.Regexp('^[0-9]*$',
                              message="Card must contain only numbers")
        ])
    confirm_creditCardNumber = StringField(
        'Confirm Credit Card Number',
        validators=[DataRequired(),
                    equal_to('creditCardNumber')])
    cardHolder = StringField(
        'Card Holder', validators=[DataRequired(),
                                   Length(min=2, max=100)])
    expirationDate = DateField('Expiration Date (YYYY-MM-DD)',
                               format='%Y-%m-%d',
                               validators=[
                                   DataRequired("Invalid Date Field"),
                                   DateRange(min=datetime.date.today())
                               ])
    securityCode = IntegerField('Security Code',
                                validators=[
                                    DataRequired("Invalid Security Code"),
                                    validators.NumberRange(min=100, max=999)
                                ])
    amount = FloatField('Amount', validators=[DataRequired("Invalid Amount")])

    submit = SubmitField('Pay')
Пример #28
0
class SignInForm(FlaskForm):
    Username = StringField(
        'Username',
        validators=[
            InputRequired(),
            Length(4, 64),
            regexp(
                '^[A-Za-z][A-Za-z0-9_.]*$', 0,
                'Usernames must start with a letter and must have only letters, numbers, '
                'dots or underscores')
        ])
    First_Name = StringField('First Name', validators=[InputRequired()])
    Last_Name = StringField('Last Name', validators=[InputRequired()])
    Email = EmailField('Email', validators=[InputRequired(), Email()])
    Password = PasswordField('Password',
                             validators=[InputRequired(),
                                         Length(8)])
    Password2 = PasswordField('Repeat Password',
                              validators=[
                                  InputRequired(),
                                  equal_to('Password',
                                           message='Passwords must match.')
                              ])
    submit = SubmitField('Sign Up')

    def validate_password(self, field):
        with open('static/commonpassowrds.txt') as f:
            for line in f.readlines():
                if field.data == line.strip():
                    raise ValueError('Your password is too common.')
class ProfileForm(Form):
    user = StringField(u'user',
                       validators=[
                           validators.input_required(messages.required),
                           my_validators.user_exists(new_user=False)
                       ])
    email = StringField(u'email',
                        validators=[
                            validators.input_required(messages.required),
                            my_validators.mail_exists(new_user=False)
                        ])
    password = StringField(u'password',
                           validators=[
                               validators.equal_to(
                                   'confirm_password',
                                   message='Passwords deben ser iguales')
                           ])
    confirm_password = StringField(u'confirm_password')
    periodicity = SelectField(
        u'periodicity',
        choices=[(Periodicidad.diaria.value, Periodicidad.diaria.value),
                 (Periodicidad.semanal.value, Periodicidad.semanal.value),
                 (Periodicidad.mensual.value, Periodicidad.mensual.value)])

    def set_values(self, user):
        self.user.data = user.user
        self.email.data = user.email
        self.periodicity.data = user.perfil.periodicidad
Пример #30
0
class RegistrationForm(FlaskForm):
    username = StringField('Username',
                           validators=[
                               validators.input_required(),
                           ])
    email = StringField('Email',
                        validators=[
                            validators.input_required(),
                            validators.email(),
                        ])
    password = PasswordField('Password',
                             validators=[
                                 validators.input_required(),
                                 validators.length(min=8, max=30)
                             ])
    password2 = PasswordField('Repeat Password',
                              validators=[
                                  validators.input_required(),
                                  validators.equal_to('password'),
                              ])

    submit = SubmitField('Register')

    def validate_username(self, username):
        user = User.query.filter_by(username=username.data).first()
        if user is not None:
            raise ValidationError('This username is already in use.')

    def validate_email(self, email):
        user = User.query.filter_by(email=email.data).first()
        if user is not None:
            raise ValidationError('This email is already in use.')
Пример #31
0
    def scaffold_form(self):

        # Start with the standard form as provided by Flask-Admin. We've already told Flask-Admin to exclude the
        # password field from this form.

        form_class = super(UserModelView, self).scaffold_form()

        # Add a password field, naming it "password2" and labeling it "New Password".
        form_class.password = PasswordField('Change Password',
                             [validators.Optional(),
                              validators.equal_to('confirm_password')])
        form_class.confirm_password = PasswordField()
        form_class.active = BooleanField(default=True)

        return form_class
Пример #32
0
    def test_lazy_proxy(self):
        """Tests that the validators support lazy translation strings for messages."""

        class ReallyLazyProxy(object):
            def __unicode__(self):
                raise Exception('Translator function called during form declaration: it should be called at response time.')
            __str__ = __unicode__

        message = ReallyLazyProxy()
        self.assertRaises(Exception, str, message)
        self.assertRaises(Exception, text_type, message)
        self.assertTrue(equal_to('fieldname', message=message))
        self.assertTrue(length(min=1, message=message))
        self.assertTrue(NumberRange(1, 5, message=message))
        self.assertTrue(required(message=message))
        self.assertTrue(regexp('.+', message=message))
        self.assertTrue(email(message=message))
        self.assertTrue(ip_address(message=message))
        self.assertTrue(url(message=message))
Пример #33
0
 def test_equal_to(self):
     self.form['foo'] = DummyField('test')
     self.assertEqual(equal_to('foo')(self.form, self.form['foo']), None)
     self.assertRaises(ValidationError, equal_to('invalid_field_name'), self.form, DummyField('test'))
     self.assertRaises(ValidationError, equal_to('foo'), self.form, DummyField('different_value'))
Пример #34
0
 def test_equal_to(self):
     self.form["foo"] = DummyField("test")
     self.assertEqual(equal_to("foo")(self.form, self.form["foo"]), None)
     self.assertRaises(ValidationError, equal_to("invalid_field_name"), self.form, DummyField("test"))
     self.assertRaises(ValidationError, equal_to("foo"), self.form, DummyField("different_value"))
Пример #35
0
 def EqualTo(cls,fieldname, message=None):
     ''' Compares the values of two fields. '''
     return validators.equal_to(fieldname, message)