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


Python blocks.RichTextBlock方法代码示例

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


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

示例1: test_features_list_on_rich_text_block

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import RichTextBlock [as 别名]
def test_features_list_on_rich_text_block(self):
        block = RichTextBlock(features=['quotation', 'embed', 'made-up-feature'])

        form_html = block.render_form(block.to_python("<p>hello</p>"), 'body')

        # Check that the custom plugin options are being passed in the hallo initialiser
        self.assertIn('"halloquotation":', form_html)
        self.assertIn('"hallowagtailembeds":', form_html)
        self.assertNotIn('"hallolists":', form_html)
        self.assertNotIn('"hallowagtailimage":', form_html)

        # check that media (js/css) from the features is being imported
        media_html = str(block.media)
        self.assertIn('testapp/js/hallo-quotation.js', media_html)
        self.assertIn('testapp/css/hallo-quotation.css', media_html)
        # check that we're NOT importing media for the default features we're not using
        self.assertNotIn('wagtaildocs/js/hallo-plugins/hallo-wagtaildoclink.js', media_html) 
开发者ID:wagtail,项目名称:wagtail,代码行数:19,代码来源:test_rich_text.py

示例2: test_value_property

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import RichTextBlock [as 别名]
def test_value_property(self):

        class SectionStructValue(blocks.StructValue):
            @property
            def foo(self):
                return 'bar %s' % self.get('title', '')

        class SectionBlock(blocks.StructBlock):
            title = blocks.CharBlock()
            body = blocks.RichTextBlock()

            class Meta:
                value_class = SectionStructValue

        block = SectionBlock()
        struct_value = block.to_python({'title': 'hello', 'body': '<b>world</b>'})
        value = struct_value.foo
        self.assertEqual(value, 'bar hello') 
开发者ID:wagtail,项目名称:wagtail,代码行数:20,代码来源:test_blocks.py

示例3: test_system_checks_recurse_into_lists

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import RichTextBlock [as 别名]
def test_system_checks_recurse_into_lists(self):
        failing_block = blocks.RichTextBlock()
        block = blocks.StreamBlock([
            ('paragraph_list', blocks.ListBlock(
                blocks.StructBlock([
                    ('heading', blocks.CharBlock()),
                    ('rich text', failing_block),
                ])
            ))
        ])

        errors = block.check()
        self.assertEqual(len(errors), 1)
        self.assertEqual(errors[0].id, 'wagtailcore.E001')
        self.assertEqual(errors[0].hint, "Block names cannot contain spaces")
        self.assertEqual(errors[0].obj, failing_block) 
开发者ID:wagtail,项目名称:wagtail,代码行数:18,代码来源:test_blocks.py

示例4: test_system_checks_recurse_into_streams

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import RichTextBlock [as 别名]
def test_system_checks_recurse_into_streams(self):
        failing_block = blocks.RichTextBlock()
        block = blocks.StreamBlock([
            ('carousel', blocks.StreamBlock([
                ('text', blocks.StructBlock([
                    ('heading', blocks.CharBlock()),
                    ('rich text', failing_block),
                ]))
            ]))
        ])

        errors = block.check()
        self.assertEqual(len(errors), 1)
        self.assertEqual(errors[0].id, 'wagtailcore.E001')
        self.assertEqual(errors[0].hint, "Block names cannot contain spaces")
        self.assertEqual(errors[0].obj, failing_block) 
开发者ID:wagtail,项目名称:wagtail,代码行数:18,代码来源:test_blocks.py

示例5: test_system_checks_recurse_into_structs

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import RichTextBlock [as 别名]
def test_system_checks_recurse_into_structs(self):
        failing_block_1 = blocks.RichTextBlock()
        failing_block_2 = blocks.RichTextBlock()
        block = blocks.StreamBlock([
            ('two_column', blocks.StructBlock([
                ('left', blocks.StructBlock([
                    ('heading', blocks.CharBlock()),
                    ('rich text', failing_block_1),
                ])),
                ('right', blocks.StructBlock([
                    ('heading', blocks.CharBlock()),
                    ('rich text', failing_block_2),
                ]))
            ]))
        ])

        errors = block.check()
        self.assertEqual(len(errors), 2)
        self.assertEqual(errors[0].id, 'wagtailcore.E001')
        self.assertEqual(errors[0].hint, "Block names cannot contain spaces")
        self.assertEqual(errors[0].obj, failing_block_1)
        self.assertEqual(errors[1].id, 'wagtailcore.E001')
        self.assertEqual(errors[1].hint, "Block names cannot contain spaces")
        self.assertEqual(errors[1].obj, failing_block_2) 
开发者ID:wagtail,项目名称:wagtail,代码行数:26,代码来源:test_blocks.py

示例6: __init__

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import RichTextBlock [as 别名]
def __init__(self, *args, **kwargs):
        if "default" not in kwargs:
            kwargs["default"] = None

        super().__init__(
            [
                ("paragraph", RichTextBlock(features=RICH_TEXT_FEATURES)),
                ("image", ImageChooserBlock()),
                ("button", ButtonBlock()),
                ("embed", EmbedBlock()),
                (
                    "embed_html",
                    RawHTMLBlock(
                        help_text=(
                            "Warning: be careful what you paste here, since this "
                            "field could introduce XSS (or similar) bugs. "
                            "This field is meant solely for third-party embeds."
                        )
                    ),
                ),
                ("code_snippet", CodeSnippetBlock()),
            ],
            **kwargs
        ) 
开发者ID:mdn,项目名称:developer-portal,代码行数:26,代码来源:fields.py

