Пример #1
0
class VenueForm(Form):
    name = StringField('name', validators=[DataRequired()])
    city = StringField('city', validators=[DataRequired()])
    state = SelectField('state',
                        validators=[DataRequired()],
                        choices=[
                            ('AL', 'AL'),
                            ('AK', 'AK'),
                            ('AZ', 'AZ'),
                            ('AR', 'AR'),
                            ('CA', 'CA'),
                            ('CO', 'CO'),
                            ('CT', 'CT'),
                            ('DE', 'DE'),
                            ('DC', 'DC'),
                            ('FL', 'FL'),
                            ('GA', 'GA'),
                            ('HI', 'HI'),
                            ('ID', 'ID'),
                            ('IL', 'IL'),
                            ('IN', 'IN'),
                            ('IA', 'IA'),
                            ('KS', 'KS'),
                            ('KY', 'KY'),
                            ('LA', 'LA'),
                            ('ME', 'ME'),
                            ('MT', 'MT'),
                            ('NE', 'NE'),
                            ('NV', 'NV'),
                            ('NH', 'NH'),
                            ('NJ', 'NJ'),
                            ('NM', 'NM'),
                            ('NY', 'NY'),
                            ('NC', 'NC'),
                            ('ND', 'ND'),
                            ('OH', 'OH'),
                            ('OK', 'OK'),
                            ('OR', 'OR'),
                            ('MD', 'MD'),
                            ('MA', 'MA'),
                            ('MI', 'MI'),
                            ('MN', 'MN'),
                            ('MS', 'MS'),
                            ('MO', 'MO'),
                            ('PA', 'PA'),
                            ('RI', 'RI'),
                            ('SC', 'SC'),
                            ('SD', 'SD'),
                            ('TN', 'TN'),
                            ('TX', 'TX'),
                            ('UT', 'UT'),
                            ('VT', 'VT'),
                            ('VA', 'VA'),
                            ('WA', 'WA'),
                            ('WV', 'WV'),
                            ('WI', 'WI'),
                            ('WY', 'WY'),
                        ])
    address = StringField('address', validators=[DataRequired()])
    phone = StringField('phone',
                        validators=[DataRequired(),
                                    Regexp(r'^[0-9\-\+]+$')])
    image_link = StringField('image_link')
    genres = SelectMultipleField('genres',
                                 validators=[DataRequired()],
                                 choices=[
                                     ('Alternative', 'Alternative'),
                                     ('Blues', 'Blues'),
                                     ('Classical', 'Classical'),
                                     ('Country', 'Country'),
                                     ('Electronic', 'Electronic'),
                                     ('Folk', 'Folk'),
                                     ('Funk', 'Funk'),
                                     ('Hip-Hop', 'Hip-Hop'),
                                     ('Heavy Metal', 'Heavy Metal'),
                                     ('Instrumental', 'Instrumental'),
                                     ('Jazz', 'Jazz'),
                                     ('Musical Theatre', 'Musical Theatre'),
                                     ('Pop', 'Pop'),
                                     ('Punk', 'Punk'),
                                     ('R&B', 'R&B'),
                                     ('Reggae', 'Reggae'),
                                     ('Rock n Roll', 'Rock n Roll'),
                                     ('Soul', 'Soul'),
                                     ('Other', 'Other'),
                                 ])
    facebook_link = StringField('facebook_link', validators=[URL()])
    website = StringField('website', validators=[URL()])
    seeking_talent = SelectField('seeking_talent',
                                 validators=[DataRequired()],
                                 choices=[(True, True), (False, False)])
    seeking_description = StringField('seeking_description')
Пример #2
0
class UserdetailForm(FlaskForm):
    name = StringField(
        label="昵称",
        validators=[
            DataRequired("请输入昵称!")
        ],
        description="昵称",
        render_kw={
            "class":"form-control",
            "placeholder":"请输入昵称!",
        }
    )

    email = StringField(
        label="邮箱",
        validators=[
            DataRequired("请输入邮箱!"),
            Email("邮箱格式不正确!")
        ],
        description="邮箱",
        render_kw={
            "class": "form-control",
            "placeholder": "请输入邮箱!",
        }
    )

    phone = StringField(
        label="手机",
        validators=[
            DataRequired("请输入手机!"),
            Regexp("1[3458]\d{9}", message="手机格式不正确!")
        ],
        description="手机",
        render_kw={
            "class": "form-control",
            "placeholder": "请输入手机号码!",
        }
    )

    face = FileField(
        label="头像",
        validators=[
            DataRequired("请上传头像!")
        ],
        description="头像",
    )

    info = TextAreaField(
        label="简介",
        validators=[
            DataRequired("请输入简介!"),
        ],
        description="简介",
        render_kw={
            "class":"form-control",
            "rows":10,
        }
    )

    submit = SubmitField(
        label='保存修改',
        render_kw={
            "class": "btn btn-success",
        },
    )
Пример #3
0
        return True


