8000 Fixes #5740 -- Use the correct url when ManifestStaticFilesStorage or similar is used by Pankrat · Pull Request #5993 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

Fixes #5740 -- Use the correct url when ManifestStaticFilesStorage or similar is used #5993

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

Merged
merged 4 commits into from
Sep 14, 2017
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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) ===
Expand Down
6 changes: 4 additions & 2 deletions cms/templatetags/cms_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
28 changes: 28 additions & 0 deletions cms/tests/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
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

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
Expand Down Expand Up @@ -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 %}<script src="{% static_with_version "cms/css/cms.base.css" %}" """
"""type="text/javascript"></script>"""
)

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 = '<script src="/static/%s" type="text/javascript"></script>'
expected = expected % versioned_filename
self.assertEqual(expected, output)


class TemplatetagDatabaseTests(TwoPagesFixture, CMSTestCase):
def _getfirst(self):
Expand Down
0