示例7: test_custom_editor_in_rich_text_block

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import RichTextBlock [as 别名]
def test_custom_editor_in_rich_text_block(self):
        block = RichTextBlock(editor='custom')

        form_html = block.render_form(block.to_python("<p>hello</p>"), 'body')

        # Check that the custom plugin options are being passed in the hallo initialiser
        self.assertIn('makeHalloRichTextEditable("body", {"halloheadings": {"formatBlocks": ["p", "h2"]}});', form_html) 
开发者ID:wagtail,项目名称:wagtail,代码行数:9,代码来源:test_rich_text.py

示例8: test_features_option_on_rich_text_block

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import RichTextBlock [as 别名]
def test_features_option_on_rich_text_block(self):
        # a 'features' list passed on the RichTextBlock
        # should override the list in OPTIONS
        block = RichTextBlock(features=['h2', 'embed'])

        form_html = block.render_form(block.to_python("<p>hello</p>"), 'body')

        self.assertIn('"type": "header-two"', form_html)
        self.assertIn('"type": "EMBED"', form_html)
        self.assertNotIn('"type": "IMAGE""', form_html)
        self.assertNotIn('"type": "ordered-list-item""', form_html) 
开发者ID:wagtail,项目名称:wagtail,代码行数:13,代码来源:test_rich_text.py

示例9: test_custom_features_option_on_rich_text_block

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import RichTextBlock [as 别名]
def test_custom_features_option_on_rich_text_block(self):
        block = RichTextBlock(editor='custom')

        form_html = block.render_form(block.to_python("<p>hello</p>"), 'body')

        # Check that the custom plugin options are being passed in the hallo initialiser
        self.assertIn('"halloquotation":', form_html)
        self.assertIn('"hallowagtailimage":', form_html)
        self.assertNotIn('"hallowagtailembeds":', form_html)
        self.assertNotIn('"hallolists":', form_html)

        # a 'features' list passed on the RichTextBlock
        # should override the list in OPTIONS
        block = RichTextBlock(editor='custom', features=['quotation', 'embed'])

        form_html = block.render_form(block.to_python("<p>hello</p>"), 'body')

        self.assertIn('"halloquotation":', form_html)
        self.assertIn('"hallowagtailembeds":', form_html)
        self.assertNotIn('"hallowagtailimage":', form_html)
        self.assertNotIn('"hallolists":', form_html)

        # check that media (js/css) from the features is being imported
        media_html = str(block.media)
        self.assertIn('testapp/js/hallo-quotation.js', media_html)
        self.assertIn('testapp/css/hallo-quotation.css', media_html)
        # check that we're NOT importing media for the default features we're not using
        self.assertNotIn('wagtaildocs/js/hallo-plugins/hallo-wagtaildoclink.js', media_html) 
开发者ID:wagtail,项目名称:wagtail,代码行数:30,代码来源:test_rich_text.py

示例10: get_comparison_class_for_block

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import RichTextBlock [as 别名]
def get_comparison_class_for_block(block):
    if hasattr(block, 'get_comparison_class'):
        return block.get_comparison_class()
    elif isinstance(block, (blocks.CharBlock, blocks.TextBlock)):
        return CharBlockComparison
    elif isinstance(block, blocks.RawHTMLBlock):
        # Compare raw HTML blocks as if they were plain text, so that tags are shown explicitly
        return CharBlockComparison
    elif isinstance(block, blocks.RichTextBlock):
        return RichTextBlockComparison
    elif isinstance(block, blocks.StructBlock):
        return StructBlockComparison
    else:
        # As all stream field blocks have a HTML representation, fall back to diffing that.
        return RichTextBlockComparison 
开发者ID:wagtail,项目名称:wagtail,代码行数:17,代码来源:compare.py

示例11: test_get_default_with_fallback_value

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import RichTextBlock [as 别名]
def test_get_default_with_fallback_value(self):
        default_value = blocks.RichTextBlock().get_default()
        self.assertIsInstance(default_value, RichText)
        self.assertEqual(default_value.source, '') 
开发者ID:wagtail,项目名称:wagtail,代码行数:6,代码来源:test_blocks.py

示例12: test_get_default_with_default_none

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import RichTextBlock [as 别名]
def test_get_default_with_default_none(self):
        default_value = blocks.RichTextBlock(default=None).get_default()
        self.assertIsInstance(default_value, RichText)
        self.assertEqual(default_value.source, '') 
开发者ID:wagtail,项目名称:wagtail,代码行数:6,代码来源:test_blocks.py

示例13: test_get_default_with_empty_string

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import RichTextBlock [as 别名]
def test_get_default_with_empty_string(self):
        default_value = blocks.RichTextBlock(default='').get_default()
        self.assertIsInstance(default_value, RichText)
        self.assertEqual(default_value.source, '') 
开发者ID:wagtail,项目名称:wagtail,代码行数:6,代码来源:test_blocks.py

示例14: test_get_default_with_nonempty_string

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import RichTextBlock [as 别名]
def test_get_default_with_nonempty_string(self):
        default_value = blocks.RichTextBlock(default='<p>foo</p>').get_default()
        self.assertIsInstance(default_value, RichText)
        self.assertEqual(default_value.source, '<p>foo</p>') 
开发者ID:wagtail,项目名称:wagtail,代码行数:6,代码来源:test_blocks.py

示例15: test_get_default_with_richtext_value

# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import RichTextBlock [as 别名]
def test_get_default_with_richtext_value(self):
        default_value = blocks.RichTextBlock(default=RichText('<p>foo</p>')).get_default()
        self.assertIsInstance(default_value, RichText)
        self.assertEqual(default_value.source, '<p>foo</p>') 
开发者ID:wagtail,项目名称:wagtail,代码行数:6,代码来源:test_blocks.py


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