本文整理汇总了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)
示例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,
})
示例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 ''
示例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,
})
示例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 ''
示例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 ''
示例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, '')
示例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)
示例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 ''
示例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 ''
示例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
示例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)
示例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 ''
示例14: test_no_finders_available
def test_no_finders_available(self):
with self.assertRaises(EmbedUnsupportedProviderException):
get_embed('www.test.com/1234', max_width=400)
示例15: get_embed
def get_embed(url, max_width=None):
try:
return embeds.get_embed(url, max_width=max_width)
except EmbedException:
return ''