kopia lustrzana https://github.com/wagtail/wagtail
Merge branch 'master' of https://github.com/spapas/wagtail into spapas-master
commit
e7bb62d8ec
|
@ -13,15 +13,18 @@ def get_embed(url, max_width=None):
|
|||
except Embed.DoesNotExist:
|
||||
pass
|
||||
|
||||
# Call embedly API
|
||||
client = Embedly(key=settings.EMBEDLY_KEY)
|
||||
try:
|
||||
# Call embedly API
|
||||
client = Embedly(key=settings.EMBEDLY_KEY)
|
||||
except AttributeError:
|
||||
return None
|
||||
if max_width is not None:
|
||||
oembed = client.oembed(url, maxwidth=max_width, better=False)
|
||||
else:
|
||||
oembed = client.oembed(url, better=False)
|
||||
|
||||
# Check for error
|
||||
if oembed.error:
|
||||
if oembed.get('error'):
|
||||
return None
|
||||
|
||||
# Save result to database
|
||||
|
@ -29,18 +32,18 @@ def get_embed(url, max_width=None):
|
|||
url=url,
|
||||
max_width=max_width,
|
||||
defaults={
|
||||
'type': oembed.type,
|
||||
'title': oembed.title,
|
||||
'thumbnail_url': oembed.thumbnail_url,
|
||||
'width': oembed.width,
|
||||
'height': oembed.height
|
||||
'type': oembed['type'],
|
||||
'title': oembed['title'],
|
||||
'thumbnail_url': oembed.get('thumbnail_url'),
|
||||
'width': oembed.get('width'),
|
||||
'height': oembed.get('height')
|
||||
}
|
||||
)
|
||||
|
||||
if oembed.type == 'photo':
|
||||
html = '<img src="%s" />' % (oembed.url, )
|
||||
if oembed['type'] == 'photo':
|
||||
html = '<img src="%s" />' % (oembed['url'], )
|
||||
else:
|
||||
html = oembed.html
|
||||
html = oembed.get('html')
|
||||
|
||||
if html:
|
||||
row.html = html
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from django.forms.util import ErrorList
|
||||
from django.conf import settings
|
||||
|
||||
from wagtail.wagtailadmin.modal_workflow import render_modal_workflow
|
||||
|
||||
from wagtail.wagtailembeds.forms import EmbedForm
|
||||
from wagtail.wagtailembeds.format import embed_to_editor_html
|
||||
|
||||
|
@ -27,7 +27,10 @@ def chooser_upload(request):
|
|||
)
|
||||
else:
|
||||
errors = form._errors.setdefault('url', ErrorList())
|
||||
errors.append('This URL is not recognised')
|
||||
if not hasattr(settings, 'EMBEDLY_KEY'):
|
||||
errors.append('Please set EMBEDLY_KEY in your settings')
|
||||
else:
|
||||
errors.append('This URL is not recognised')
|
||||
return render_modal_workflow(request, 'wagtailembeds/chooser/chooser.html', 'wagtailembeds/chooser/chooser.js', {
|
||||
'form': form,
|
||||
})
|
||||
|
|
Ładowanie…
Reference in New Issue