def upload_recaptcha_validator_shim(form, field):
    ''' Selectively does a recaptcha validation '''
    if app.config['USE_RECAPTCHA']:
        # Recaptcha anonymous and new users
        if not flask.g.user or flask.g.user.age < app.config['ACCOUNT_RECAPTCHA_AGE']:
            return RecaptchaValidator()(form, field)
    else:
        # Always pass validating the recaptcha field if disabled
        return True


_username_validator = Regexp(
    r'^[a-zA-Z0-9_\-]+$',
    message='Your username must only consist of alphanumerics and _- (a-zA-Z0-9_-)')


class LoginForm(FlaskForm):
    username = StringField('Username or email address', [DataRequired()])
    password = PasswordField('Password', [DataRequired()])


class PasswordResetRequestForm(FlaskForm):
    email = StringField('Email address', [
        Email(),
        DataRequired(),
        Length(min=5, max=128)
    ])
Пример #4
0
class Verify_login(Form):  #前台用户账号密码登录验证
    mobile = StringField(
        validators=[Regexp(r'^1(3|4|5|7|8)\d{9}$', message='手机号码输入错误')])
    password = StringField(validators=[Regexp(r'\w{6,16}', message='密码输入不正确')])
Пример #5
0
class RegisterForm(FlaskForm):
    """会员注册表单"""
    name = StringField(
        label="昵称",
        validators=[DataRequired("请输入昵称")],
        description="昵称",
        render_kw={
            "class": "form-control",
            "placeholder": "请输入昵称!",
            # "required": 'required'
        })
    email = StringField(
        label="邮箱",
        validators=[DataRequired("请输入邮箱"),
                    Email("邮箱格式不正确")],
        description="邮箱",
        render_kw={
            "class": "form-control",
            "placeholder": "请输入邮箱!",
            # "required": 'required'
        })
    phone = StringField(label="手机",
                        validators=[
                            DataRequired("请输入手机号"),
                            Regexp("1[3458]\d{9}", message="手机格式不正确")
                        ],
                        description="手机",
                        render_kw={
                            "class": "form-control",
                            "placeholder": "请输入手机号!"
                        })
    pwd = PasswordField(label="密码",
                        validators=[DataRequired("请输入密码")],
                        description="密码",
                        render_kw={
                            "class": "form-control",
                            "placeholder": "请输入密码!"
                        })
    repwd = PasswordField(
        label="请再次输入密码",
        validators=[DataRequired("请再次输入密码"),
                    EqualTo('pwd', '两次输入密码不一致')],
        description="密码",
        render_kw={
            "class": "form-control",
            "placeholder": "请再次输入密码!"
        })
    submit = SubmitField(
        '注册', render_kw={"class": "btn btn-primary btn-block btn-flat"})

    def validate_name(self, field):
        name = field.data
        user = User.query.filter_by(name=name).count()
        if user == 1:
            raise ValidationError("昵称已存在")

    def validate_email(self, field):
        email = field.data
        user = User.query.filter_by(email=email).count()
        if user == 1:
            raise ValidationError("邮箱已存在")

    def validate_phone(self, field):
        phone = field.data
        user = User.query.filter_by(phone=phone).count()
        if user == 1:
            raise ValidationError("手机号已存在")
class SigninForm(BaseForm):
    telephone = StringField(
        validators=[Regexp(r"1[345789]\d{9}", message='请输入正确格式的手机号码!')])
    password = StringField(
        validators=[Regexp(r"[0-9a-zA-Z_\.]{6,20}", message='请输入正确格式的密码!')])
    remeber = StringField()
Пример #7
0
class AddressForm(FlaskForm):
    address_name = StringField(
        'address_name',
        [DataRequired(),
         Regexp(r'^[a-zA-Z\s0-9]*$'),
         Length(min=4, max=25)])
Пример #8
0
class ArtistForm(Form):
    name = StringField('name', validators=[DataRequired()])
    city = StringField('city', validators=[DataRequired()])
    state = SelectField('state',
                        validators=[DataRequired()],
                        choices=[
                            ('AL', 'AL'),
                            ('AK', 'AK'),
                            ('AZ', 'AZ'),
                            ('AR', 'AR'),
                            ('CA', 'CA'),
                            ('CO', 'CO'),
                            ('CT', 'CT'),
                            ('DE', 'DE'),
                            ('DC', 'DC'),
                            ('FL', 'FL'),
                            ('GA', 'GA'),
                            ('HI', 'HI'),
                            ('ID', 'ID'),
                            ('IL', 'IL'),
                            ('IN', 'IN'),
                            ('IA', 'IA'),
                            ('KS', 'KS'),
                            ('KY', 'KY'),
                            ('LA', 'LA'),
                            ('ME', 'ME'),
                            ('MT', 'MT'),
                            ('NE', 'NE'),
                            ('NV', 'NV'),
                            ('NH', 'NH'),
                            ('NJ', 'NJ'),
                            ('NM', 'NM'),
                            ('NY', 'NY'),
                            ('NC', 'NC'),
                            ('ND', 'ND'),
                            ('OH', 'OH'),
                            ('OK', 'OK'),
                            ('OR', 'OR'),
                            ('MD', 'MD'),
                            ('MA', 'MA'),
                            ('MI', 'MI'),
                            ('MN', 'MN'),
                            ('MS', 'MS'),
                            ('MO', 'MO'),
                            ('PA', 'PA'),
                            ('RI', 'RI'),
                            ('SC', 'SC'),
                            ('SD', 'SD'),
                            ('TN', 'TN'),
                            ('TX', 'TX'),
                            ('UT', 'UT'),
                            ('VT', 'VT'),
                            ('VA', 'VA'),
                            ('WA', 'WA'),
                            ('WV', 'WV'),
                            ('WI', 'WI'),
                            ('WY', 'WY'),
                        ])
    phone = StringField(
        # TODO implement validation logic for state
        'phone',
        validators=[
            Regexp(r'^[0-9\-\+]+$', 0, message='The phone must be valid')
        ])
    image_link = StringField('image_link', validators=[URL()])
    genres = SelectMultipleField(
        # TODO implement enum restriction
        'genres',
        validators=[DataRequired()],
        choices=[
            ('Alternative', 'Alternative'),
            ('Blues', 'Blues'),
            ('Classical', 'Classical'),
            ('Country', 'Country'),
            ('Electronic', 'Electronic'),
            ('Folk', 'Folk'),
            ('Funk', 'Funk'),
            ('Hip-Hop', 'Hip-Hop'),
            ('Heavy Metal', 'Heavy Metal'),
            ('Instrumental', 'Instrumental'),
            ('Jazz', 'Jazz'),
            ('Musical Theatre', 'Musical Theatre'),
            ('Pop', 'Pop'),
            ('Punk', 'Punk'),
            ('R&B', 'R&B'),
            ('Reggae', 'Reggae'),
            ('Rock n Roll', 'Rock n Roll'),
            ('Soul', 'Soul'),
            ('Other', 'Other'),
        ])
    facebook_link = StringField(
        # TODO implement enum restriction
        'facebook_link',
        validators=[URL()])
Пример #9
0
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField
from wtforms.validators import DataRequired, Length, EqualTo, Email, Regexp
from wtforms.validators import ValidationError

# Validators
# EqualTo is passed as a function so we can pass parameters to it.
_veq = EqualTo
_vreq = DataRequired()
_vml32 = Length(max=32)
_vml64 = Length(max=64)
_vml128 = Length(max=128)
_vml256 = Length(max=256)
_vemail = Email()
_valnum = Regexp('^[a-zA-Z0-9_-]*$',
                 message="This field only allows \
                 alphanumeric characters, along with '-' and '_'.")


class RegistrationForm(FlaskForm):
    username = StringField('Username', validators=[_vreq, _vml32, _valnum])
    email = StringField('Email', validators=[_vreq, _vml256, _vemail])
    password = PasswordField('Password', validators=[_vreq, _vml128])
    password2 = PasswordField('Confirm',
                              validators=[_vreq, _vml128,
                                          _veq('password')])
    submit = SubmitField('Register')

    def validate_username(self, username):
        # Check the username is unique
        user = User.query.filter_by(username=username.data).first()
Пример #10
0
class RegistForm(FlaskForm):
    name = StringField(
        label="昵称",
        validators=[DataRequired("请输入昵称!")],
        description="昵称",
        render_kw={
            "class": "form-control input-lg",
            "placeholder": "请输入昵称!",
            # "required": "required"
        })
    pwd = PasswordField(label="密码",
                        validators=[DataRequired("请输入密码!")],
                        description="密码",
                        render_kw={
                            "class": "form-control input-lg",
                            "placeholder": "请输入密码!",
                        })
    repwd = PasswordField(label="确认密码",
                          validators=[
                              DataRequired("请输入确认密码!"),
                              EqualTo('pwd', message="两次密码不一致!")
                          ],
                          description="确认密码",
                          render_kw={
                              "class": "form-control input-lg",
                              "placeholder": "请输入确认密码!",
                          })
    email = StringField(
        label="邮箱",
        validators=[DataRequired("请输入邮箱!"),
                    Email("邮箱格式不正确!")],
        description="邮箱",
        render_kw={
            "class": "form-control input-lg",
            "placeholder": "请输入邮箱!",
            # "required": "required"
        })
    phone = StringField(label="手机",
                        validators=[
                            DataRequired("请输入手机!"),
                            Regexp("1[3458]\\d{9}", message="手机格式不正确!")
                        ],
                        description="手机",
                        render_kw={
                            "class": "form-control input-lg",
                            "placeholder": "请输入手机!",
                        })
    submit = SubmitField('注册',
                         render_kw={
                             "class": "btn btn-lg btn-success btn-block",
                         })

    def validate_name(self, field):
        name = field.data
        user = User.query.filter_by(name=name).count()
        if user == 1:
            raise ValidationError("昵称已经存在!")

    def validate_email(self, field):
        email = field.data
        user = User.query.filter_by(email=email).count()
        if user == 1:
            raise ValidationError("邮箱已经存在!")

    def validate_phone(self, field):
        phone = field.data
        user = User.query.filter_by(phone=phone).count()
        if user == 1:
            raise ValidationError("手机号码已经存在!")
