From 2c254ae49dbd785e4a7668f443face3c1de68926 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Thu, 7 Dec 2023 21:16:43 +0100 Subject: [PATCH] Fixes #420 - Switch to staticfiles_storage.url() to reference JS files --- tinymce/compressor.py | 10 ++++------ tinymce/settings.py | 15 +++++++-------- tinymce/widgets.py | 2 +- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/tinymce/compressor.py b/tinymce/compressor.py index 81027be9..e81dfe21 100644 --- a/tinymce/compressor.py +++ b/tinymce/compressor.py @@ -60,12 +60,10 @@ def gzip_compressor(request): response = HttpResponse() response["Content-Type"] = "text/javascript" + js_url = tinymce.settings.get_js_url() + js_base_url = js_url[: js_url.rfind("/")] if not isJS: - response.write( - render_to_string( - "tinymce/tiny_mce_gzip.js", {"base_url": tinymce.settings.JS_BASE_URL} - ) - ) + response.write(render_to_string("tinymce/tiny_mce_gzip.js", {"base_url": js_base_url})) return response patch_vary_headers(response, ["Accept-Encoding"]) @@ -94,7 +92,7 @@ def gzip_compressor(request): return response tinyMCEPreInit = { - "base": tinymce.settings.JS_BASE_URL, + "base": js_base_url, "suffix": "", } content.append(f"var tinyMCEPreInit={json.dumps(tinyMCEPreInit)};") diff --git a/tinymce/settings.py b/tinymce/settings.py index bd665299..2cf5f5f1 100644 --- a/tinymce/settings.py +++ b/tinymce/settings.py @@ -1,6 +1,5 @@ -import os - from django.conf import settings +from django.contrib.staticfiles.storage import staticfiles_storage DEFAULT_CONFIG = getattr( settings, @@ -29,10 +28,10 @@ settings, "TINYMCE_FILEBROWSER", "filebrowser" in settings.INSTALLED_APPS ) -JS_URL = getattr( - settings, - "TINYMCE_JS_URL", - os.path.join(settings.STATIC_URL, "tinymce/tinymce.min.js"), -) -JS_BASE_URL = JS_URL[: JS_URL.rfind("/")] +def get_js_url(): + return getattr( + settings, + "TINYMCE_JS_URL", + staticfiles_storage.url("tinymce/tinymce.min.js"), + ) diff --git a/tinymce/widgets.py b/tinymce/widgets.py index 0a7ebe28..ddbe70ef 100644 --- a/tinymce/widgets.py +++ b/tinymce/widgets.py @@ -101,7 +101,7 @@ def _media(self): if tinymce.settings.USE_COMPRESSOR: js = [reverse("tinymce-compressor")] else: - js = [tinymce.settings.JS_URL] + js = [tinymce.settings.get_js_url()] if tinymce.settings.USE_FILEBROWSER: js.append(reverse("tinymce-filebrowser")) if tinymce.settings.USE_EXTRA_MEDIA: