コード例 #1
0
ファイル: core.py プロジェクト: mobyle2-legacy/WTForms
class FileField(TextField):
    """
    Can render a file-upload field.  Will take any passed filename value, if
    any is sent by the browser in the post params.  This field will NOT
    actually handle the file upload portion, as wtforms does not deal with
    individual frameworks' file handling capabilities.
    """
    widget = widgets.FileInput()
コード例 #2
0
 def __call__(self, field, **kwargs):
     default_widget = widgets.FileInput()
     kwargs.pop('class_', None)
     return HTMLString(
         render_template('meetings/registration/_image_widget.html',
                         field=field,
                         default_widget=default_widget,
                         field_kwargs=kwargs))
コード例 #3
0
 def __call__(self, field, **kwargs):
     default_widget = widgets.FileInput()
     kwargs.pop('class_', None)
     return HTMLString(
         render_template('meetings/registration/_document_widget.html',
                         field=field,
                         default_widget=default_widget,
                         participant=getattr(field, '_participant', None),
                         field_kwargs=kwargs))
コード例 #4
0
class Menu_form(Form):
    title = TextField(label='title',
                      validators=[
                          validators.DataRequired(message='菜单不能为空'),
                          validators.Length(min=3,
                                            max=8,
                                            message='菜单最少3个字符,最大16个字符')
                      ],
                      widget=widgets.FileInput(),
                      render_kw={'class': 'form-control'})
コード例 #5
0
class CreateCenterForm(FlaskForm):
    name = StringField('nombre', validators=[DataRequired(), Length(max=55)])
    address = StringField('direccion', validators=[Length(max=99)])
    phone = StringField(
        'telefono',
        validators=[
            Length(min=8,
                   max=20,
                   message='el telefono debe tener entre 8 y 20 digitos')
        ])
    email = EmailField('email',
                       validators=[
                           DataRequired(),
                           Email('el email ingresado no es válido'),
                           Length(max=60,
                                  message='se permite hasta 60 caracteres')
                       ])
    opening = TimeField('apertura', validators=[DataRequired()])
    closing = TimeField('cierre', validators=[DataRequired()])

    city_id = SelectField('municipio', choices=[n for n in range(1, 153)])

    # city_id = SelectField('municipio', choices=get_cities_list(), coerce=int)

    center_type = SelectField(label='tipo',
                              choices=[(g, g) for g in CENTER_TYPES])
    web_site = URLField('sitio web',
                        render_kw={"placeholder": "https://www.site.com"})
    protocol = FileField(
        'protocolo',
        widget=widgets.FileInput(),
        validators=[FileAllowed(['pdf'], 'protocolo en pdf unicamente')])
    gl_lat = HiddenField()
    gl_long = HiddenField()

    @classmethod
    def validate_phone(cls, form, phone):
        for ch in phone.data:
            if not ch.isdigit():
                raise ValidationError(
                    'al ingresar el telefono, utilice dígitos únicamente, sin espacios ni guiones'
                )

    @classmethod
    def validate_opening(cls, form, opening):
        if form.closing.data <= opening.data:
            raise ValidationError(
                'el horario de apertura y cierre no son correctos')
コード例 #6
0
class RecoverForms(BaseForm):
    handlemod = core.RadioField(label='选择操作类型',
                                choices=(
                                    (1, '恢复链接'),
                                    (2, '删除链接'),
                                ),
                                validators=[DataRequired()],
                                coerce=int)
    fileupload = simple.StringField(
        label="上传列表文件",
        widget=widgets.FileInput(),
        render_kw={'placeholder': 'form-control'},
    )
    imageurls = simple.StringField(label="链接地址",
                                   widget=widgets.TextArea(),
                                   render_kw={
                                       "placeholder": "输入链接url地址以换行分隔",
                                       "rows": 10,
                                       'class': 'form-control'
                                   })
    remark = simple.StringField(label="备注",
                                widget=widgets.TextInput(),
                                render_kw={
                                    "placeholder": "本次操作说明,可不填写。",
                                    'class': 'form-control'
                                })
    addwhiteimg = core.RadioField(
        label='图片是否加入图片白名单',
        choices=((0, '加入'), (1, '不加入')),
        default=1,
        validators=[DataRequired()],
        coerce=int,
    )
    relation = core.RadioField(
        label='是否关联3g网及分页',
        choices=(
            (1, '关联'),
            (2, '不关联'),
        ),
        validators=[DataRequired()],
        coerce=int,
        default=2,
    )
コード例 #7
0
ファイル: user.py プロジェクト: wuyuz/ChatTools
class RegisterForm(Form):
    name = simple.StringField(
        label='用户名',
        validators=[
            validators.Length(min=2,
                              max=18,
                              message='用户名长度必须大于%(min)d且小于%(max)d'),
            validators.DataRequired()
        ],
        widget=widgets.TextInput(),
        # 输入框的默认值
        default='alex')

    pwd = simple.PasswordField(
        label='密码',
        validators=[
            validators.Length(min=2, message='用户名长度必须大于%(min)d'),
            validators.DataRequired(message='密码不能为空.')
        ],
        widget=widgets.PasswordInput(),
    )

    pwd_confirm = simple.PasswordField(
        label='重复密码',
        validators=[
            validators.DataRequired(message='重复密码不能为空.'),
            # 内部校验器:与哪一个字段要一直,比django自带的要简单一些,否则还要使用钩子
            validators.EqualTo('pwd', message="两次密码输入不一致")
        ],
        widget=widgets.PasswordInput(),
    )
    file = simple.FileField(
        label='头像上传',
        widget=widgets.FileInput(),
    )

    # 定制钩子函数,使用validate_字段名
    def validate_pwd_confirm(self, field):
        if field.data != self.data['pwd']:
            raise validators.StopValidation("密码不一致")  # 不再继续后续验证
        self.data.pop('pwd_confirm')