Merge branch 'master' of github.com:torchbox/wagtail into docs

pull/256/head
Jeffrey Hearn 2014-05-13 19:00:50 -04:00
commit b42a0d2cf0
9 zmienionych plików z 128 dodań i 43 usunięć

Wyświetl plik

@ -1,3 +1,15 @@
var halloPlugins = {
'halloformat': {},
'halloheadings': {formatBlocks: ["p", "h2", "h3", "h4", "h5"]},
'hallolists': {},
'hallohr': {},
'halloreundo': {},
'hallowagtaillink': {},
};
function registerHalloPlugin(name, opts) {
halloPlugins[name] = (opts || {});
}
function makeRichTextEditable(id) {
var input = $('#' + id);
var richText = $('<div class="richtext"></div>').html(input.val());
@ -19,17 +31,7 @@ function makeRichTextEditable(id) {
richText.hallo({
toolbar: 'halloToolbarFixed',
toolbarcssClass: 'testy',
plugins: {
'halloformat': {},
'halloheadings': {formatBlocks: ["p", "h2", "h3", "h4", "h5"]},
'hallolists': {},
'hallohr': {},
'halloreundo': {},
'hallowagtailimage': {},
'hallowagtailembeds': {},
'hallowagtaillink': {},
'hallowagtaildoclink': {}
}
plugins: halloPlugins
}).bind('hallomodified', function(event, data) {
input.val(data.content);
if (!removeStylingPending) {

Wyświetl plik

@ -4,11 +4,6 @@
CSS declarations to be included on the 'create page' and 'edit page' views
{% endcomment %}
{% comment %}
TODO: have a mechanism for sub-apps to specify their own declarations -
ideally wagtailadmin shouldn't have to know anything at all about wagtailimages and friends
{% endcomment %}
{% compress css %}
<link rel="stylesheet" href="{{ STATIC_URL }}wagtailadmin/scss/layouts/page-editor.scss" type="text/x-scss" />
<link rel="stylesheet" href="{{ STATIC_URL }}wagtailadmin/scss/panels/rich-text.scss" type="text/x-scss" />

Wyświetl plik

@ -4,6 +4,11 @@
Javascript declarations to be included on the 'create page' and 'edit page' views
{% endcomment %}
<script>
window.chooserUrls = {
'pageChooser': '{% url "wagtailadmin_choose_page" %}'
};
</script>
{% compress js %}
<script src="{{ STATIC_URL }}wagtailadmin/js/vendor/rangy-core.js"></script>
@ -14,21 +19,9 @@
<script src="{{ STATIC_URL }}wagtailadmin/js/hallo-plugins/hallo-wagtail-toolbar.js"></script>
<script src="{{ STATIC_URL }}wagtailadmin/js/hallo-plugins/hallo-wagtaillink.js"></script>
<script src="{{ STATIC_URL }}wagtailadmin/js/hallo-plugins/hallo-hr.js"></script>
<script src="{{ STATIC_URL }}wagtailimages/js/hallo-plugins/hallo-wagtailimage.js"></script>
<script src="{{ STATIC_URL }}wagtailembeds/js/hallo-plugins/hallo-wagtailembeds.js"></script>
<script src="{{ STATIC_URL }}wagtaildocs/js/hallo-plugins/hallo-wagtaildoclink.js"></script>
<script src="{{ STATIC_URL }}wagtailadmin/js/page-editor.js"></script>
<script src="{{ STATIC_URL }}wagtailadmin/js/page-chooser.js"></script>
{% comment %}
TODO: use the insert_editor_js hook to inject things like image-chooser.js and hallo-wagtailimage.js
from their respective apps such as wagtailimages -
ideally wagtailadmin shouldn't have to know anything at all about wagtailimages.
TODO: a method of injecting these sorts of things on demand when the modal is spawned.
{% endcomment %}
<script src="{{ STATIC_URL }}wagtailimages/js/image-chooser.js"></script>
<script src="{{ STATIC_URL }}wagtaildocs/js/document-chooser.js"></script>
<script src="{{ STATIC_URL }}wagtailsnippets/js/snippet-chooser.js"></script>
<script src="{{ STATIC_URL }}admin/js/urlify.js"></script>
{% hook_output 'insert_editor_js' %}
@ -41,19 +34,10 @@
{% comment %}
Additional js from widgets media. Allows for custom widgets in admin panel.
Can be used for TODO above (including image-choser.js at wagtailimages)
{% endcomment %}
{{ edit_handler.form.media.js }}
<script>
window.chooserUrls = {
'documentChooser': '{% url "wagtaildocs_chooser" %}',
'imageChooser': '{% url "wagtailimages_chooser" %}',
'embedsChooser': '{% url "wagtailembeds_chooser" %}',
'pageChooser': '{% url "wagtailadmin_choose_page" %}',
'snippetChooser': '{% url "wagtailsnippets_choose_generic" %}'
};
{% get_date_format_override as format_override %}
window.overrideDateInputFormat ='{{ format_override }}';

Wyświetl plik

@ -1,5 +1,7 @@
from django.conf import settings
from django.conf.urls import include, url
from django.core import urlresolvers
from django.utils.html import format_html, format_html_join
from django.utils.translation import ugettext_lazy as _
from wagtail.wagtailadmin import hooks
@ -21,3 +23,23 @@ def construct_main_menu(request, menu_items):
MenuItem(_('Documents'), urlresolvers.reverse('wagtaildocs_index'), classnames='icon icon-doc-full-inverse', order=400)
)
hooks.register('construct_main_menu', construct_main_menu)
def editor_js():
js_files = [
'wagtaildocs/js/hallo-plugins/hallo-wagtaildoclink.js',
'wagtaildocs/js/document-chooser.js',
]
js_includes = format_html_join('\n', '<script src="{0}{1}"></script>',
((settings.STATIC_URL, filename) for filename in js_files)
)
return js_includes + format_html(
"""
<script>
window.chooserUrls.documentChooser = '{0}';
registerHalloPlugin('hallowagtaildoclink');
</script>
""",
urlresolvers.reverse('wagtaildocs_chooser')
)
hooks.register('insert_editor_js', editor_js)

Wyświetl plik

@ -152,6 +152,17 @@ def get_embed(url, max_width=None, finder=None):
finder = get_default_finder()
embed_dict = finder(url, max_width)
# Make sure width and height are valid integers before inserting into database
try:
embed_dict['width'] = int(embed_dict['width'])
except (TypeError, ValueError):
embed_dict['width'] = None
try:
embed_dict['height'] = int(embed_dict['height'])
except (TypeError, ValueError):
embed_dict['height'] = None
# Create database record
embed, created = Embed.objects.get_or_create(
url=url,

Wyświetl plik

@ -8,6 +8,20 @@ class TestEmbeds(TestCase):
def setUp(self):
self.hit_count = 0
def dummy_finder(self, url, max_width=None):
# Up hit count
self.hit_count += 1
# Return a pretend record
return {
'title': "Test: " + url,
'type': 'video',
'thumbnail_url': '',
'width': max_width if max_width else 640,
'height': 480,
'html': "<p>Blah blah blah</p>",
}
def test_get_embed(self):
embed = get_embed('www.test.com/1234', max_width=400, finder=self.dummy_finder)
@ -31,20 +45,23 @@ class TestEmbeds(TestCase):
embed = get_embed('www.test.com/4321', finder=self.dummy_finder)
self.assertEqual(self.hit_count, 3)
def dummy_finder(self, url, max_width=None):
# Up hit count
self.hit_count += 1
# Return a pretend record
def dummy_finder_invalid_width(self, url, max_width=None):
# Return a record with an invalid width
return {
'title': "Test: " + url,
'type': 'video',
'thumbnail_url': '',
'width': max_width if max_width else 640,
'width': '100%',
'height': 480,
'html': "<p>Blah blah blah</p>",
}
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)
class TestChooser(TestCase):
def setUp(self):

Wyświetl plik

@ -1,4 +1,7 @@
from django.conf import settings
from django.conf.urls import include, url
from django.core import urlresolvers
from django.utils.html import format_html
from wagtail.wagtailadmin import hooks
from wagtail.wagtailembeds import urls
@ -9,3 +12,18 @@ def register_admin_urls():
url(r'^embeds/', include(urls)),
]
hooks.register('register_admin_urls', register_admin_urls)
def editor_js():
return format_html("""
<script src="{0}{1}"></script>
<script>
window.chooserUrls.embedsChooser = '{2}';
registerHalloPlugin('hallowagtailembeds');
</script>
""",
settings.STATIC_URL,
'wagtailembeds/js/hallo-plugins/hallo-wagtailembeds.js',
urlresolvers.reverse('wagtailembeds_chooser')
)
hooks.register('insert_editor_js', editor_js)

Wyświetl plik

@ -1,5 +1,7 @@
from django.conf import settings
from django.conf.urls import include, url
from django.core import urlresolvers
from django.utils.html import format_html, format_html_join
from django.utils.translation import ugettext_lazy as _
from wagtail.wagtailadmin import hooks
@ -21,3 +23,23 @@ def construct_main_menu(request, menu_items):
MenuItem(_('Images'), urlresolvers.reverse('wagtailimages_index'), classnames='icon icon-image', order=300)
)
hooks.register('construct_main_menu', construct_main_menu)
def editor_js():
js_files = [
'wagtailimages/js/hallo-plugins/hallo-wagtailimage.js',
'wagtailimages/js/image-chooser.js',
]
js_includes = format_html_join('\n', '<script src="{0}{1}"></script>',
((settings.STATIC_URL, filename) for filename in js_files)
)
return js_includes + format_html(
"""
<script>
window.chooserUrls.imageChooser = '{0}';
registerHalloPlugin('hallowagtailimage');
</script>
""",
urlresolvers.reverse('wagtailimages_chooser')
)
hooks.register('insert_editor_js', editor_js)

Wyświetl plik

@ -1,5 +1,7 @@
from django.conf import settings
from django.conf.urls import include, url
from django.core import urlresolvers
from django.utils.html import format_html
from django.utils.translation import ugettext_lazy as _
from wagtail.wagtailadmin import hooks
@ -22,3 +24,15 @@ def construct_main_menu(request, menu_items):
MenuItem(_('Snippets'), urlresolvers.reverse('wagtailsnippets_index'), classnames='icon icon-snippet', order=500)
)
hooks.register('construct_main_menu', construct_main_menu)
def editor_js():
return format_html("""
<script src="{0}{1}"></script>
<script>window.chooserUrls.snippetChooser = '{2}';</script>
""",
settings.STATIC_URL,
'wagtailsnippets/js/snippet-chooser.js',
urlresolvers.reverse('wagtailsnippets_choose_generic')
)
hooks.register('insert_editor_js', editor_js)