Пример #11
0
class AddPersonnel(FlaskForm):
    picture = FileField(
        "Profile Picture",
        validators=[
            FileAllowed(
                ["jpg", "png"],
                message=
                "The file you selected had an unsupported extension. Please upload a JPG or PNG file instead."
            )
        ])
    first_name = StringField(
        "First name",
        validators=[
            DataRequired(),
            Length(
                min=2,
                max=50,
                message="This field must be between 2 and 50 characters long.")
        ])
    middle_name = StringField(
        "Middle name",
        validators=[
            Optional(),
            Length(
                min=1,
                max=100,
                message="This field must be between 1 and 100 characters long."
            )
        ])
    last_name = StringField(
        "Last name",
        validators=[
            DataRequired(),
            Length(
                min=2,
                max=50,
                message="This field must be between 2 and 50 characters long.")
        ])
    sex = RadioField("Gender",
                     choices=[('Woman', 'Woman'), ('Man', 'Man'),
                              ('Other', 'Other')],
                     default="Other",
                     validators=[Optional()])
    birthday = DateField("Birthday",
                         format='%Y-%m-%d',
                         validators=[Optional()])
    phone = StringField(
        "Phone",
        validators=[
            Optional(),
            Regexp("^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*$",
                   message="Phone format must be similar to +(123)-456-78-90")
        ])
    occupation = TextAreaField("Your current occupation at the laboratory:",
                               validators=[Optional()])
    institution = StringField(
        "The institution you belong to:",
        validators=[
            DataRequired(),
            Length(
                min=3,
                max=100,
                message="This field must be between 3 and 100 characters long."
            )
        ])

    submit = SubmitField("Add personnel data")
Пример #12
0
class RegistrationForm(FlaskForm):
    personel_id = StringField('Personel ID',
                              validators=[
                                  DataRequired(),
                                  Regexp(r'^\d+$', 0,
                                         'This should be 10 digits')
                              ])
    first_name = StringField('First Name',
                             validators=[
                                 DataRequired(),
                                 Length(1, 64),
                                 Regexp(r'^[A-za-z]+$', 0,
                                        'First Name must have only letters')
                             ])

    last_name = StringField('Last Name',
                            validators=[
                                DataRequired(),
                                Length(1, 64),
                                Regexp(r'^[A-za-z]+$', 0,
                                       'Last Name must have only letters')
                            ])
    national_id = StringField('National ID',
                              validators=[
                                  DataRequired(),
                                  Regexp(r'^\d{10}$', 0,
                                         'This should be 10 digits')
                              ])
    phone_number = StringField('Phone Number',
                               validators=[
                                   DataRequired(),
                                   Length(1, 20),
                                   Regexp('^\d+$', 0,
                                          'Phone Number should be numbers')
                               ])
    address = StringField('Address', validators=[DataRequired()])
    age = StringField('Age',
                      validators=[
                          DataRequired(),
                          Regexp(r'^\d{1,3}$', 0, 'Age should be valid number')
                      ])
    income = StringField(
        'Income',
        validators=[DataRequired(),
                    Regexp('^\d+$', 0, 'Should be a number')])
    married = BooleanField('Married')
    gender = RadioField('Gender',
                        choices=[('Male', 'Male'), ('Female', 'Female')])
    submit = SubmitField('Submit')

    def validate_national_id(self, field):
        emp = Employee.query.filter_by(national_id=field.data).first()
        if emp and emp.personel_id != self.personel_id.data:
            raise ValidationError('National ID is already registered.')

    def validate_personel_id(self, field):
        emp = Employee.query.filter_by(national_id=field.data).first()
        if emp and emp.personel_id != self.personel_id.data:
            raise ValidationError('Personel ID is already registered.')

    def validate_phone_number(self, field):
        emp = Employee.query.filter_by(phone_number=field.data).first()
        if emp and emp.personel_id != self.personel_id.data:
            raise ValidationError('Phone number is already registered.')
Пример #13
0
class RegistForm(FlaskForm):
    name = StringField(label="昵称",
                       validators=[DataRequired("请输入昵称")],
                       description="昵称",
                       render_kw={
                           "class": "form-control input-lg",
                           "placeholder": "昵称"
                       })

    email = StringField(
        label="邮箱",
        validators=[DataRequired("请输入邮箱"),
                    Email("请输入正确的邮箱格式")],
        description="昵称",
        render_kw={
            "class": "form-control input-lg",
            "placeholder": "邮箱"
        })

    phone = StringField(label="电话",
                        validators=[
                            DataRequired("请输入电话"),
                            Regexp(r"^1[35678]\d{9}$", message="手机格式输入不正确")
                        ],
                        description="电话",
                        render_kw={
                            "class": "form-control input-lg",
                            "placeholder": "电话",
                            "maxlength": 11
                        })

    pwd = PasswordField(label="密码:",
                        validators=[DataRequired("请输入密码")],
                        description="密码",
                        render_kw={
                            "class": "form-control  input-lg",
                            "placeholder": "请输入密码!",
                        })

    repwd = PasswordField(label="确认密码:",
                          validators=[
                              DataRequired("请输入确认密码"),
                              EqualTo('pwd', message="两次密码输入不一致!")
                          ],
                          description="确认密码",
                          render_kw={
                              "class": "form-control input-lg",
                              "placeholder": "请输入确认密码!",
                          })

    submit = SubmitField(
        label="注册", render_kw={"class": "btn btn-lg btn-success btn-block"})

    def validate_name(self, field):
        name = field.data
        user = User.query.filter_by(name=name).count()
        if user == 1:
            raise ValidationError("用户名已经存在!")

    def validate_email(self, field):
        email = field.data
        user = User.query.filter_by(email=email).count()
        if user == 1:
            raise ValidationError("用户邮箱已经存在!")

    def validate_phone(self, field):
        phone = field.data
        user = User.query.filter_by(phone=phone).count()
        if user == 1:
            raise ValidationError("用户电话已经存在!")
