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

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

项目:wazo-admin-ui    作者:wazo-pbx    | 项目源码 | 文件源码
def to_dict(self):
        result = {}
        for name, f in self._fields.items():
            if name == 'csrf_token' or isinstance(f, SubmitField):
                continue
            elif isinstance(f, FormField):
                result[name] = f.form.to_dict()
            elif isinstance(f, FieldList):
                result[name] = [entry.to_dict() for entry in f.entries]
            elif not f.raw_data and f.default is None:
                continue
            else:
                default = f.default or f.data
                data = f.data if f.data else default
                result[name] = data if data != '' else None
        return result
项目:wazo-admin-ui    作者:wazo-pbx    | 项目源码 | 文件源码
def test_to_dict_with_submitfield(self):
        class MyForm(BaseForm):
            attribute1 = StringField()
            submit = SubmitField()

        with app.test_request_context(method='POST', data={'attribute1': 'value',
                                                           'submit': 'true'}):
            form = MyForm()
        result = form.to_dict()

        assert_that(result, has_entries(attribute1='value'))