當前位置: 首頁>>代碼示例>>Python>>正文


Python FormBuilder.get_form_class方法代碼示例

本文整理匯總了Python中wagtail.wagtailforms.forms.FormBuilder.get_form_class方法的典型用法代碼示例。如果您正苦於以下問題:Python FormBuilder.get_form_class方法的具體用法?Python FormBuilder.get_form_class怎麽用?Python FormBuilder.get_form_class使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在wagtail.wagtailforms.forms.FormBuilder的用法示例。


在下文中一共展示了FormBuilder.get_form_class方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestFormBuilder

# 需要導入模塊: from wagtail.wagtailforms.forms import FormBuilder [as 別名]
# 或者: from wagtail.wagtailforms.forms.FormBuilder import get_form_class [as 別名]
class TestFormBuilder(TestCase):
    fixtures = ['test.json']

    def setUp(self):
        self.form_page = Page.objects.get(url_path='/home/contact-us/').specific
        self.fb = FormBuilder(self.form_page.form_fields.all())

    def test_fields(self):
        """
        This tests that all fields were added to the form with the correct types
        """
        form_class = self.fb.get_form_class()
        
        self.assertTrue('your-email' in form_class.base_fields.keys())
        self.assertTrue('your-message' in form_class.base_fields.keys())

        self.assertIsInstance(form_class.base_fields['your-email'], forms.EmailField)
        self.assertIsInstance(form_class.base_fields['your-message'], forms.CharField)
開發者ID:ostmodern,項目名稱:wagtail,代碼行數:20,代碼來源:tests.py

示例2: TestFormBuilder

# 需要導入模塊: from wagtail.wagtailforms.forms import FormBuilder [as 別名]
# 或者: from wagtail.wagtailforms.forms.FormBuilder import get_form_class [as 別名]
class TestFormBuilder(TestCase):
    def setUp(self):
        # Create a form page
        self.form_page = make_form_page()

        # Create a form builder
        self.fb = FormBuilder(self.form_page.form_fields.all())

    def test_fields(self):
        """
        This tests that all fields were added to the form with the correct types
        """
        form_class = self.fb.get_form_class()

        self.assertIn('your-email', form_class.base_fields.keys())
        self.assertIn('your-message', form_class.base_fields.keys())

        self.assertIsInstance(form_class.base_fields['your-email'], forms.EmailField)
        self.assertIsInstance(form_class.base_fields['your-message'], forms.CharField)
開發者ID:wgiddens,項目名稱:wagtail,代碼行數:21,代碼來源:tests.py

示例3: TestFormBuilder

# 需要導入模塊: from wagtail.wagtailforms.forms import FormBuilder [as 別名]
# 或者: from wagtail.wagtailforms.forms.FormBuilder import get_form_class [as 別名]

#.........這裏部分代碼省略.........
            page=self.form_page,
            sort_order=2,
            label="Your birthtime :)",
            field_type='datetime',
            required=True,
        )
        FormField.objects.create(
            page=self.form_page,
            sort_order=1,
            label="Your email",
            field_type='email',
            required=True,
        )
        FormField.objects.create(
            page=self.form_page,
            sort_order=2,
            label="Your homepage",
            field_type='url',
            required=True,
        )
        FormField.objects.create(
            page=self.form_page,
            sort_order=2,
            label="Your favourite number",
            field_type='number',
            required=True,
        )
        FormField.objects.create(
            page=self.form_page,
            sort_order=2,
            label="Your favourite Python IDEs",
            field_type='dropdown',
            required=True,
            choices='PyCharm,vim,nano',
        )
        FormField.objects.create(
            page=self.form_page,
            sort_order=2,
            label="Your favourite Python IDE",
            help_text="Choose one",
            field_type='radio',
            required=True,
            choices='PyCharm,vim,nano',
        )
        FormField.objects.create(
            page=self.form_page,
            sort_order=3,
            label="Your choices",
            field_type='checkboxes',
            required=False,
            choices='foo,bar,baz',
        )
        FormField.objects.create(
            page=self.form_page,
            sort_order=3,
            label="I agree to the Terms of Use",
            field_type='checkbox',
            required=True,
        )

        # Create a form builder
        self.fb = FormBuilder(self.form_page.form_fields.all())

    def test_fields(self):
        """
        This tests that all fields were added to the form with the correct types
        """
        form_class = self.fb.get_form_class()

        # All fields are present in form
        field_names = form_class.base_fields.keys()
        self.assertIn('your-name', field_names)
        self.assertIn('your-message', field_names)
        self.assertIn('your-birthday', field_names)
        self.assertIn('your-birthtime', field_names)
        self.assertIn('your-email', field_names)
        self.assertIn('your-homepage', field_names)
        self.assertIn('your-favourite-number', field_names)
        self.assertIn('your-favourite-python-ides', field_names)
        self.assertIn('your-favourite-python-ide', field_names)
        self.assertIn('your-choices', field_names)
        self.assertIn('i-agree-to-the-terms-of-use', field_names)

        # All fields have proper type
        self.assertIsInstance(form_class.base_fields['your-name'], forms.CharField)
        self.assertIsInstance(form_class.base_fields['your-message'], forms.CharField)
        self.assertIsInstance(form_class.base_fields['your-birthday'], forms.DateField)
        self.assertIsInstance(form_class.base_fields['your-birthtime'], forms.DateTimeField)
        self.assertIsInstance(form_class.base_fields['your-email'], forms.EmailField)
        self.assertIsInstance(form_class.base_fields['your-homepage'], forms.URLField)
        self.assertIsInstance(form_class.base_fields['your-favourite-number'], forms.DecimalField)
        self.assertIsInstance(form_class.base_fields['your-favourite-python-ides'], forms.ChoiceField)
        self.assertIsInstance(form_class.base_fields['your-favourite-python-ide'], forms.ChoiceField)
        self.assertIsInstance(form_class.base_fields['your-choices'], forms.MultipleChoiceField)
        self.assertIsInstance(form_class.base_fields['i-agree-to-the-terms-of-use'], forms.BooleanField)

        # Some fields have non-default widgets
        self.assertIsInstance(form_class.base_fields['your-message'].widget, forms.Textarea)
        self.assertIsInstance(form_class.base_fields['your-favourite-python-ide'].widget, forms.RadioSelect)
        self.assertIsInstance(form_class.base_fields['your-choices'].widget, forms.CheckboxSelectMultiple)
開發者ID:Eraldo,項目名稱:wagtail,代碼行數:104,代碼來源:tests.py


注:本文中的wagtail.wagtailforms.forms.FormBuilder.get_form_class方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。