Пример #14
0
class RegisterForm(FlaskForm):
    """
    用户注册表单
    """
    username = StringField(label="账户 :",
                           validators=[
                               DataRequired("用户名不能为空!"),
                               Length(min=3, max=50, message="用户名长度必须在3到10位之间")
                           ],
                           description="用户名",
                           render_kw={
                               "type": "text",
                               "placeholder": "请输入用户名!",
                               "class": "validate-username",
                               "size": 38,
                           })
    phone = StringField(label="联系电话 :",
                        validators=[
                            DataRequired("手机号不能为空!"),
                            Regexp("1[34578][0-9]{9}", message="手机号码格式不正确")
                        ],
                        description="手机号",
                        render_kw={
                            "type": "text",
                            "placeholder": "请输入联系电话!",
                            "size": 38,
                        })
    email = StringField(
        label="邮箱 :",
        validators=[DataRequired("邮箱不能为空!"),
                    Email("邮箱格式不正确!")],
        description="邮箱",
        render_kw={
            "type": "email",
            "placeholder": "请输入邮箱!",
            "size": 38,
        })
    password = PasswordField(
        label="密码 :",
        validators=[
            DataRequired("密码不能为空!"),
            # 密码至少包含数字和英文,长度6 - 20
            Regexp("^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$",
                   message="密码格式不正确")
        ],
        description="密码",
        render_kw={
            "placeholder": "请输入密码!",
            "size": 38,
        })
    repassword = PasswordField(label="确认密码 :",
                               validators=[
                                   DataRequired("请输入确认密码!"),
                                   EqualTo('password', message="两次密码不一致!")
                               ],
                               description="确认密码",
                               render_kw={
                                   "placeholder": "请输入确认密码!",
                                   "size": 38,
                               })
    submit = SubmitField('同意协议并注册',
                         render_kw={
                             "class": "btn btn-primary login",
                         })

    def validate_email(self, field):
        """
        检测注册邮箱是否已经存在
        :param field: 字段名
        """
        email = field.data
        user = User.query.filter_by(email=email).count()
        if user == 1:
            raise ValidationError("邮箱已经存在!")

    def validate_phone(self, field):
        """
        检测手机号是否已经存在
        :param field: 字段名
        """
        phone = field.data
        user = User.query.filter_by(phone=phone).count()
        if user == 1:
            raise ValidationError("手机号已经存在!")
