• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python embeds.get_embed函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中wagtail.wagtailembeds.embeds.get_embed函数的典型用法代码示例。如果您正苦于以下问题:Python get_embed函数的具体用法?Python get_embed怎么用?Python get_embed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_get_embed

    def test_get_embed(self):
        embed = get_embed('www.test.com/1234', max_width=400, finder=self.dummy_finder)

        # Check that the embed is correct
        self.assertEqual(embed.title, "Test: www.test.com/1234")
        self.assertEqual(embed.type, 'video')
        self.assertEqual(embed.width, 400)

        # Check ratio calculations
        self.assertEqual(embed.ratio, 480 / 400)
        self.assertEqual(embed.ratio_css, '120.0%')
        self.assertTrue(embed.is_responsive)

        # Check that there has only been one hit to the backend
        self.assertEqual(self.hit_count, 1)

        # Look for the same embed again and check the hit count hasn't increased
        embed = get_embed('www.test.com/1234', max_width=400, finder=self.dummy_finder)
        self.assertEqual(self.hit_count, 1)

        # Look for a different embed, hit count should increase
        embed = get_embed('www.test.com/4321', max_width=400, finder=self.dummy_finder)
        self.assertEqual(self.hit_count, 2)

        # Look for the same embed with a different width, this should also increase hit count
        embed = get_embed('www.test.com/4321', finder=self.dummy_finder)
        self.assertEqual(self.hit_count, 3)
开发者ID:kapito,项目名称:wagtail,代码行数:27,代码来源:tests.py


示例2: embed_to_editor_html

def embed_to_editor_html(url):
    embed = embeds.get_embed(url)
    # catching EmbedException is the responsibility of the caller

    # Render template
    return render_to_string('wagtailembeds/embed_editor.html', {
        'embed': embed,
    })
开发者ID:kapito,项目名称:wagtail,代码行数:8,代码来源:format.py


示例3: embed

def embed(url, max_width=None):
    embed = get_embed(url, max_width=max_width)
    try:
        if embed is not None:
            return mark_safe(embed.html)
        else:
            return ''
    except:
        return ''
开发者ID:EricSchles,项目名称:wagtail,代码行数:9,代码来源:wagtailembeds_tags.py


示例4: embed_to_editor_html

def embed_to_editor_html(url):
    embed = get_embed(url)
    if embed is None:
        return

    # Render template
    return render_to_string('wagtailembeds/embed_editor.html', {
        'embed': embed,
    })
开发者ID:AustinBurns,项目名称:wagtail,代码行数:9,代码来源:format.py


示例5: embed_to_frontend_html

def embed_to_frontend_html(url):
    try:
        embed = embeds.get_embed(url)

        # Render template
        return render_to_string('wagtailembeds/embed_frontend.html', {
            'embed': embed,
        })
    except EmbedException:
        # silently ignore failed embeds, rather than letting them crash the page
        return ''
开发者ID:kapito,项目名称:wagtail,代码行数:11,代码来源:format.py


示例6: embed_to_editor_html

def embed_to_editor_html(url):
    try:
        embed = embeds.get_embed(url)

        # Render template
        return render_to_string('wagtailembeds/embed_editor.html', {
            'embed': embed,
        })
    except embeds.EmbedException:
        # Could be replaced with a nice error message
        return ''
开发者ID:bjesus,项目名称:wagtail,代码行数:11,代码来源:format.py


示例7: test_no_html

    def test_no_html(self):
        def no_html_finder(url, max_width=None):
            """
            A finder which returns everything but HTML
            """
            embed = self.dummy_finder(url, max_width)
            embed['html'] = None
            return embed

        embed = get_embed('www.test.com/1234', max_width=400, finder=no_html_finder)

        self.assertEqual(embed.html, '')
开发者ID:didorothy,项目名称:wagtail,代码行数:12,代码来源:tests.py


