From 763fe803589991a79f907bffa85c211542821553 Mon Sep 17 00:00:00 2001 From: Sylvain Fankhauser Date: Sun, 7 May 2017 14:58:52 +0200 Subject: [PATCH 1/4] Fix static_with_version with ManifestStaticFilesStorage Fixes #5963. --- cms/templatetags/cms_static.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cms/templatetags/cms_static.py b/cms/templatetags/cms_static.py index 05c79575f0c..18da36119de 100644 --- a/cms/templatetags/cms_static.py +++ b/cms/templatetags/cms_static.py @@ -28,5 +28,7 @@ def do_static_with_version(parser, token): class StaticWithVersionNode(StaticNode): def url(self, context): - url = super(StaticWithVersionNode, self).url(context) - return static_with_version(url) + path = self.path.resolve(context) + path_with_version = static_with_version(path) + + return self.handle_simple(path_with_version) From caabd9824d333e4f7aaf013b4aee46b323f016df Mon Sep 17 00:00:00 2001 From: Pankrat Date: Mon, 19 Jun 2017 12:31:33 +0200 Subject: [PATCH 2/4] Add test for looking up versioned static files --- cms/tests/test_templatetags.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/cms/tests/test_templatetags.py b/cms/tests/test_templatetags.py index f470e74f867..7baab9535bf 100644 --- a/cms/tests/test_templatetags.py +++ b/cms/tests/test_templatetags.py @@ -10,6 +10,7 @@ from django.core import mail from django.core.exceptions import ImproperlyConfigured from django.test import RequestFactory +from django.test.utils import override_settings from django.utils.html import escape from django.utils.timezone import now from djangocms_text_ckeditor.cms_plugins import TextPlugin @@ -17,6 +18,8 @@ from sekizai.data import UniqueSequence from sekizai.helpers import get_varname +from mock import patch + import cms from cms.api import create_page, create_title, add_plugin from cms.middleware.toolbar import ToolbarMiddleware @@ -100,6 +103,25 @@ def test_static_with_version(self): output = self.render_template_obj(template, {}, None) self.assertEqual(expected, output) + @override_settings(STATICFILES_STORAGE='django.contrib.staticfiles.storage.ManifestStaticFilesStorage') + @patch('django.contrib.staticfiles.storage.staticfiles_storage') + def test_static_with_version_manifest(self, mock_storage): + """ + Check that static files are looked up at the location where they are + stored when using static file manifests. + """ + mock_storage.url.side_effect = lambda x: '/static/' + x + expected = 'cms/css/%(version)s/cms.base.css' + expected = expected % {'version': cms.__version__} + + template = ( + """{% load cms_static %}""" + ) + + self.render_template_obj(template, {}, None) + mock_storage.url.assert_called_with(expected) + class TemplatetagDatabaseTests(TwoPagesFixture, CMSTestCase): def _getfirst(self): From 10bc8a5208e14b4b3192a7f86dd3688d2bc4e94c Mon Sep 17 00:00:00 2001 From: Pankrat Date: Tue, 4 Jul 2017 22:37:08 +0200 Subject: [PATCH 3/4] Fix test on Django < 1.10 Don't fail if the static files storage is not called at all. On Django 1.8 and 1.9, `StaticNode` doesn't use the static files storage for looking up static files. This was changed in this commit: https://github.com/django/django/commit/cf546e11ac76c8dec527e39ff8ce8249a195ab42 --- cms/tests/test_templatetags.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/cms/tests/test_templatetags.py b/cms/tests/test_templatetags.py index 7baab9535bf..3495afbbb31 100644 --- a/cms/tests/test_templatetags.py +++ b/cms/tests/test_templatetags.py @@ -111,16 +111,22 @@ def test_static_with_version_manifest(self, mock_storage): stored when using static file manifests. """ mock_storage.url.side_effect = lambda x: '/static/' + x - expected = 'cms/css/%(version)s/cms.base.css' - expected = expected % {'version': cms.__version__} template = ( - """{% load cms_static %}""" ) - self.render_template_obj(template, {}, None) - mock_storage.url.assert_called_with(expected) + output = self.render_template_obj(template, {}, None) + # If the manifest is used for looking up the static file (Django 1.10 + # and later), it needs to be looked up with a proper path. + versioned_filename = 'cms/css/%s/cms.base.css' % cms.__version__ + if mock_storage.url.called: + mock_storage.url.assert_called_with(versioned_filename) + + expected = '' + expected = expected % versioned_filename + self.assertEqual(expected, output) class TemplatetagDatabaseTests(TwoPagesFixture, CMSTestCase): From bcc2b4ae532a6d5555049cfd898a946003d3905c Mon Sep 17 00:00:00 2001 From: Paulo Alvarado Date: Thu, 14 Sep 2017 05:36:21 -0500 Subject: [PATCH 4/4] Updated changelog --- CHANGELOG.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 92410fc8c0c..fdf4f1e039e 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -28,6 +28,8 @@ * Fixed a bug in which the placeholder cache was not consistently cleared when a page was published. * Enhanced the plugin menu to not show plugins the user does not have permission to add. * Fixed a regression which prevented users from setting a redirect to the homepage. +* Fixed a ``ValueError`` raised when using ``ManifestStaticFilesStorage`` or similar for static files. + This only affects Django >= 1.10 === 3.4.3 (2017-04-24) ===