当前位置: 首页>>代码示例>>Python>>正文


Python blocks.PageChooserBlock方法代码示例

本文整理汇总了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) 
开发者ID:wagtail,项目名称:wagtail,代码行数:25,代码来源:test_blocks.py

示例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) 
开发者ID:wagtail,项目名称:wagtail,代码行数:29,代码来源:test_blocks.py

示例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) 
开发者ID:wagtail,项目名称:wagtail,代码行数:11,代码来源:test_blocks.py

示例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) 
开发者ID:wagtail,项目名称:wagtail,代码行数:11,代码来源:test_blocks.py

示例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) 
开发者ID:wagtail,项目名称:wagtail,代码行数:11,代码来源:test_blocks.py

示例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) 
开发者ID:wagtail,项目名称:wagtail,代码行数:6,代码来源:test_blocks.py

示例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) 
开发者ID:wagtail,项目名称:wagtail,代码行数:6,代码来源:test_blocks.py

示例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) 
开发者ID:wagtail,项目名称:wagtail,代码行数:6,代码来源:test_blocks.py

示例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) 
开发者ID:wagtail,项目名称:wagtail,代码行数:6,代码来源:test_blocks.py

示例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) 
开发者ID:wagtail,项目名称:wagtail,代码行数:6,代码来源:test_blocks.py

示例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) 
开发者ID:wagtail,项目名称:wagtail,代码行数:11,代码来源:test_blocks.py

示例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) 
开发者ID:wagtail,项目名称:wagtail,代码行数:13,代码来源:test_blocks.py

示例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) 
开发者ID:wagtail,项目名称:wagtail,代码行数:5,代码来源:test_blocks.py

示例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) 
开发者ID:wagtail,项目名称:wagtail,代码行数:5,代码来源:test_blocks.py

示例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) 
开发者ID:wagtail,项目名称:wagtail,代码行数:5,代码来源:test_blocks.py


注:本文中的wagtail.core.blocks.PageChooserBlock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。