本文整理汇总了Python中wagtail.wagtailadmin.edit_handlers.FieldPanel类的典型用法代码示例。如果您正苦于以下问题:Python FieldPanel类的具体用法?Python FieldPanel怎么用?Python FieldPanel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FieldPanel类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
self.EventPageForm = get_form_for_model(
EventPage, form_class=WagtailAdminPageForm, 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)
开发者ID:DjangoBD,项目名称:wagtail,代码行数:7,代码来源:test_edit_handlers.py
示例2: TestFieldPanel
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)
开发者ID:Fluxflashor,项目名称:wagtail,代码行数:79,代码来源:test_edit_handlers.py
示例3: setUp
def setUp(self):
fake_field = self.FakeField()
fake_field.field = self.FakeClass()
self.field_panel = FieldPanel('barbecue', 'snowman')(
instance=True,
form={'barbecue': fake_field})
开发者ID:0b3r,项目名称:wagtail,代码行数:6,代码来源:test_edit_handlers.py
示例4: TestFieldPanel
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())
开发者ID:0b3r,项目名称:wagtail,代码行数:93,代码来源:test_edit_handlers.py
注:本文中的wagtail.wagtailadmin.edit_handlers.FieldPanel类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论