mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-25 07:13:46 +00:00
Merge pull request #226 from kaedroho/embeds_author-and-provider-fields
Add author_name and provider_name to Embed
This commit is contained in:
commit
13d546e835
8 changed files with 84 additions and 6 deletions
|
|
@ -17,6 +17,7 @@ Changelog
|
|||
* Added translation for Portuguese Brazil
|
||||
* Made compatible with Python 2.6
|
||||
* 'richtext' template filter now wraps output in <div class="rich-text"></div>, to assist in styling
|
||||
* Embeds now save author_name and provider_name if set by oEmbed provider
|
||||
* Fix: non-ASCII characters in image filenames are now converted into ASCII equivalents rather than becoming all underscores
|
||||
* Fix: paths to fonts and images within CSS are no longer hard-coded to /static/
|
||||
* Fix: Localization files for the JQuery UI datepicker are stored locally and only imported when a localization is known to be available
|
||||
|
|
|
|||
|
|
@ -77,7 +77,9 @@ def embedly(url, max_width=None, key=None):
|
|||
|
||||
# Return embed as a dict
|
||||
return {
|
||||
'title': oembed['title'],
|
||||
'title': oembed['title'] if 'title' in oembed else '',
|
||||
'author_name': oembed['author_name'] if 'author_name' in oembed else '',
|
||||
'provider_name': oembed['provider_name'] if 'provider_name' in oembed else '',
|
||||
'type': oembed['type'],
|
||||
'thumbnail_url': oembed.get('thumbnail_url'),
|
||||
'width': oembed.get('width'),
|
||||
|
|
@ -114,7 +116,9 @@ def oembed(url, max_width=None):
|
|||
|
||||
# Return embed as a dict
|
||||
return {
|
||||
'title': oembed['title'],
|
||||
'title': oembed['title'] if 'title' in oembed else '',
|
||||
'author_name': oembed['author_name'] if 'author_name' in oembed else '',
|
||||
'provider_name': oembed['provider_name'] if 'provider_name' in oembed else '',
|
||||
'type': oembed['type'],
|
||||
'thumbnail_url': oembed.get('thumbnail_url'),
|
||||
'width': oembed.get('width'),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from __future__ import division # Use true division
|
||||
|
||||
from django.utils.html import escape
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
from wagtail.wagtailembeds import get_embed
|
||||
|
||||
|
|
@ -15,8 +16,11 @@ def embed_to_frontend_html(url):
|
|||
else:
|
||||
ratio = "0"
|
||||
|
||||
# Build html
|
||||
return '<div style="padding-bottom: %s;" class="responsive-object">%s</div>' % (ratio, embed.html)
|
||||
# Render template
|
||||
render_to_string('wagtailembeds/embed_frontend.html', {
|
||||
'embed': embed,
|
||||
'ratio': ratio,
|
||||
})
|
||||
else:
|
||||
return ''
|
||||
except:
|
||||
|
|
@ -28,4 +32,7 @@ def embed_to_editor_html(url):
|
|||
if embed is None:
|
||||
return
|
||||
|
||||
return '<div class="embed-placeholder" contenteditable="false" data-embedtype="media" data-url="%s"><h3>%s</h3><p>%s</p><img src="%s"></div>' % (url, escape(embed.title), url, embed.thumbnail_url)
|
||||
# Render template
|
||||
return render_to_string('wagtailembeds/embed_editor.html', {
|
||||
'embed': embed,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from south.utils import datetime_utils as datetime
|
||||
from south.db import db
|
||||
from south.v2 import SchemaMigration
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Migration(SchemaMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
# Adding field 'Embed.author_name'
|
||||
db.add_column(u'wagtailembeds_embed', 'author_name',
|
||||
self.gf('django.db.models.fields.TextField')(default='', blank=True),
|
||||
keep_default=False)
|
||||
|
||||
# Adding field 'Embed.provider_name'
|
||||
db.add_column(u'wagtailembeds_embed', 'provider_name',
|
||||
self.gf('django.db.models.fields.TextField')(default='', blank=True),
|
||||
keep_default=False)
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
# Deleting field 'Embed.author_name'
|
||||
db.delete_column(u'wagtailembeds_embed', 'author_name')
|
||||
|
||||
# Deleting field 'Embed.provider_name'
|
||||
db.delete_column(u'wagtailembeds_embed', 'provider_name')
|
||||
|
||||
|
||||
models = {
|
||||
u'wagtailembeds.embed': {
|
||||
'Meta': {'unique_together': "(('url', 'max_width'),)", 'object_name': 'Embed'},
|
||||
'author_name': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'height': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'html': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'last_updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
|
||||
'max_width': ('django.db.models.fields.SmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'provider_name': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'thumbnail_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
|
||||
'title': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'type': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
|
||||
'url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
|
||||
'width': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['wagtailembeds']
|
||||
|
|
@ -15,6 +15,8 @@ class Embed(models.Model):
|
|||
type = models.CharField(max_length=10, choices=EMBED_TYPES)
|
||||
html = models.TextField(blank=True)
|
||||
title = models.TextField(blank=True)
|
||||
author_name = models.TextField(blank=True)
|
||||
provider_name = models.TextField(blank=True)
|
||||
thumbnail_url = models.URLField(null=True, blank=True)
|
||||
width = models.IntegerField(null=True, blank=True)
|
||||
height = models.IntegerField(null=True, blank=True)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
function(modal) {
|
||||
modal.respond('embedChosen', '{{ embed_html|safe }}');
|
||||
modal.respond('embedChosen', '{{ embed_html|escapejs }}');
|
||||
modal.close();
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<div class="embed-placeholder" contenteditable="false" data-embedtype="media" data-url="{{ embed.url }}">
|
||||
<h3>{{ embed.title }}</h3>
|
||||
<p>URL: {{ embed.url }}</p>
|
||||
{% if embed.provider_name %}
|
||||
<p>Provider: {{ embed.provider_name }}</p>
|
||||
{% endif %}
|
||||
{% if embed.author_name %}
|
||||
<p>Author: {{ embed.author_name }}</p>
|
||||
{% endif %}
|
||||
{% if embed.thumbnail_url %}
|
||||
<img src="{{ embed.thumbnail_url }}" alt="{{ embed.title }}">
|
||||
{% endif %}
|
||||
</div>
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
<div style="padding-bottom: {{ ratio }};" class="responsive-object">
|
||||
{{ embed.html }}
|
||||
</div>
|
||||
Loading…
Reference in a new issue