Пример #15
0
class ArtistForm(Form):
    name = StringField('name', validators=[DataRequired()])
    city = StringField('city', validators=[DataRequired()])
    state = SelectField('state',
                        validators=[DataRequired()],
                        choices=[
                            ('AL', 'AL'),
                            ('AK', 'AK'),
                            ('AZ', 'AZ'),
                            ('AR', 'AR'),
                            ('CA', 'CA'),
                            ('CO', 'CO'),
                            ('CT', 'CT'),
                            ('DE', 'DE'),
                            ('DC', 'DC'),
                            ('FL', 'FL'),
                            ('GA', 'GA'),
                            ('HI', 'HI'),
                            ('ID', 'ID'),
                            ('IL', 'IL'),
                            ('IN', 'IN'),
                            ('IA', 'IA'),
                            ('KS', 'KS'),
                            ('KY', 'KY'),
                            ('LA', 'LA'),
                            ('ME', 'ME'),
                            ('MT', 'MT'),
                            ('NE', 'NE'),
                            ('NV', 'NV'),
                            ('NH', 'NH'),
                            ('NJ', 'NJ'),
                            ('NM', 'NM'),
                            ('NY', 'NY'),
                            ('NC', 'NC'),
                            ('ND', 'ND'),
                            ('OH', 'OH'),
                            ('OK', 'OK'),
                            ('OR', 'OR'),
                            ('MD', 'MD'),
                            ('MA', 'MA'),
                            ('MI', 'MI'),
                            ('MN', 'MN'),
                            ('MS', 'MS'),
                            ('MO', 'MO'),
                            ('PA', 'PA'),
                            ('RI', 'RI'),
                            ('SC', 'SC'),
                            ('SD', 'SD'),
                            ('TN', 'TN'),
                            ('TX', 'TX'),
                            ('UT', 'UT'),
                            ('VT', 'VT'),
                            ('VA', 'VA'),
                            ('WA', 'WA'),
                            ('WV', 'WV'),
                            ('WI', 'WI'),
                            ('WY', 'WY'),
                        ])
    phone = StringField(
        # [x] Implement validation logic for phone
        'phone',
        validators=[
            Regexp('\d{3}-\d{3}-\d{4}',
                   message='phone number should be xxx-xxx-xxxx')
        ])
    image_link = StringField('image_link',
                             validators=[URL(message='image should be URL')])
    genres = SelectMultipleField('genres',
                                 validators=[DataRequired()],
                                 choices=[
                                     ('Alternative', 'Alternative'),
                                     ('Blues', 'Blues'),
                                     ('Classical', 'Classical'),
                                     ('Country', 'Country'),
                                     ('Electronic', 'Electronic'),
                                     ('Folk', 'Folk'),
                                     ('Funk', 'Funk'),
                                     ('Hip-Hop', 'Hip-Hop'),
                                     ('Heavy Metal', 'Heavy Metal'),
                                     ('Instrumental', 'Instrumental'),
                                     ('Jazz', 'Jazz'),
                                     ('Musical Theatre', 'Musical Theatre'),
                                     ('Pop', 'Pop'),
                                     ('Punk', 'Punk'),
                                     ('R&B', 'R&B'),
                                     ('Reggae', 'Reggae'),
                                     ('Rock n Roll', 'Rock n Roll'),
                                     ('Soul', 'Soul'),
                                     ('Other', 'Other'),
                                 ])
    website = StringField('website',
                          validators=[URL(message='website should be URL')])
    facebook_link = StringField(
        'facebook_link',
        validators=[URL(message='Facebook link should be URL')])
    seeking_venue = BooleanField('seeking_venue')
    seeking_description = StringField('seeking_description')
Пример #16
0
class ChangeInfoForm(FlaskForm):
    firstname = StringField('First name', [Length(min=4, max=30),
                Regexp('^[A-Za-z]*$', 0, 'Names must have only letters.')])

    lastname  = StringField('Last name', [Length(min=4, max=30),
                Regexp('^[A-Za-z]*$', 0, 'Names must have only letters.')])
class TeacherLoginForm(Form):
    teacher_id = StringField(validators=[Regexp(regex=r'^[0-9]{5}$', message='教师编号应为5位数字')])
    password = StringField(validators=[Regexp(regex=r'^[0-9a-zA-Z]{5,18}$', message='密码应为5~18位数字或字母组成')])
Пример #18
0
class SignupForm(FlaskForm):
    """
    FlaskForm for registering/signup purposes.

    """

    username = StringField(
        label='Username',
        validators=[
            DataRequired(),
            Length(3, 80),
            Regexp(
                '^[A-Za-z0-9_]{3,}$',
                message='Username should consist of numbers, '
                        'letters, and underscores.'
            )
        ]
    )
    password = PasswordField(
        'Password',
        validators=[
            DataRequired(),
            EqualTo('password2', message='Passwords must match.')
        ]
    )
    password2 = PasswordField(
        'Confirm password',
        validators=[DataRequired()]
    )
    email = StringField(
        'Email',
        validators=[
            DataRequired(),
            Length(1, 120),
            Email()
        ]
    )

    def validate_email(self, email_field):
        """
        Check whether the user's email exists on the database.

        Args:
            email_field: email to be checked.

        Returns:
            True if not found, else False.

        """

        if User.query.filter_by(email=email_field.data).first():
            raise ValidationError(
                'There already is a user with this email address.')

    def validate_username(self, username_field):
        """
        Check whether the username exists on the database.

        Args:
            username_field: username to be checked.

        Returns:
            True if not found, else False.

        """

        if User.query.filter_by(username=username_field.data).first():
            raise ValidationError('This username is already taken.')
class TeacherChangePasswordForm(Form):
    # 教师编号为5位数字
    teacher_id = StringField(validators=[Regexp(regex=r'^[0-9]{5}$', message='教师编号应为5位数字')])
    old_password = StringField(validators=[Regexp(regex=r'^[0-9a-zA-Z]{5,18}$', message='旧密码应为5~18位数字或字母组成')])
    new_password = StringField(validators=[Regexp(regex=r'^[0-9a-zA-Z]{5,18}$', message='新密码应为5~18位数字或字母组成')])
Пример #20
0
class SigninForm(BaseForm):
    telephone = StringField(
        validators=[Regexp(r'1[345789]\d{9}', message="请输入正确格式的手机号")])
    password = StringField(
        validators=[Regexp(r'[0-9a-zA-Z_\.]{3,20}', message="请输入正确格式的密码")])
    remember = StringField(IntegerField())
class AdminLoginForm(Form):
    password = StringField(validators=[Regexp(regex=r'^[0-9a-zA-Z]{5,18}$', message='旧密码应为5~18位数字或字母组成')])
