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


Python blocks.EmbedBlock方法代码示例

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


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

示例1: test_render_within_structblock

# 需要导入模块: from wagtail.embeds import blocks [as 别名]
# 或者: from wagtail.embeds.blocks import EmbedBlock [as 别名]
def test_render_within_structblock(self, get_embed):
        """
        When rendering the value of an EmbedBlock directly in a template
        (as happens when accessing it as a child of a StructBlock), the
        proper embed output should be rendered, not the URL.
        """
        get_embed.return_value = Embed(html='<h1>Hello world!</h1>')

        block = blocks.StructBlock([
            ('title', blocks.CharBlock()),
            ('embed', EmbedBlock()),
        ])

        block_val = block.to_python({'title': 'A test', 'embed': 'http://www.example.com/foo'})

        temp = template.Template('embed: {{ self.embed }}')
        context = template.Context({'self': block_val})
        result = temp.render(context)

        self.assertIn('<h1>Hello world!</h1>', result)

        # Check that get_embed was called correctly
        get_embed.assert_any_call('http://www.example.com/foo') 
开发者ID:wagtail,项目名称:wagtail,代码行数:25,代码来源:test_embeds.py

示例2: test_default

# 需要导入模块: from wagtail.embeds import blocks [as 别名]
# 或者: from wagtail.embeds.blocks import EmbedBlock [as 别名]
def test_default(self):
        block1 = EmbedBlock()
        self.assertEqual(block1.get_default(), None)

        block2 = EmbedBlock(default='')
        self.assertEqual(block2.get_default(), None)

        block3 = EmbedBlock(default=None)
        self.assertEqual(block3.get_default(), None)

        block4 = EmbedBlock(default='http://www.example.com/foo')
        self.assertIsInstance(block4.get_default(), EmbedValue)
        self.assertEqual(block4.get_default().url, 'http://www.example.com/foo')

        block5 = EmbedBlock(default=EmbedValue('http://www.example.com/foo'))
        self.assertIsInstance(block5.get_default(), EmbedValue)
        self.assertEqual(block5.get_default().url, 'http://www.example.com/foo') 
开发者ID:wagtail,项目名称:wagtail,代码行数:19,代码来源:test_embeds.py

示例3: __init__

# 需要导入模块: from wagtail.embeds import blocks [as 别名]
# 或者: from wagtail.embeds.blocks import EmbedBlock [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

示例4: test_deserialize

# 需要导入模块: from wagtail.embeds import blocks [as 别名]
# 或者: from wagtail.embeds.blocks import EmbedBlock [as 别名]
def test_deserialize(self):
        """
        Deserialising the JSONish value of an EmbedBlock (a URL) should give us an EmbedValue
        for that URL
        """
        block = EmbedBlock(required=False)

        block_val = block.to_python('http://www.example.com/foo')
        self.assertIsInstance(block_val, EmbedValue)
        self.assertEqual(block_val.url, 'http://www.example.com/foo')

        # empty values should yield None
        empty_block_val = block.to_python('')
        self.assertEqual(empty_block_val, None) 
开发者ID:wagtail,项目名称:wagtail,代码行数:16,代码来源:test_embeds.py

示例5: test_serialize

# 需要导入模块: from wagtail.embeds import blocks [as 别名]
# 或者: from wagtail.embeds.blocks import EmbedBlock [as 别名]
def test_serialize(self):
        block = EmbedBlock(required=False)

        block_val = EmbedValue('http://www.example.com/foo')
        serialized_val = block.get_prep_value(block_val)
        self.assertEqual(serialized_val, 'http://www.example.com/foo')

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

示例6: test_render

# 需要导入模块: from wagtail.embeds import blocks [as 别名]
# 或者: from wagtail.embeds.blocks import EmbedBlock [as 别名]
def test_render(self, get_embed):
        get_embed.return_value = Embed(html='<h1>Hello world!</h1>')

        block = EmbedBlock()
        block_val = block.to_python('http://www.example.com/foo')

        temp = template.Template('embed: {{ embed }}')
        context = template.Context({'embed': block_val})
        result = temp.render(context)

        # Check that the embed was in the returned HTML
        self.assertIn('<h1>Hello world!</h1>', result)

        # Check that get_embed was called correctly
        get_embed.assert_any_call('http://www.example.com/foo') 
开发者ID:wagtail,项目名称:wagtail,代码行数:17,代码来源:test_embeds.py

示例7: test_render_form

