Python wtforms 模块,IntegerField() 实例源码

我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用wtforms.IntegerField()

项目:wazo-admin-ui    作者:wazo-pbx    | 项目源码 | 文件源码
def setUp(self):
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False

        class UserForm(BaseForm):
            user_id = IntegerField()
            timeout = StringField()

        TemplateDestinationForm.user = FormField(UserForm)
项目:hedhes    作者:Zo0x    | 项目源码 | 文件源码
def factory(cls, data, **kwargs):
        for d in data:
            if d.key == 'default_search_quality':
                setattr(cls, d.key, SelectMultipleField(d.name, choices=app.config.get('AVAILABLE_QUALITIES'), default=d.value, validators=[Optional()]))
            elif d.type == 'list':
                setattr(cls, d.key, SelectMultipleField(d.name, default=d.value))
            elif d.type == 'string':
                setattr(cls, d.key, StringField(d.name, default=d.value))
            elif d.type == 'bool':
                setattr(cls, d.key, BooleanField(d.name, default=d.value))
            elif d.type == 'float':
                setattr(cls, d.key, FloatField(d.name, default=d.value))
            elif d.type == 'int':
                setattr(cls, d.key, IntegerField(d.name, default=d.value))
        return cls(**kwargs)
项目:pillar    作者:armadillica    | 项目源码 | 文件源码
def add_form_properties(form_class, node_type):
    """Add fields to a form based on the node and form schema provided.
    :type node_schema: dict
    :param node_schema: the validation schema used by Cerberus
    :type form_class: class
    :param form_class: The form class to which we append fields
    :type form_schema: dict
    :param form_schema: description of how to build the form (which fields to
            show and hide)
    """

    for prop_name, schema_prop, form_prop in iter_node_properties(node_type):

        # Recursive call if detects a dict
        field_type = schema_prop['type']

        if field_type == 'dict':
            assert prop_name == 'attachments'
            field = attachments.attachment_form_group_create(schema_prop)
        elif field_type == 'list':
            if prop_name == 'files':
                schema = schema_prop['schema']['schema']
                file_select_form = build_file_select_form(schema)
                field = FieldList(CustomFormField(file_select_form),
                                  min_entries=1)
            elif 'allowed' in schema_prop['schema']:
                choices = [(c, c) for c in schema_prop['schema']['allowed']]
                field = SelectMultipleField(choices=choices)
            else:
                field = SelectMultipleField(choices=[])
        elif 'allowed' in schema_prop:
            select = []
            for option in schema_prop['allowed']:
                select.append((str(option), str(option)))
            field = SelectField(choices=select)
        elif field_type == 'datetime':
            if form_prop.get('dateonly'):
                field = DateField(prop_name, default=date.today())
            else:
                field = DateTimeField(prop_name, default=datetime.now())
        elif field_type == 'integer':
            field = IntegerField(prop_name, default=0)
        elif field_type == 'float':
            field = FloatField(prop_name, default=0.0)
        elif field_type == 'boolean':
            field = BooleanField(prop_name)
        elif field_type == 'objectid' and 'data_relation' in schema_prop:
            if schema_prop['data_relation']['resource'] == 'files':
                field = FileSelectField(prop_name)
            else:
                field = StringField(prop_name)
        elif schema_prop.get('maxlength', 0) > 64:
            field = TextAreaField(prop_name)
        else:
            field = StringField(prop_name)

        setattr(form_class, prop_name, field)