Draftail was failing to initialise with defined options in settings

pull/4332/merge
Todd Dembrey 2018-03-02 11:15:20 +00:00 zatwierdzone przez Matt Westcott
rodzic 76975525f7
commit 09f8a4f38a
5 zmienionych plików z 45 dodań i 0 usunięć

Wyświetl plik

@ -11,6 +11,7 @@ Changelog
* Fix: Image title text in the gallery and in the chooser now wraps for long filenames (LB (Ben Johnston), Luiz Boaretto)
* Fix: Move image editor action buttons to the bottom of the form on mobile (Julian Gallo)
* Fix: StreamField icons are now correctly sorted into groups on the 'append' menu (Tim Heap)
* Fix: Draftail now supports features specified via the `WAGTAILADMIN_RICH_TEXT_EDITORS` setting (Todd Dembrey)
2.0 (28.02.2018)

Wyświetl plik

@ -278,6 +278,7 @@ Contributors
* Julian Gallo
* Dan Dietz
* Michael Harrison
* Todd Dembrey
Translators
===========

Wyświetl plik

@ -25,6 +25,7 @@ Bug fixes
* Image title text in the gallery and in the chooser now wraps for long filenames (LB (Ben Johnston), Luiz Boaretto)
* Move image editor action buttons to the bottom of the form on mobile (Julian Gallo)
* StreamField icons are now correctly sorted into groups on the 'append' menu (Tim Heap)
* Draftail now supports features specified via the `WAGTAILADMIN_RICH_TEXT_EDITORS` setting (Todd Dembrey)
Upgrade considerations
======================

Wyświetl plik

@ -18,6 +18,7 @@ class DraftailRichTextArea(WidgetWithScript, widgets.HiddenInput):
def __init__(self, *args, **kwargs):
# note: this constructor will receive an 'options' kwarg taken from the WAGTAILADMIN_RICH_TEXT_EDITORS setting,
# but we don't currently recognise any options from there (other than 'features', which is passed here as a separate kwarg)
kwargs.pop('options', None)
self.options = {}
self.features = kwargs.pop('features', None)

Wyświetl plik

@ -377,6 +377,47 @@ class TestHalloJsWithFeaturesKwarg(BaseRichTextEditHandlerTestCase, WagtailTestU
self.assertNotIn('wagtaildocs/js/hallo-plugins/hallo-wagtaildoclink.js', media_html)
@override_settings(WAGTAILADMIN_RICH_TEXT_EDITORS={
'default': {
'WIDGET': 'wagtail.admin.rich_text.DraftailRichTextArea',
'OPTIONS': {
'features': ['h2', 'image']
}
},
})
class TestDraftailWithFeatureOptions(BaseRichTextEditHandlerTestCase, WagtailTestUtils):
def setUp(self):
super().setUp()
# Find root page
self.root_page = Page.objects.get(id=2)
self.login()
def test_settings_features_option_on_rich_text_field(self):
response = self.client.get(reverse(
'wagtailadmin_pages:add', args=('tests', 'defaultrichtextfieldpage', self.root_page.id)
))
self.assertEqual(response.status_code, 200)
self.assertContains(response, '"type": "header-two"')
self.assertContains(response, '"type": "IMAGE"')
self.assertNotContains(response, '"type": "ordered-list-item"')
def test_features_option_on_rich_text_block(self):
# a 'features' list passed on the RichTextBlock
# should override the list in OPTIONS
block = RichTextBlock(features=['h2', 'embed'])
form_html = block.render_form(block.to_python("<p>hello</p>"), 'body')
self.assertIn('"type": "header-two"', form_html)
self.assertIn('"type": "EMBED"', form_html)
self.assertNotIn('"type": "IMAGE""', form_html)
self.assertNotIn('"type": "ordered-list-item""', form_html)
@override_settings(WAGTAILADMIN_RICH_TEXT_EDITORS={
'default': {
'WIDGET': 'wagtail.admin.rich_text.HalloRichTextArea',