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) === 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) diff --git a/cms/tests/test_templatetags.py b/cms/tests/test_templatetags.py index f470e74f867..3495afbbb31 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,31 @@ 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 + + template = ( + """{% load staticfiles cms_static %}""" + ) + + 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): def _getfirst(self):