diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 3894acc134..9076f47133 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -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) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 7cdb2c14aa..95caf01fed 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -278,6 +278,7 @@ Contributors * Julian Gallo * Dan Dietz * Michael Harrison +* Todd Dembrey Translators =========== diff --git a/docs/releases/2.1.rst b/docs/releases/2.1.rst index 8a8e051753..95aba5ae6b 100644 --- a/docs/releases/2.1.rst +++ b/docs/releases/2.1.rst @@ -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 ====================== diff --git a/wagtail/admin/rich_text/editors/draftail/__init__.py b/wagtail/admin/rich_text/editors/draftail/__init__.py index d8578c573f..fed4173b5d 100644 --- a/wagtail/admin/rich_text/editors/draftail/__init__.py +++ b/wagtail/admin/rich_text/editors/draftail/__init__.py @@ -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) diff --git a/wagtail/admin/tests/test_rich_text.py b/wagtail/admin/tests/test_rich_text.py index 58add70cb9..dfbe7f31db 100644 --- a/wagtail/admin/tests/test_rich_text.py +++ b/wagtail/admin/tests/test_rich_text.py @@ -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("

hello

"), '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',