Пример #22
0
class RecoverForm(FlaskForm):
    username = StringField("Username", validators=[InputRequired()])
    phone = StringField("PhoneNumber", validators=[DataRequired(), Length(10,10), Regexp('^[0-9]*$')])
    password = PasswordField('New Password', validators=[InputRequired()])
    submit = SubmitField('Submit')
class StudentLoginForm(Form):
    student_id = StringField(validators=[Regexp(regex=r'^[0-9]{10}$', message='学生编号应为10位数字')])
    password = StringField(validators=[Regexp(regex=r'^[0-9a-zA-Z]{5,18}$', message='密码应为5~18位数字或字母组成')])
Пример #24
0
class Verify_aAddress(Form):
    mobile = StringField(
        validators=[Regexp(r'^1(3|4|5|7|8)\d{9}$', message='手机号码输入错误')])
    name = StringField(validators=[InputRequired(message='请输入收货人姓名')])
    address = StringField(validators=[InputRequired(message='请输入收货地址')])
class StudentChangePasswordForm(Form):
    # 学生编号为10位数字
    student_id = StringField(validators=[Regexp(regex=r'^[0-9]{10}$', message='学生编号应为10位数字')])
    old_password = StringField(validators=[Regexp(regex=r'^[0-9a-zA-Z]{5,18}$', message='旧密码应为5~18位数字或字母组成')])
    new_password = StringField(validators=[Regexp(regex=r'^[0-9a-zA-Z]{5,18}$', message='新密码应为5~18位数字或字母组成')])
Пример #26
0
class Verify_aCart(Form):  #添加购物车商品id验证
    goods_id = IntegerField(validators=[InputRequired(message='商品id没传参')
                                        ])  #商品id
    number = IntegerField(validators=[Regexp(r'\d', message='数量输入错误')])
Пример #27
0
class CreateEventForm(Form):
    """A form for the creation of a :class:`~app.models.Event` object.

    :ivar title: :class:`wtforms.fields.StringField` - The title of the event.
    :ivar slug: :class:`wtforms.fields.StringField` - A unique url fragment for
        this blog post. This may only contain letters, numbers, and dashes
        (``-``).
    :ivar location: :class:`wtforms.fields.StringField` - The location of the
        event.
    :ivar start_date: :class:`wtforms.fields.DateField` - The date the event
        starts on.
    :ivar end_date: :class:`wtforms.fields.DateField` - The date the event
        ends on.
    :ivar start_time: :class:`TimeField` - The time the event starts.
    :ivar end_time: :class:`TimeField` - The time the event ends.
    :ivar is_recurring: :class:`wtforms.fields.BooleanField` - True if the
        event is recurring.
    :ivar frequency: :class:`wtforms.fields.SelectField` - The interval of the
        occurrence. Can only take the value ``"weekly"``.
    :ivar every: :class:`wtforms.fields.IntegerField` - The number of
        ``frequency`` units after which the event repeats. For example,
        ``frequency = "weekly"`` and ``every = 2`` indicates that the event
        occurs every two weeks.
    :ivar ends: :class:`wtforms.fields.RadioField` - ``"after"`` if the event
        ends after ``num_occurrences`` occurrences, or ``"on"`` if the date
        ends on ``recurrence_end_date``.
    :ivar num_occurrences: :class:`wtforms.fields.IntegerField` - The number of
        occurrences for a recurring event.  Should be set only if ``ends`` is
        set to ``"after"``.
    :ivar recurrence_end_date: :class:`wtforms.fields.DateField` - The date
        that the recurrence ends on.  Should be set only if ``ends`` is set to
        ``"on"``.
    :ivar recurrence_summary: :class:`wtforms.fields.StringField` - A plain
        English explanation of the recurrence. Generated in JavaScript but
        stored here.
    :ivar short_description: :class:`wtforms.fields.TextAreaField` - The
        markdown text of the short description for the event.
    :ivar long_description: :class:`wtforms.fields.TextAreaField` - The
        markdown text of the long description for the event.
    :ivar published: :class:`wtforms.fields.BooleanField` - True if the event
        is published.
    :ivar facebook_url: :class:`wtforms.fields.StringField` - The URL of the
        associated Facebook event.
    :ivar event_image: :class:`wtforms.fields.StringField` - The filename of
        the headline image.
    """

    title = StringField('Title',
                        [Required(message="Please provide an event title.")])
    slug = StringField('Slug', [UniqueEvent(),
                                Regexp(Regex.SLUG_REGEX,
                                       message=INVALID_SLUG)])
    location = StringField('Location')
    start_date = DateField('Start date', [Optional()], format=DATE_FORMAT)
    start_time = TimeField('Start time', [Optional()])
    end_date = DateField('End date', [Optional()], format=DATE_FORMAT)
    end_time = TimeField('End time', [Optional()])
    is_recurring = BooleanField('Is Recurring')
    frequency = SelectField('Repeats', choices=[('weekly', 'Weekly')],
                            default="weekly")
    every = IntegerField('Every', [NumberRange(min=1, max=30)], default=1)
    ends = RadioField('Ends', choices=[("after", "After"), ("on", "On")],
                      default="after")
    num_occurrences = IntegerField('Every', [NumberRange(min=1)], default=1)
    recurrence_end_date = DateField('Repeat End Date', [Optional()],
                                    format=DATE_FORMAT)
    recurrence_summary = StringField('Summary')
    short_description = TextAreaField('Short description',
                                      default=SHORT_DESCRIPTION_PLACEHOLDER)
    long_description = TextAreaField('Long description',
                                     default=LONG_DESCRIPTION_PLACEHOLDER)
    published = BooleanField('Published')
    facebook_url = StringField('Facebook  URL', [Optional(), URL()])
    event_image = StringField('Image', [image_with_same_name])

    def post_validate(self, validation_stopped):
        """Make sure that the start datetime comes before the end datetime.


        :param self: The form to validate
        :type self: :class:`Form`
        :param bool validation_stopped: True if any validator raised
            :class:`~wtforms.validators.StopValidation`.
        :raises: :class:`wtforms.validators.ValidationError`
        """
        if not validation_stopped:
            start_date = self.start_date.data
            start_time = self.start_time.data
            end_date = self.end_date.data
            end_time = self.end_time.data

            # Start and end dates should be in order.
            if start_date and end_date and start_date > end_date:
                raise ValidationError("Start date should come before end date")
            if (all([start_date, start_time, end_date, end_time]) and
                    start_time > end_time):
                raise ValidationError("Start time should come before end date")
