本文整理匯總了Python中wagtail.wagtailadmin.edit_handlers.FieldPanel.required_fields方法的典型用法代碼示例。如果您正苦於以下問題:Python FieldPanel.required_fields方法的具體用法?Python FieldPanel.required_fields怎麽用?Python FieldPanel.required_fields使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wagtail.wagtailadmin.edit_handlers.FieldPanel
的用法示例。
在下文中一共展示了FieldPanel.required_fields方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestFieldPanel
# 需要導入模塊: from wagtail.wagtailadmin.edit_handlers import FieldPanel [as 別名]
# 或者: from wagtail.wagtailadmin.edit_handlers.FieldPanel import required_fields [as 別名]
class TestFieldPanel(TestCase):
def setUp(self):
self.EventPageForm = get_form_for_model(EventPage, formsets=[])
self.event = EventPage(title='Abergavenny sheepdog trials',
date_from=date(2014, 7, 20), date_to=date(2014, 7, 21))
self.EndDatePanel = FieldPanel('date_to', classname='full-width').bind_to_model(EventPage)
def test_render_as_object(self):
form = self.EventPageForm(
{'title': 'Pontypridd sheepdog trials', 'date_from': '2014-07-20', 'date_to': '2014-07-22'},
instance=self.event)
form.is_valid()
field_panel = self.EndDatePanel(
instance=self.event,
form=form
)
result = field_panel.render_as_object()
# check that label appears in the 'object' wrapper as well as the field
self.assertIn('<legend>End date</legend>', result)
self.assertIn('<label for="id_date_to">End date:</label>', result)
# check that help text is included
self.assertIn('Not required if event is on a single day', result)
# check that the populated form field is included
self.assertIn('value="2014-07-22"', result)
# there should be no errors on this field
self.assertNotIn('<p class="error-message">', result)
def test_render_as_field(self):
form = self.EventPageForm(
{'title': 'Pontypridd sheepdog trials', 'date_from': '2014-07-20', 'date_to': '2014-07-22'},
instance=self.event)
form.is_valid()
field_panel = self.EndDatePanel(
instance=self.event,
form=form
)
result = field_panel.render_as_field()
# check that label is output in the 'field' style
self.assertIn('<label for="id_date_to">End date:</label>', result)
self.assertNotIn('<legend>End date</legend>', result)
# check that help text is included
self.assertIn('Not required if event is on a single day', result)
# check that the populated form field is included
self.assertIn('value="2014-07-22"', result)
# there should be no errors on this field
self.assertNotIn('<p class="error-message">', result)
def test_required_fields(self):
result = self.EndDatePanel.required_fields()
self.assertEqual(result, ['date_to'])
def test_error_message_is_rendered(self):
form = self.EventPageForm(
{'title': 'Pontypridd sheepdog trials', 'date_from': '2014-07-20', 'date_to': '2014-07-33'},
instance=self.event)
form.is_valid()
field_panel = self.EndDatePanel(
instance=self.event,
form=form
)
result = field_panel.render_as_field()
self.assertIn('<p class="error-message">', result)
self.assertIn('<span>Enter a valid date.</span>', result)