示例8: test_get_embed

    def test_get_embed(self):
        embed = get_embed("www.test.com/1234", max_width=400, finder=self.dummy_finder)

        # Check that the embed is correct
        self.assertEqual(embed.title, "Test: www.test.com/1234")
        self.assertEqual(embed.type, "video")
        self.assertEqual(embed.width, 400)

        # Check that there has only been one hit to the backend
        self.assertEqual(self.hit_count, 1)

        # Look for the same embed again and check the hit count hasn't increased
        embed = get_embed("www.test.com/1234", max_width=400, finder=self.dummy_finder)
        self.assertEqual(self.hit_count, 1)

        # Look for a different embed, hit count should increase
        embed = get_embed("www.test.com/4321", max_width=400, finder=self.dummy_finder)
        self.assertEqual(self.hit_count, 2)

        # Look for the same embed with a different width, this should also increase hit count
        embed = get_embed("www.test.com/4321", finder=self.dummy_finder)
        self.assertEqual(self.hit_count, 3)
开发者ID:carriercomm,项目名称:wagtail,代码行数:22,代码来源:tests.py


示例9: embed_to_frontend_html

def embed_to_frontend_html(url):
    try:
        embed = embeds.get_embed(url)

        # Work out ratio
        if embed.width and embed.height:
            ratio = str(embed.height / embed.width * 100) + "%"
        else:
            ratio = "0"

        # Render template
        return render_to_string('wagtailembeds/embed_frontend.html', {
            'embed': embed,
            'ratio': ratio,
        })
    except embeds.EmbedException:
        return ''
开发者ID:bjesus,项目名称:wagtail,代码行数:17,代码来源:format.py


示例10: embed_to_frontend_html

def embed_to_frontend_html(url):
    try:
        embed = embeds.get_embed(url)

        # Work out ratio
        if embed.width and embed.height:
            ratio = str(embed.height / embed.width * 100) + "%"
        else:
            ratio = "0"

        # Render template
        return render_to_string('wagtailembeds/embed_frontend.html', {
            'embed': embed,
            'ratio': ratio,
        })
    except EmbedException:
        # silently ignore failed embeds, rather than letting them crash the page
        return ''
开发者ID:DimiC,项目名称:wagtail,代码行数:18,代码来源:format.py


示例11: data

    def data(self):
        data = {
            'title': self.title
        }

        prev_page = self.prev_page
        data['prev_url'] = prev_page.url if prev_page else None

        next_page = self.next_page
        data['next_url'] = next_page.url if next_page else None

        data['embed_url'] = self.embed_url

        try:
            # use default SoundCloud embed style for dispatches;
            # bypass overrides in our custom finder in localore/embeds.py
            data['embed_html'] = embeds.get_embed(
                self.embed_url,
                finder=get_default_finder()
            ).html
        except EmbedException:
            data['embed_html'] = ''

        return data
开发者ID:CharleyFarley,项目名称:localore,代码行数:24,代码来源:models.py


示例12: test_invalid_width

    def test_invalid_width(self):
        embed = get_embed('www.test.com/1234', max_width=400, finder=self.dummy_finder_invalid_width)

        # Width must be set to None
        self.assertEqual(embed.width, None)
开发者ID:didorothy,项目名称:wagtail,代码行数:5,代码来源:tests.py


示例13: embed

def embed(url, max_width=None):
    try:
        embed = embeds.get_embed(url, max_width=max_width)
        return mark_safe(embed.html)
    except embeds.EmbedException:
        return ''
开发者ID:Magzhan123,项目名称:TabysKTS,代码行数:6,代码来源:wagtailembeds_tags.py


示例14: test_no_finders_available

 def test_no_finders_available(self):
     with self.assertRaises(EmbedUnsupportedProviderException):
         get_embed('www.test.com/1234', max_width=400)
开发者ID:kapito,项目名称:wagtail,代码行数:3,代码来源:tests.py


示例15: get_embed

def get_embed(url, max_width=None):
    try:
        return embeds.get_embed(url, max_width=max_width)
    except EmbedException:
        return ''
开发者ID:janun,项目名称:janunde,代码行数:5,代码来源:stuff.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python finders.get_default_finder函数代码示例发布时间:2022-05-26
下一篇:
Python blocks.EmbedBlock类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap