From 87e868d3156a597eaa6266de9ad21f5dcbc79705 Mon Sep 17 00:00:00 2001 From: Sage Abdullah Date: Wed, 9 Nov 2022 09:50:33 +0000 Subject: [PATCH] Move preview_settings to wagtail_config template tag --- client/src/entrypoints/admin/preview-panel.js | 9 ++----- .../shared/side_panels/preview.html | 3 +-- .../admin/templatetags/wagtailadmin_tags.py | 24 +++++++++---------- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/client/src/entrypoints/admin/preview-panel.js b/client/src/entrypoints/admin/preview-panel.js index 48026a9e85..d12a05e5f1 100644 --- a/client/src/entrypoints/admin/preview-panel.js +++ b/client/src/entrypoints/admin/preview-panel.js @@ -9,11 +9,6 @@ function initPreview() { // Preview side panel is not shown if the object does not have any preview modes if (!previewSidePanel) return; - // Get settings from the preview_settings template tag - const settings = JSON.parse( - document.getElementById('wagtail-preview-settings').textContent, - ); - // The previewSidePanel is a generic container for side panels, // the content of the preview panel itself is in a child element const previewPanel = previewSidePanel.querySelector('[data-preview-panel]'); @@ -218,7 +213,7 @@ function initPreview() { refreshButton.addEventListener('click', handlePreview); } - if (settings.WAGTAIL_AUTO_UPDATE_PREVIEW) { + if (WAGTAIL_CONFIG.WAGTAIL_AUTO_UPDATE_PREVIEW) { let oldPayload = new URLSearchParams(new FormData(form)).toString(); let updateInterval; @@ -244,7 +239,7 @@ function initPreview() { // Only set the interval while the panel is shown updateInterval = setInterval( checkAndUpdatePreview, - settings.WAGTAIL_AUTO_UPDATE_PREVIEW_INTERVAL, + WAGTAIL_CONFIG.WAGTAIL_AUTO_UPDATE_PREVIEW_INTERVAL, ); }); diff --git a/wagtail/admin/templates/wagtailadmin/shared/side_panels/preview.html b/wagtail/admin/templates/wagtailadmin/shared/side_panels/preview.html index 5b01f2c55a..e3d20af4f3 100644 --- a/wagtail/admin/templates/wagtailadmin/shared/side_panels/preview.html +++ b/wagtail/admin/templates/wagtailadmin/shared/side_panels/preview.html @@ -1,7 +1,6 @@ {% load i18n wagtailadmin_tags %} -{% preview_settings as settings %} -{{ settings|json_script:"wagtail-preview-settings" }} +{% wagtail_config as settings %}
diff --git a/wagtail/admin/templatetags/wagtailadmin_tags.py b/wagtail/admin/templatetags/wagtailadmin_tags.py index cf9f9c22ee..4496b11d4a 100644 --- a/wagtail/admin/templatetags/wagtailadmin_tags.py +++ b/wagtail/admin/templatetags/wagtailadmin_tags.py @@ -863,19 +863,6 @@ def get_comments_enabled(): return getattr(settings, "WAGTAILADMIN_COMMENTS_ENABLED", True) -@register.simple_tag -def preview_settings(): - default_options = { - "WAGTAIL_AUTO_UPDATE_PREVIEW": True, - "WAGTAIL_AUTO_UPDATE_PREVIEW_INTERVAL": 500, - } - - return { - option: getattr(settings, option, default) - for option, default in default_options.items() - } - - @register.simple_tag(takes_context=True) def wagtail_config(context): request = context["request"] @@ -889,6 +876,17 @@ def wagtail_config(context): }, } + default_settings = { + "WAGTAIL_AUTO_UPDATE_PREVIEW": True, + "WAGTAIL_AUTO_UPDATE_PREVIEW_INTERVAL": 500, + } + config.update( + { + option: getattr(settings, option, default) + for option, default in default_settings.items() + } + ) + return config