当前位置 博文首页 > 文章内容

    fields,用于说明如何使用wtforms.fields.Field()

    作者:Tan09wlll 栏目:Tan的日记 时间:2021-02-25 14:41:08

    本站于2023年9月4日。收到“大连君*****咨询有限公司”通知
    说我们IIS7站长博客,有一篇博文用了他们的图片。
    要求我们给他们一张图片6000元。要不然法院告我们

    为避免不必要的麻烦,IIS7站长博客,全站内容图片下架、并积极应诉
    博文内容全部不再显示,请需要相关资讯的站长朋友到必应搜索。谢谢!

    另祝:版权碰瓷诈骗团伙,早日弃暗投明。

    相关新闻:借版权之名、行诈骗之实,周某因犯诈骗罪被判处有期徒刑十一年六个月

    叹!百花齐放的时代,渐行渐远!



    def test_text_area_a_wtforms_field(self):

            text_area = MaxTextAreaField('LabelText', _form=self.mock_form, _name='aName')

            self.assertIsInstance(text_area, Field)

    def test_text_area_supports_maxlength_property(self):

            text_area = MaxTextAreaField('TestLabel', maxlength=20, _form=self.mock_form, _name='aName')

            self.assertIsInstance(text_area, Field)

            self.assertEqual(text_area.maxlength, 20)

    def test_integer_field(self):

            integer_field = CustomIntegerField(_form=self.mock_form, _name='aName')

            self.assertIsInstance(integer_field, Field)


            try:

                integer_field.process_formdata(['NonInteger'])

            except:

                self.fail("Exceptions should not thrown by CustomIntegerField")

    def test_decimal_field(self):

            decimal_field = CustomDecimalField(_form=self.mock_form, _name='aName')

            self.assertIsInstance(decimal_field, Field)


            try:

                decimal_field.process_formdata(['NonDecimal'])

            except:

                self.fail("Exception should not be thrown by CustomDecimalField")

    def _init_form_helper(self, form, lock_fields):

            """General :meth:`init_form` helper utility to remove all fields

            in `lock_fields`.


            :param form: The :class:`flask_wtf.Form` instance.

            :param lock_fields: :class:`list` of field names to be removed.

            """

            for k, v in form.__dict__.items():

                if isinstance(v, Field) and not isinstance(v, HiddenField):

                    if k in lock_fields:

                        del form[k]