Catch EmbedNotFoundExeception fixes #1324

This commit is contained in:
Karl Hobley 2015-06-05 12:50:13 +01:00
parent 225f54ad6c
commit 00d558c9be
3 changed files with 16 additions and 11 deletions

View file

@ -27,11 +27,15 @@ def embed_to_frontend_html(url):
def embed_to_editor_html(url):
embed = embeds.get_embed(url)
if embed is None:
return
try:
embed = embeds.get_embed(url)
if embed is None:
return
# Render template
return render_to_string('wagtailembeds/embed_editor.html', {
'embed': embed,
})
# Render template
return render_to_string('wagtailembeds/embed_editor.html', {
'embed': embed,
})
except embeds.EmbedNotFoundException:
# Could be replaced with a nice error message
return ''

View file

@ -9,5 +9,8 @@ register = template.Library()
@register.filter
def embed(url, max_width=None):
embed = embeds.get_embed(url, max_width=max_width)
return mark_safe(embed.html)
try:
embed = embeds.get_embed(url, max_width=max_width)
return mark_safe(embed.html)
except embeds.EmbedNotFoundException:
return ''

View file

@ -290,7 +290,6 @@ class TestEmbedFilter(TestCase):
self.assertEqual(result, '<img src="http://www.example.com" />')
@unittest.expectedFailure
@patch('wagtail.wagtailembeds.embeds.get_embed')
def test_catches_embed_not_found(self, get_embed):
get_embed.side_effect = EmbedNotFoundException
@ -470,7 +469,6 @@ class TestMediaEmbedHandler(TestCase):
self.assertIn('<p>Author: test author name</p>', result)
self.assertIn('<img src="http://test/thumbnail.url" alt="test title">', result)
@unittest.expectedFailure
@patch('wagtail.wagtailembeds.embeds.get_embed')
def test_test_expand_db_attributes_for_editor_catches_embed_not_found(self, get_embed):
get_embed.side_effect = EmbedNotFoundException