本文整理匯總了Python中wagtail.wagtailadmin.edit_handlers.FieldPanel.rendered_fields方法的典型用法代碼示例。如果您正苦於以下問題:Python FieldPanel.rendered_fields方法的具體用法?Python FieldPanel.rendered_fields怎麽用?Python FieldPanel.rendered_fields使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wagtail.wagtailadmin.edit_handlers.FieldPanel
的用法示例。
在下文中一共展示了FieldPanel.rendered_fields方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestFieldPanel
# 需要導入模塊: from wagtail.wagtailadmin.edit_handlers import FieldPanel [as 別名]
# 或者: from wagtail.wagtailadmin.edit_handlers.FieldPanel import rendered_fields [as 別名]
class TestFieldPanel(TestCase):
class FakeClass(object):
required = False
widget = 'fake widget'
class FakeField(object):
label = 'label'
help_text = 'help text'
errors = ['errors']
id_for_label = 'id for label'
class FakeForm(dict):
def __init__(self, *args, **kwargs):
self.fields = self.fields_iterator()
def fields_iterator(self):
for i in self:
yield i
def setUp(self):
fake_field = self.FakeField()
fake_field.field = self.FakeClass()
self.field_panel = FieldPanel('barbecue', 'snowman')(
instance=True,
form={'barbecue': fake_field})
def test_render_as_object(self):
result = self.field_panel.render_as_object()
self.assertIn('<legend>label</legend>',
result)
self.assertIn('<p class="error-message">',
result)
def test_render_js_unknown_widget(self):
field = self.FakeField()
bound_field = self.FakeField()
widget = self.FakeField()
field.widget = widget
bound_field.field = field
self.field_panel.bound_field = bound_field
result = self.field_panel.render_js()
self.assertEqual(result,
'')
def test_render_as_field(self):
field = self.FakeField()
bound_field = self.FakeField()
bound_field.field = field
self.field_panel.bound_field = bound_field
result = self.field_panel.render_as_field()
self.assertIn('<p class="help">help text</p>',
result)
self.assertIn('<span>errors</span>',
result)
def test_rendered_fields(self):
result = self.field_panel.rendered_fields()
self.assertEqual(result, ['barbecue'])
def test_field_type(self):
fake_object = self.FakeClass()
another_fake_object = self.FakeClass()
fake_object.field = another_fake_object
self.field_panel.bound_field = fake_object
self.assertEqual(self.field_panel.field_type(), 'fake_class')
def test_widget_overrides(self):
result = FieldPanel('barbecue', 'snowman').widget_overrides()
self.assertEqual(result, {})
def test_required_formsets(self):
result = FieldPanel('barbecue', 'snowman').required_formsets()
self.assertEqual(result, [])
def test_get_form_class(self):
result = FieldPanel('barbecue', 'snowman').get_form_class(Page)
self.assertTrue(issubclass(result, WagtailAdminModelForm))
def test_render_js(self):
result = self.field_panel.render_js()
self.assertEqual(result, "")
def test_render_missing_fields(self):
fake_form = self.FakeForm()
fake_form["foo"] = "bar"
self.field_panel.form = fake_form
self.assertEqual(self.field_panel.render_missing_fields(), "bar")
def test_render_form_content(self):
fake_form = self.FakeForm()
fake_form["foo"] = "bar"
self.field_panel.form = fake_form
self.assertIn("bar", self.field_panel.render_form_content())