Пример #28
0
class URLForm_usr(FlaskForm):
    txturl = StringField(validators=[
        DataRequired(),
        Regexp(r'(?:http\:|https\:)?\/\/.*\.(?:png|jpg|jpeg)$',
               message="Invalid image url.")
    ])
Пример #29
0
# root/app/user/forms.py

from flask import flash
from flask_wtf import FlaskForm  # , RecaptchaField
from wtforms import StringField, PasswordField, IntegerField, BooleanField,\
ValidationError
from wtforms.validators import InputRequired, Email, EqualTo, Length, \
NumberRange, Regexp
from app.models import User


username     = StringField('Username', [
            Length(min=4, max=30),
            InputRequired(message='Must provide your username.'),
            Regexp('^[A-Za-z][A-Za-z0-9_.]*$', 0,
                'Usernames must have only letters, numbers, dots or underscores.')])

password     = PasswordField('Password', [
            Length(min=5, max=30),
            InputRequired(message='Must provide a password.')])

password2    = PasswordField('Confirm password', [
            EqualTo('password', message='Must match Password field.'),
            InputRequired(message='Must provide a confirmation for password.')])

old_password = PasswordField('Actual password', [
            Length(min=5, max=30),
            InputRequired(message='Must provide a password.')])

email        = StringField('Email address', [Email(),
            Length(min=6, max=40),
Пример #30
0
 def __init__(self, require_tld=True, message=None):
     tld_part = require_tld and r"\.\w{2,10}" or ""
     regex = r"^[a-z]+://([^/:]+%s|([0-9]{1,3}\.){3}[0-9]{1,3})(:[0-9]+)?(\/.*)?$" % tld_part
     Regexp.__init__(self, regex, re.IGNORECASE | re.UNICODE, message)
Пример #31
0
class UpdateForm(FlaskForm):
    patient_id = StringField(
        "Patient SSN Id*",
        validators=[InputRequired(), Regexp(regex=r'^\d{9}$')],
        render_kw={'Placeholder': 'Patient Id'})
    patient_name = StringField("Patient Name",
                               validators=[
                                   Optional(),
                                   Regexp(regex='^[A-Za-z]+$',
                                          message='Only Alphabets allowed')
                               ],
                               render_kw={
                                   'Placeholder': 'Patient Name',
                                   'readonly': True
                               })
    age = IntegerField("Age",
                       validators=[Optional(),
                                   NumberRange(min=0, max=999)],
                       render_kw={
                           'Placeholder': 'Age',
                           'readonly': True
                       })

    doa = DateField("Date of Admission",
                    validators=[Optional()],
                    format='%Y-%m-%d',
                    render_kw={
                        'readonly': True,
                        'Placeholder': "yyyy-mm-dd"
                    })
    bed_type = SelectField("Bed Type",
                           validators=[Optional()],
                           choices=[('General ward', 'General Ward'),
                                    ('Semi sharing', 'Semi Sharing'),
                                    ('Single room', 'Single Room')],
                           render_kw={
                               'Placeholder': 'Select',
                               'readonly': True
                           })
    address = TextAreaField("Address",
                            validators=[Optional()],
                            render_kw={
                                'Placeholder': 'Enter Address',
                                'readonly': True
                            })
    state = StringField("State",
                        validators=[Optional(),
                                    Regexp(regex='^[a-zA-Z]+$')],
                        render_kw={
                            'Placeholder': 'State',
                            'readonly': True
                        })
    city = StringField("City",
                       validators=[Optional(),
                                   Regexp(regex='^[a-zA-Z]+$')],
                       render_kw={
                           'Placeholder': 'City',
                           'readonly': True
                       })
    get = SubmitField("Get")
    update = SubmitField("Update")