Python wtforms.fields 模块,SelectMultipleField() 实例源码

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

项目:flask-zhenai-mongo-echarts    作者:Fretice    | 项目源码 | 文件源码
def convert(self, model, field, field_args):
        kwargs = {
            'label': getattr(field, 'verbose_name', field.name),
            'description': getattr(field, 'help_text', None) or '',
            'validators': getattr(field, 'validators', None) or [],
            'filters': getattr(field, 'filters', None) or [],
            'default': field.default,
        }
        if field_args:
            kwargs.update(field_args)

        if kwargs['validators']:
            # Create a copy of the list since we will be modifying it.
            kwargs['validators'] = list(kwargs['validators'])

        if field.required:
            kwargs['validators'].append(validators.InputRequired())
        else:
            kwargs['validators'].append(validators.Optional())

        ftype = type(field).__name__

        if field.choices:
            kwargs['choices'] = field.choices

            if ftype in self.converters:
                kwargs["coerce"] = self.coerce(ftype)
            multiple_field = kwargs.pop('multiple', False)
            radio_field = kwargs.pop('radio', False)
            if multiple_field:
                return f.SelectMultipleField(**kwargs)
            if radio_field:
                return f.RadioField(**kwargs)
            return f.SelectField(**kwargs)

        ftype = type(field).__name__

        if hasattr(field, 'to_form_field'):
            return field.to_form_field(model, kwargs)

        if ftype in self.converters:
            return self.converters[ftype](model, field, kwargs)