# 需要导入模块: from wagtail.embeds import blocks [as 别名]
# 或者: from wagtail.embeds.blocks import EmbedBlock [as 别名]
def test_render_form(self):
        """
        The form field for an EmbedBlock should be a text input containing
        the URL
        """
        block = EmbedBlock()

        form_html = block.render_form(EmbedValue('http://www.example.com/foo'), prefix='myembed')
        self.assertIn('<input ', form_html)
        self.assertIn('value="http://www.example.com/foo"', form_html) 
开发者ID:wagtail,项目名称:wagtail,代码行数:12,代码来源:test_embeds.py

示例8: test_clean_required

# 需要导入模块: from wagtail.embeds import blocks [as 别名]
# 或者: from wagtail.embeds.blocks import EmbedBlock [as 别名]
def test_clean_required(self, get_embed):
        get_embed.return_value = Embed(html='<h1>Hello world!</h1>')

        block = EmbedBlock()

        cleaned_value = block.clean(
            EmbedValue('https://www.youtube.com/watch?v=_U79Wc965vw'))
        self.assertIsInstance(cleaned_value, EmbedValue)
        self.assertEqual(cleaned_value.url,
                         'https://www.youtube.com/watch?v=_U79Wc965vw')

        with self.assertRaisesMessage(ValidationError, ''):
            block.clean(None) 
开发者ID:wagtail,项目名称:wagtail,代码行数:15,代码来源:test_embeds.py

示例9: test_clean_non_required

# 需要导入模块: from wagtail.embeds import blocks [as 别名]
# 或者: from wagtail.embeds.blocks import EmbedBlock [as 别名]
def test_clean_non_required(self, get_embed):
        get_embed.return_value = Embed(html='<h1>Hello world!</h1>')

        block = EmbedBlock(required=False)

        cleaned_value = block.clean(
            EmbedValue('https://www.youtube.com/watch?v=_U79Wc965vw'))
        self.assertIsInstance(cleaned_value, EmbedValue)
        self.assertEqual(cleaned_value.url,
                         'https://www.youtube.com/watch?v=_U79Wc965vw')

        cleaned_value = block.clean(None)
        self.assertIsNone(cleaned_value) 
开发者ID:wagtail,项目名称:wagtail,代码行数:15,代码来源:test_embeds.py

示例10: test_clean_invalid_url

# 需要导入模块: from wagtail.embeds import blocks [as 别名]
# 或者: from wagtail.embeds.blocks import EmbedBlock [as 别名]
def test_clean_invalid_url(self, get_embed):
        get_embed.side_effect = EmbedNotFoundException

        non_required_block = EmbedBlock(required=False)

        with self.assertRaises(ValidationError):
            non_required_block.clean(
                EmbedValue('http://no-oembed-here.com/something'))

        required_block = EmbedBlock()

        with self.assertRaises(ValidationError):
            required_block.clean(
                EmbedValue('http://no-oembed-here.com/something')) 
开发者ID:wagtail,项目名称:wagtail,代码行数:16,代码来源:test_embeds.py

示例11: serialise_block

# 需要导入模块: from wagtail.embeds import blocks [as 别名]
# 或者: from wagtail.embeds.blocks import EmbedBlock [as 别名]
def serialise_block(self, block, value):
        if hasattr(block, 'to_graphql_representation'):
            return block.to_graphql_representation(value)
        elif isinstance(block, blocks.RichTextBlock):
            return serialize_rich_text(value.source)
        elif isinstance(block, EmbedBlock):
            try:
                embed = get_embed(value.url)
                return {
                    'html': embed.html,
                    'url': value.url,
                }
            except EmbedException:
                return {
                    'html': '',
                    'url': None
                }
        elif isinstance(block, ImageChooserBlock):
            # FIXME
            return {
                'id': value.id,
                'alt': value.title,
                'src': settings.MEDIA_PREFIX + value.file.url,
                'hash': value.get_file_hash()
            }
        elif isinstance(block, blocks.FieldBlock):
            return value
        elif isinstance(block, blocks.StructBlock):
            return self.serialise_struct_block(block, value)
        elif isinstance(block, blocks.ListBlock):
            return self.serialise_list_block(block, value)
        elif isinstance(block, blocks.StreamBlock):
            return self.serialise_stream_block(block, value) 
开发者ID:torchbox,项目名称:wagtail-torchbox,代码行数:35,代码来源:streamfield.py


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