mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Merge pull request #1888 from gasman/fix/report-embed-errors
Ensure errors in embed chooser are propagated back to the form
This commit is contained in:
commit
8ca01a8428
@ -21,17 +21,15 @@ def embed_to_frontend_html(url):
|
||||
'ratio': ratio,
|
||||
})
|
||||
except embeds.EmbedException:
|
||||
# silently ignore failed embeds, rather than letting them crash the page
|
||||
return ''
|
||||
|
||||
|
||||
def embed_to_editor_html(url):
|
||||
try:
|
||||
embed = embeds.get_embed(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,
|
||||
})
|
||||
except embeds.EmbedException:
|
||||
# Could be replaced with a nice error message
|
||||
return ''
|
||||
# Render template
|
||||
return render_to_string('wagtailembeds/embed_editor.html', {
|
||||
'embed': embed,
|
||||
})
|
||||
|
@ -1,4 +1,4 @@
|
||||
from wagtail.wagtailembeds import format
|
||||
from wagtail.wagtailembeds import format, embeds
|
||||
|
||||
|
||||
class MediaEmbedHandler(object):
|
||||
@ -26,6 +26,10 @@ class MediaEmbedHandler(object):
|
||||
representation.
|
||||
"""
|
||||
if for_editor:
|
||||
return format.embed_to_editor_html(attrs['url'])
|
||||
try:
|
||||
return format.embed_to_editor_html(attrs['url'])
|
||||
except embeds.EmbedException:
|
||||
# Could be replaced with a nice error message
|
||||
return ''
|
||||
else:
|
||||
return format.embed_to_frontend_html(attrs['url'])
|
||||
|
@ -12,6 +12,7 @@ import django.utils.six.moves.urllib.request
|
||||
from django import template
|
||||
from django.test import TestCase
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.six.moves.urllib.error import URLError
|
||||
|
||||
from wagtail.wagtailcore import blocks
|
||||
@ -112,7 +113,28 @@ class TestChooser(TestCase, WagtailTestUtils):
|
||||
r = self.client.get('/admin/embeds/chooser/')
|
||||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
# TODO: Test submitting
|
||||
@patch('wagtail.wagtailembeds.embeds.get_embed')
|
||||
def test_submit_valid_embed(self, get_embed):
|
||||
get_embed.return_value = Embed(html='<img src="http://www.example.com" />', title="An example embed")
|
||||
|
||||
response = self.client.post(reverse('wagtailembeds:chooser_upload'), {
|
||||
'url': 'http://www.example.com/'
|
||||
})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, """modal.respond('embedChosen'""")
|
||||
self.assertContains(response, """An example embed""")
|
||||
|
||||
@patch('wagtail.wagtailembeds.embeds.get_embed')
|
||||
def test_submit_unrecognised_embed(self, get_embed):
|
||||
get_embed.side_effect = EmbedNotFoundException
|
||||
|
||||
response = self.client.post(reverse('wagtailembeds:chooser_upload'), {
|
||||
'url': 'http://www.example.com/'
|
||||
})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertNotContains(response, """modal.respond('embedChosen'""")
|
||||
self.assertContains(response, """Cannot find an embed for this URL.""")
|
||||
|
||||
|
||||
class TestEmbedly(TestCase):
|
||||
@unittest.skipIf(no_embedly, "Embedly is not installed")
|
||||
|
@ -8,7 +8,6 @@ from wagtail.wagtailembeds.format import embed_to_editor_html
|
||||
from wagtail.wagtailembeds.embeds import EmbedNotFoundException, EmbedlyException, AccessDeniedEmbedlyException
|
||||
|
||||
|
||||
|
||||
def chooser(request):
|
||||
form = EmbedForm()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user