本文整理匯總了Python中wagtail.core.blocks.PageChooserBlock方法的典型用法代碼示例。如果您正苦於以下問題:Python blocks.PageChooserBlock方法的具體用法?Python blocks.PageChooserBlock怎麽用?Python blocks.PageChooserBlock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wagtail.core.blocks
的用法示例。
在下文中一共展示了blocks.PageChooserBlock方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_initialisation_from_subclass
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import PageChooserBlock [as 別名]
def test_initialisation_from_subclass(self):
class LinkStructValue(blocks.StructValue):
def url(self):
return self.get('page') or self.get('link')
class LinkBlock(blocks.StructBlock):
title = blocks.CharBlock()
page = blocks.PageChooserBlock(required=False)
link = blocks.URLBlock(required=False)
class Meta:
value_class = LinkStructValue
block = LinkBlock()
self.assertEqual(list(block.child_blocks.keys()), ['title', 'page', 'link'])
block_value = block.to_python({'title': 'Website', 'link': 'https://website.com'})
self.assertIsInstance(block_value, LinkStructValue)
default_value = block.get_default()
self.assertIsInstance(default_value, LinkStructValue)
示例2: test_initialisation_with_multiple_subclassses
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import PageChooserBlock [as 別名]
def test_initialisation_with_multiple_subclassses(self):
class LinkStructValue(blocks.StructValue):
def url(self):
return self.get('page') or self.get('link')
class LinkBlock(blocks.StructBlock):
title = blocks.CharBlock()
page = blocks.PageChooserBlock(required=False)
link = blocks.URLBlock(required=False)
class Meta:
value_class = LinkStructValue
class StyledLinkBlock(LinkBlock):
classname = blocks.CharBlock()
block = StyledLinkBlock()
self.assertEqual(list(block.child_blocks.keys()), ['title', 'page', 'link', 'classname'])
value_from_datadict = block.value_from_datadict({
'queen-title': "Torchbox",
'queen-link': "http://www.torchbox.com",
'queen-classname': "fullsize",
}, {}, 'queen')
self.assertIsInstance(value_from_datadict, LinkStructValue)
示例3: test_calls_child_bulk_to_python_when_available
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import PageChooserBlock [as 別名]
def test_calls_child_bulk_to_python_when_available(self):
page_ids = [2, 3, 4, 5]
expected_pages = Page.objects.filter(pk__in=page_ids)
block = blocks.ListBlock(blocks.PageChooserBlock())
with self.assertNumQueries(1):
pages = block.to_python(page_ids)
self.assertSequenceEqual(pages, expected_pages)
示例4: test_serialize
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import PageChooserBlock [as 別名]
def test_serialize(self):
"""The value of a PageChooserBlock (a Page object) should serialize to an ID"""
block = blocks.PageChooserBlock()
christmas_page = Page.objects.get(slug='christmas')
self.assertEqual(block.get_prep_value(christmas_page), christmas_page.id)
# None should serialize to None
self.assertEqual(block.get_prep_value(None), None)
示例5: test_deserialize
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import PageChooserBlock [as 別名]
def test_deserialize(self):
"""The serialized value of a PageChooserBlock (an ID) should deserialize to a Page object"""
block = blocks.PageChooserBlock()
christmas_page = Page.objects.get(slug='christmas')
self.assertEqual(block.to_python(christmas_page.id), christmas_page)
# None should deserialize to None
self.assertEqual(block.to_python(None), None)
示例6: test_form_render_with_target_model_default
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import PageChooserBlock [as 別名]
def test_form_render_with_target_model_default(self):
block = blocks.PageChooserBlock()
empty_form_html = block.render_form(None, 'page')
self.assertIn('createPageChooser("page", ["wagtailcore.page"], null, false, null);', empty_form_html)
示例7: test_form_render_with_target_model_string
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import PageChooserBlock [as 別名]
def test_form_render_with_target_model_string(self):
block = blocks.PageChooserBlock(help_text="pick a page, any page", page_type='tests.SimplePage')
empty_form_html = block.render_form(None, 'page')
self.assertIn('createPageChooser("page", ["tests.simplepage"], null, false, null);', empty_form_html)
示例8: test_form_render_with_target_model_literal
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import PageChooserBlock [as 別名]
def test_form_render_with_target_model_literal(self):
block = blocks.PageChooserBlock(help_text="pick a page, any page", page_type=SimplePage)
empty_form_html = block.render_form(None, 'page')
self.assertIn('createPageChooser("page", ["tests.simplepage"], null, false, null);', empty_form_html)
示例9: test_form_render_with_target_model_multiple_strings
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import PageChooserBlock [as 別名]
def test_form_render_with_target_model_multiple_strings(self):
block = blocks.PageChooserBlock(help_text="pick a page, any page", page_type=['tests.SimplePage', 'tests.EventPage'])
empty_form_html = block.render_form(None, 'page')
self.assertIn('createPageChooser("page", ["tests.simplepage", "tests.eventpage"], null, false, null);', empty_form_html)
示例10: test_form_render_with_target_model_multiple_literals
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import PageChooserBlock [as 別名]
def test_form_render_with_target_model_multiple_literals(self):
block = blocks.PageChooserBlock(help_text="pick a page, any page", page_type=[SimplePage, EventPage])
empty_form_html = block.render_form(None, 'page')
self.assertIn('createPageChooser("page", ["tests.simplepage", "tests.eventpage"], null, false, null);', empty_form_html)
示例11: test_form_response
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import PageChooserBlock [as 別名]
def test_form_response(self):
block = blocks.PageChooserBlock()
christmas_page = Page.objects.get(slug='christmas')
value = block.value_from_datadict({'page': str(christmas_page.id)}, {}, 'page')
self.assertEqual(value, christmas_page)
empty_value = block.value_from_datadict({'page': ''}, {}, 'page')
self.assertEqual(empty_value, None)
示例12: test_clean
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import PageChooserBlock [as 別名]
def test_clean(self):
required_block = blocks.PageChooserBlock()
nonrequired_block = blocks.PageChooserBlock(required=False)
christmas_page = Page.objects.get(slug='christmas')
self.assertEqual(required_block.clean(christmas_page), christmas_page)
with self.assertRaises(ValidationError):
required_block.clean(None)
self.assertEqual(nonrequired_block.clean(christmas_page), christmas_page)
self.assertEqual(nonrequired_block.clean(None), None)
示例13: test_target_model_default
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import PageChooserBlock [as 別名]
def test_target_model_default(self):
block = blocks.PageChooserBlock()
self.assertEqual(block.target_model, Page)
示例14: test_target_model_string
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import PageChooserBlock [as 別名]
def test_target_model_string(self):
block = blocks.PageChooserBlock(page_type='tests.SimplePage')
self.assertEqual(block.target_model, SimplePage)
示例15: test_target_model_literal
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import PageChooserBlock [as 別名]
def test_target_model_literal(self):
block = blocks.PageChooserBlock(page_type=SimplePage)
self.assertEqual(block.target_model, SimplePage)