Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include cache_suffix tinymce parameter in project's static files #465

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,25 @@ def test_tinymce_widget_media(self):
],
)

def test_widget_media_applied_cache_suffix(self):
tinymce_version = "6.8"

orig_config = tinymce.settings.DEFAULT_CONFIG
with patch.dict(
tinymce.settings.DEFAULT_CONFIG,
{**orig_config, "cache_suffix": f"?ver={tinymce_version}"},
):
widget = TinyMCE()

self.assertEqual(list(widget.media.render_css()), [])
self.assertEqual(
widget.media.render_js(),
[
f'<script src="/tinymce/compressor/?ver={tinymce_version}"></script>',
f'<script src="/static/django_tinymce/init_tinymce.js?ver={tinymce_version}"></script>',
],
)

def test_tinymce_widget_required(self):
"""
The TinyMCE widget should never output the required HTML attribute, even
Expand Down
14 changes: 13 additions & 1 deletion tinymce/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from django.core.serializers.json import DjangoJSONEncoder
from django.forms.utils import flatatt
from django.urls import reverse
from django.utils.html import escape
from django.utils.html import escape, format_html
from django.utils.safestring import mark_safe
from django.utils.translation import get_language, gettext as _, to_locale

Expand Down Expand Up @@ -114,6 +114,18 @@ def _media(self):

media = property(_media)

def _render_js(self):
revision_parameter = tinymce.settings.DEFAULT_CONFIG.get("cache_suffix", "")

return [
format_html(
'<script src="{}{}"></script>', (self.absolute_path(path)), revision_parameter
)
for path in self._js
]

forms.widgets.Media.render_js = _render_js


class AdminTinyMCE(TinyMCE, admin_widgets.AdminTextareaWidget):
pass
Expand Down
Loading