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


Python blocks.ChoiceBlock方法代码示例

本文整理汇总了Python中wagtail.core.blocks.ChoiceBlock方法的典型用法代码示例。如果您正苦于以下问题:Python blocks.ChoiceBlock方法的具体用法?Python blocks.ChoiceBlock怎么用?Python blocks.ChoiceBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wagtail.core.blocks的用法示例。


在下文中一共展示了blocks.ChoiceBlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_subclassing

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import ChoiceBlock [as 别名]
def test_subclassing(self):
        class BeverageChoiceBlock(blocks.ChoiceBlock):
            choices = [
                ('tea', 'Tea'),
                ('coffee', 'Coffee'),
            ]

        block = BeverageChoiceBlock(required=False)
        html = block.render_form('tea', prefix='beverage')
        self.assertTagInHTML('<select id="beverage" name="beverage" placeholder="">', html)
        self.assertInHTML('<option value="tea" selected="selected">Tea</option>', html)

        # subclasses of ChoiceBlock should deconstruct to a basic ChoiceBlock for migrations
        self.assertEqual(
            block.deconstruct(),
            (
                'wagtail.core.blocks.ChoiceBlock',
                [],
                {
                    'choices': [('tea', 'Tea'), ('coffee', 'Coffee')],
                    'required': False,
                },
            )
        ) 
开发者ID:wagtail,项目名称:wagtail,代码行数:26,代码来源:test_blocks.py

示例2: test_optgroup_searchable_content_with_lazy_translation

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import ChoiceBlock [as 别名]
def test_optgroup_searchable_content_with_lazy_translation(self):
        block = blocks.ChoiceBlock(choices=[
            (__('Section 1'), [
                ('1-1', __("Block 1")),
                ('1-2', __("Block 2")),
            ]),
            (__('Section 2'), [
                ('2-1', __("Block 1")),
                ('2-2', __("Block 2")),
            ]),
        ])
        result = block.get_searchable_content("2-2")
        # result must survive JSON (de)serialisation, which is not the case for
        # lazy translation objects
        result = json.loads(json.dumps(result))
        self.assertEqual(result, ["Section 2", "Block 2"]) 
开发者ID:wagtail,项目名称:wagtail,代码行数:18,代码来源:test_blocks.py

示例3: test_deconstruct_with_callable_choices

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import ChoiceBlock [as 别名]
def test_deconstruct_with_callable_choices(self):
        def callable_choices():
            return [
                ('tea', 'Tea'),
                ('coffee', 'Coffee'),
            ]

        block = blocks.ChoiceBlock(choices=callable_choices, required=False)
        html = block.render_form('tea', prefix='beverage')

        self.assertTagInHTML('<select id="beverage" name="beverage" placeholder="">', html)
        self.assertInHTML('<option value="tea" selected="selected">Tea</option>', html)

        self.assertEqual(
            block.deconstruct(),
            (
                'wagtail.core.blocks.ChoiceBlock',
                [],
                {
                    'choices': callable_choices,
                    'required': False,
                },
            )
        ) 
开发者ID:wagtail,项目名称:wagtail,代码行数:26,代码来源:test_blocks.py

示例4: test_choicefield_render

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import ChoiceBlock [as 别名]
def test_choicefield_render(self):
        class ChoiceBlock(blocks.FieldBlock):
            field = forms.ChoiceField(choices=(
                ('choice-1', "Choice 1"),
                ('choice-2', "Choice 2"),
            ))

        block = ChoiceBlock()
        html = block.render('choice-2')

        self.assertEqual(html, "choice-2") 
开发者ID:wagtail,项目名称:wagtail,代码行数:13,代码来源:test_blocks.py

示例5: test_choicefield_render_form

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import ChoiceBlock [as 别名]
def test_choicefield_render_form(self):
        class ChoiceBlock(blocks.FieldBlock):
            field = forms.ChoiceField(choices=(
                ('choice-1', "Choice 1"),
                ('choice-2', "Choice 2"),
            ))

        block = ChoiceBlock()
        html = block.render_form('choice-2')

        self.assertIn('<div class="field choice_field widget-select">', html)
        self.assertTagInHTML('<select id="" name="" placeholder="">', html)
        self.assertInHTML('<option value="choice-1">Choice 1</option>', html)
        self.assertInHTML('<option value="choice-2" selected="selected">Choice 2</option>', html) 
开发者ID:wagtail,项目名称:wagtail,代码行数:16,代码来源:test_blocks.py

示例6: test_render_required_choice_block

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import ChoiceBlock [as 别名]
def test_render_required_choice_block(self):
        block = blocks.ChoiceBlock(choices=[('tea', 'Tea'), ('coffee', 'Coffee')])
        html = block.render_form('coffee', prefix='beverage')
        self.assertTagInHTML('<select id="beverage" name="beverage" placeholder="">', html)
        # blank option should still be rendered for required fields
        # (we may want it as an initial value)
        self.assertIn('<option value="">%s</option>' % self.blank_choice_dash_label, html)
        self.assertIn('<option value="tea">Tea</option>', html)
        self.assertInHTML('<option value="coffee" selected="selected">Coffee</option>', html) 
开发者ID:wagtail,项目名称:wagtail,代码行数:11,代码来源:test_blocks.py

示例7: test_render_required_choice_block_with_default

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import ChoiceBlock [as 别名]
def test_render_required_choice_block_with_default(self):
        block = blocks.ChoiceBlock(choices=[('tea', 'Tea'), ('coffee', 'Coffee')], default='tea')
        html = block.render_form('coffee', prefix='beverage')
        self.assertTagInHTML('<select id="beverage" name="beverage" placeholder="">', html)
        # blank option should NOT be rendered if default and required are set.
        self.assertNotIn('<option value="">%s</option>' % self.blank_choice_dash_label, html)
        self.assertIn('<option value="tea">Tea</option>', html)
        self.assertInHTML('<option value="coffee" selected="selected">Coffee</option>', html) 
开发者ID:wagtail,项目名称:wagtail,代码行数:10,代码来源:test_blocks.py

示例8: test_render_required_choice_block_with_callable_choices

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import ChoiceBlock [as 别名]
def test_render_required_choice_block_with_callable_choices(self):
        def callable_choices():
            return [('tea', 'Tea'), ('coffee', 'Coffee')]

        block = blocks.ChoiceBlock(choices=callable_choices)
        html = block.render_form('coffee', prefix='beverage')
        self.assertTagInHTML('<select id="beverage" name="beverage" placeholder="">', html)
        # blank option should still be rendered for required fields
        # (we may want it as an initial value)
        self.assertIn('<option value="">%s</option>' % self.blank_choice_dash_label, html)
        self.assertIn('<option value="tea">Tea</option>', html)
        self.assertInHTML('<option value="coffee" selected="selected">Coffee</option>', html) 
开发者ID:wagtail,项目名称:wagtail,代码行数:14,代码来源:test_blocks.py

示例9: test_render_non_required_choice_block

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import ChoiceBlock [as 别名]
def test_render_non_required_choice_block(self):
        block = blocks.ChoiceBlock(choices=[('tea', 'Tea'), ('coffee', 'Coffee')], required=False)
        html = block.render_form('coffee', prefix='beverage')
        self.assertTagInHTML('<select id="beverage" name="beverage" placeholder="">', html)
        self.assertIn('<option value="">%s</option>' % self.blank_choice_dash_label, html)
        self.assertIn('<option value="tea">Tea</option>', html)
        self.assertInHTML('<option value="coffee" selected="selected">Coffee</option>', html) 
开发者ID:wagtail,项目名称:wagtail,代码行数:9,代码来源:test_blocks.py

示例10: test_render_non_required_choice_block_with_callable_choices

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import ChoiceBlock [as 别名]
def test_render_non_required_choice_block_with_callable_choices(self):
        def callable_choices():
            return [('tea', 'Tea'), ('coffee', 'Coffee')]

        block = blocks.ChoiceBlock(choices=callable_choices, required=False)
        html = block.render_form('coffee', prefix='beverage')
        self.assertTagInHTML('<select id="beverage" name="beverage" placeholder="">', html)
        self.assertIn('<option value="">%s</option>' % self.blank_choice_dash_label, html)
        self.assertIn('<option value="tea">Tea</option>', html)
        self.assertInHTML('<option value="coffee" selected="selected">Coffee</option>', html) 
开发者ID:wagtail,项目名称:wagtail,代码行数:12,代码来源:test_blocks.py

示例11: test_validate_non_required_choice_block

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import ChoiceBlock [as 别名]
def test_validate_non_required_choice_block(self):
        block = blocks.ChoiceBlock(choices=[('tea', 'Tea'), ('coffee', 'Coffee')], required=False)
        self.assertEqual(block.clean('coffee'), 'coffee')

        with self.assertRaises(ValidationError):
            block.clean('whisky')

        self.assertEqual(block.clean(''), '')
        self.assertEqual(block.clean(None), '') 
