本文整理汇总了Python中wagtail.wagtailforms.forms.FormBuilder类的典型用法代码示例。如果您正苦于以下问题:Python FormBuilder类的具体用法?Python FormBuilder怎么用?Python FormBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FormBuilder类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestFormBuilder
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)
示例2: TestFormBuilder
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)
示例3: setUp
def setUp(self):
# Create a form page
home_page = Page.objects.get(url_path='/home/')
self.form_page = home_page.add_child(instance=FormPage(
title="Contact us",
slug="contact-us",
to_address="[email protected]",
from_address="[email protected]",
subject="The subject",
))
FormField.objects.create(
page=self.form_page,
sort_order=1,
label="Your name",
field_type='singleline',
required=True,
)
FormField.objects.create(
page=self.form_page,
sort_order=2,
label="Your message",
field_type='multiline',
required=True,
)
FormField.objects.create(
page=self.form_page,
sort_order=2,
label="Your birthday",
field_type='date',
required=True,
)
FormField.objects.create(
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())
示例4: TestFormBuilder
class TestFormBuilder(TestCase):
def setUp(self):
# Create a form page
home_page = Page.objects.get(url_path='/home/')
self.form_page = home_page.add_child(instance=FormPage(
title="Contact us",
slug="contact-us",
to_address="[email protected]",
from_address="[email protected]",
subject="The subject",
))
FormField.objects.create(
page=self.form_page,
sort_order=1,
label="Your name",
field_type='singleline',
required=True,
)
FormField.objects.create(
page=self.form_page,
sort_order=2,
label="Your message",
field_type='multiline',
required=True,
)
FormField.objects.create(
page=self.form_page,
sort_order=2,
label="Your birthday",
field_type='date',
required=True,
)
FormField.objects.create(
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):
"""
#.........这里部分代码省略.........
示例5: setUp
def setUp(self):
self.form_page = Page.objects.get(url_path='/home/contact-us/').specific
self.fb = FormBuilder(self.form_page.form_fields.all())
示例6: setUp
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())