开发者ID:wagtail,项目名称:wagtail,代码行数:11,代码来源:test_blocks.py

示例12: test_render_choice_block_with_existing_blank_choice

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import ChoiceBlock [as 别名]
def test_render_choice_block_with_existing_blank_choice(self):
        block = blocks.ChoiceBlock(
            choices=[('tea', 'Tea'), ('coffee', 'Coffee'), ('', 'No thanks')],
            required=False)
        html = block.render_form(None, prefix='beverage')
        self.assertTagInHTML('<select id="beverage" name="beverage" placeholder="">', html)
        self.assertNotIn('<option value="">%s</option>' % self.blank_choice_dash_label, html)
        self.assertInHTML('<option value="" selected="selected">No thanks</option>', html)
        self.assertIn('<option value="tea">Tea</option>', html)
        self.assertInHTML('<option value="coffee">Coffee</option>', html) 
开发者ID:wagtail,项目名称:wagtail,代码行数:12,代码来源:test_blocks.py

示例13: test_render_choice_block_with_existing_blank_choice_and_with_callable_choices

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import ChoiceBlock [as 别名]
def test_render_choice_block_with_existing_blank_choice_and_with_callable_choices(self):
        def callable_choices():
            return [('tea', 'Tea'), ('coffee', 'Coffee'), ('', 'No thanks')]

        block = blocks.ChoiceBlock(
            choices=callable_choices,
            required=False)
        html = block.render_form(None, prefix='beverage')
        self.assertTagInHTML('<select id="beverage" name="beverage" placeholder="">', html)
        self.assertNotIn('<option value="">%s</option>' % self.blank_choice_dash_label, html)
        self.assertInHTML('<option value="" selected="selected">No thanks</option>', html)
        self.assertIn('<option value="tea">Tea</option>', html)
        self.assertIn('<option value="coffee">Coffee</option>', html) 
开发者ID:wagtail,项目名称:wagtail,代码行数:15,代码来源:test_blocks.py

示例14: test_named_groups_with_blank_option

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import ChoiceBlock [as 别名]
def test_named_groups_with_blank_option(self):
        block = blocks.ChoiceBlock(
            choices=[
                ('Alcoholic', [
                    ('gin', 'Gin'),
                    ('whisky', 'Whisky'),
                ]),
                ('Non-alcoholic', [
                    ('tea', 'Tea'),
                    ('coffee', 'Coffee'),
                ]),
                ('Not thirsty', [
                    ('', 'No thanks')
                ]),
            ],
            required=False)

        # test rendering with the blank option selected
        html = block.render_form(None, prefix='beverage')
        self.assertTagInHTML('<select id="beverage" name="beverage" placeholder="">', html)
        self.assertNotIn('<option value="">%s</option>' % self.blank_choice_dash_label, html)
        self.assertNotInHTML('<option value="" selected="selected">%s</option>' % self.blank_choice_dash_label, html)
        self.assertIn('<optgroup label="Alcoholic">', html)
        self.assertIn('<option value="tea">Tea</option>', html)
        self.assertInHTML('<option value="" selected="selected">No thanks</option>', html)

        # test rendering with a non-blank option selected
        html = block.render_form('tea', prefix='beverage')
        self.assertTagInHTML('<select id="beverage" name="beverage" placeholder="">', html)
        self.assertNotIn('<option value="">%s</option>' % self.blank_choice_dash_label, html)
        self.assertNotInHTML('<option value="" selected="selected">%s</option>' % self.blank_choice_dash_label, html)
        self.assertIn('<optgroup label="Alcoholic">', html)
        self.assertInHTML('<option value="tea" selected="selected">Tea</option>', html) 
开发者ID:wagtail,项目名称:wagtail,代码行数:35,代码来源:test_blocks.py

示例15: test_searchable_content

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import ChoiceBlock [as 别名]
def test_searchable_content(self):
        block = blocks.ChoiceBlock(choices=[
            ('choice-1', "Choice 1"),
            ('choice-2', "Choice 2"),
        ])
        self.assertEqual(block.get_searchable_content("choice-1"),
                         ["Choice 1"]) 
开发者ID:wagtail,项目名称:wagtail,代码行数:9,代码来源:test_blocks.py


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