From 9c64b478e2569eb9001fb31655389d5a76b60101 Mon Sep 17 00:00:00 2001 From: Mathieu Pillard Date: Mon, 8 Oct 2012 20:20:24 +0200 Subject: [PATCH] 1.2 is not unsupported, remove all references to MEDIA_* (users should have moved to STATIC_* by now) as well as 1.2 stuff in the documentation. --- .gitignore | 8 +- compressor/conf.py | 32 ++------ compressor/management/commands/compress.py | 2 +- compressor/management/commands/mtime_cache.py | 2 +- compressor/templatetags/compress.py | 12 +-- compressor/test_settings.py | 5 +- compressor/tests/media/css/url/test.css | 1 - .../tests/{media => static}/css/datauri.css | 0 .../tests/{media => static}/css/nonasc.css | 0 .../tests/{media => static}/css/one.css | 0 .../tests/{media => static}/css/two.css | 0 .../{media => static}/css/url/2/url2.css | 0 .../{media => static}/css/url/nonasc.css | 0 compressor/tests/static/css/url/test.css | 1 + .../tests/{media => static}/css/url/url1.css | 0 .../tests/{media => static}/img/add.png | Bin .../tests/{media => static}/img/python.png | Bin .../{media => static}/js/nonasc-latin1.js | 0 .../tests/{media => static}/js/nonasc.js | 0 .../tests/{media => static}/js/one.coffee | 0 compressor/tests/{media => static}/js/one.js | 0 compressor/tests/test_base.py | 38 ++++----- compressor/tests/test_filters.py | 48 +++++------ compressor/tests/test_jinja2ext.py | 46 +++++------ compressor/tests/test_offline.py | 12 +-- compressor/tests/test_parsers.py | 10 +-- compressor/tests/test_signals.py | 10 +-- compressor/tests/test_storages.py | 8 +- compressor/tests/test_templatetags.py | 76 +++++++++--------- docs/quickstart.txt | 2 +- docs/remote-storages.txt | 2 +- docs/settings.txt | 16 +--- docs/usage.txt | 3 +- 33 files changed, 152 insertions(+), 182 deletions(-) delete mode 100644 compressor/tests/media/css/url/test.css rename compressor/tests/{media => static}/css/datauri.css (100%) rename compressor/tests/{media => static}/css/nonasc.css (100%) rename compressor/tests/{media => static}/css/one.css (100%) rename compressor/tests/{media => static}/css/two.css (100%) rename compressor/tests/{media => static}/css/url/2/url2.css (100%) rename compressor/tests/{media => static}/css/url/nonasc.css (100%) create mode 100644 compressor/tests/static/css/url/test.css rename compressor/tests/{media => static}/css/url/url1.css (100%) rename compressor/tests/{media => static}/img/add.png (100%) rename compressor/tests/{media => static}/img/python.png (100%) rename compressor/tests/{media => static}/js/nonasc-latin1.js (100%) rename compressor/tests/{media => static}/js/nonasc.js (100%) rename compressor/tests/{media => static}/js/one.coffee (100%) rename compressor/tests/{media => static}/js/one.js (100%) diff --git a/.gitignore b/.gitignore index 2ecfbb5..184fe90 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ build -compressor/tests/media/CACHE -compressor/tests/media/custom -compressor/tests/media/js/066cd253eada.js +compressor/tests/static/CACHE +compressor/tests/static/custom +compressor/tests/static/js/066cd253eada.js dist MANIFEST *.pyc @@ -9,4 +9,4 @@ MANIFEST *.egg docs/_build/ .sass-cache -.coverage \ No newline at end of file +.coverage diff --git a/compressor/conf.py b/compressor/conf.py index 3613166..ca146f6 100644 --- a/compressor/conf.py +++ b/compressor/conf.py @@ -1,5 +1,4 @@ import os -from django import VERSION as DJANGO_VERSION from django.conf import settings from django.core.exceptions import ImproperlyConfigured @@ -69,20 +68,17 @@ class CompressorConf(AppConf): prefix = 'compress' def configure_root(self, value): + # Uses Django's STATIC_ROOT by default if value is None: - value = getattr(settings, 'STATIC_ROOT', None) - if not value: - value = settings.MEDIA_ROOT + value = settings.STATIC_ROOT if value is None: raise ImproperlyConfigured("COMPRESS_ROOT setting must be set") return os.path.normcase(os.path.abspath(value)) def configure_url(self, value): - # Uses Django 1.3's STATIC_URL by default or falls back to MEDIA_URL + # Uses Django's STATIC_URL by default if value is None: - value = getattr(settings, 'STATIC_URL', None) - if not value: - value = settings.MEDIA_URL + value = settings.STATIC_URL if not value.endswith('/'): raise ImproperlyConfigured("URL settings (e.g. COMPRESS_URL) " "must have a trailing slash") @@ -90,31 +86,17 @@ class CompressorConf(AppConf): def configure_cache_backend(self, value): if value is None: - # If we are on Django 1.3 AND using the new CACHES setting... - if DJANGO_VERSION[:2] >= (1, 3) and hasattr(settings, 'CACHES'): - value = 'default' - else: - # falling back to the old CACHE_BACKEND setting - value = getattr(settings, 'CACHE_BACKEND', None) - if not value: - raise ImproperlyConfigured("Please specify a cache " - "backend in your settings.") + value = 'default' return value def configure_offline_context(self, value): if not value: - value = {'MEDIA_URL': settings.MEDIA_URL} - # Adds the 1.3 STATIC_URL setting to the context if available - if getattr(settings, 'STATIC_URL', None): - value['STATIC_URL'] = settings.STATIC_URL + value = {'STATIC_URL': settings.STATIC_URL} return value def configure_template_filter_context(self, value): if not value: - value = {'MEDIA_URL': settings.MEDIA_URL} - # Adds the 1.3 STATIC_URL setting to the context if available - if getattr(settings, 'STATIC_URL', None): - value['STATIC_URL'] = settings.STATIC_URL + value = {'STATIC_URL': settings.STATIC_URL} return value def configure_precompilers(self, value): diff --git a/compressor/management/commands/compress.py b/compressor/management/commands/compress.py index 236817c..b1096a7 100644 --- a/compressor/management/commands/compress.py +++ b/compressor/management/commands/compress.py @@ -115,7 +115,7 @@ class Command(NoArgsCommand): "COMPRESS_ENABLED setting is not True.", dest='force'), make_option('--follow-links', default=False, action='store_true', help="Follow symlinks when traversing the COMPRESS_ROOT " - "(which defaults to MEDIA_ROOT). Be aware that using this " + "(which defaults to STATIC_ROOT). Be aware that using this " "can lead to infinite recursion if a link points to a parent " "directory of itself.", dest='follow_links'), ) diff --git a/compressor/management/commands/mtime_cache.py b/compressor/management/commands/mtime_cache.py index 4362c2e..842ad08 100644 --- a/compressor/management/commands/mtime_cache.py +++ b/compressor/management/commands/mtime_cache.py @@ -22,7 +22,7 @@ class Command(NoArgsCommand): "'.*' and '*~'."), make_option('--follow-links', dest='follow_links', action='store_true', help="Follow symlinks when traversing the COMPRESS_ROOT " - "(which defaults to MEDIA_ROOT). Be aware that using this " + "(which defaults to STATIC_ROOT). Be aware that using this " "can lead to infinite recursion if a link points to a parent " "directory of itself."), make_option('-c', '--clean', dest='clean', action='store_true', diff --git a/compressor/templatetags/compress.py b/compressor/templatetags/compress.py index 1a12198..ae946b5 100644 --- a/compressor/templatetags/compress.py +++ b/compressor/templatetags/compress.py @@ -161,27 +161,27 @@ def compress(parser, token): Examples:: {% compress css %} - + - + {% endcompress %} Which would be rendered something like:: - + or:: {% compress js %} - + {% endcompress %} Which would be rendered something like:: - + - Linked files must be on your COMPRESS_URL (which defaults to MEDIA_URL). + Linked files must be on your COMPRESS_URL (which defaults to STATIC_URL). If DEBUG is true off-site files will throw exceptions. If DEBUG is false they will be silently stripped. """ diff --git a/compressor/test_settings.py b/compressor/test_settings.py index fc6b1f6..0e8a768 100644 --- a/compressor/test_settings.py +++ b/compressor/test_settings.py @@ -19,11 +19,10 @@ INSTALLED_APPS = [ 'compressor', ] -MEDIA_URL = '/media/' -STATIC_URL = MEDIA_URL +STATIC_URL = '/static/' -MEDIA_ROOT = os.path.join(TEST_DIR, 'media') +STATIC_ROOT = os.path.join(TEST_DIR, 'static') TEMPLATE_DIRS = ( # Specifically choose a name that will not be considered diff --git a/compressor/tests/media/css/url/test.css b/compressor/tests/media/css/url/test.css deleted file mode 100644 index 0f6edf8..0000000 --- a/compressor/tests/media/css/url/test.css +++ /dev/null @@ -1 +0,0 @@ -p { background: url('/media/images/image.gif') } \ No newline at end of file diff --git a/compressor/tests/media/css/datauri.css b/compressor/tests/static/css/datauri.css similarity index 100% rename from compressor/tests/media/css/datauri.css rename to compressor/tests/static/css/datauri.css diff --git a/compressor/tests/media/css/nonasc.css b/compressor/tests/static/css/nonasc.css similarity index 100% rename from compressor/tests/media/css/nonasc.css rename to compressor/tests/static/css/nonasc.css diff --git a/compressor/tests/media/css/one.css b/compressor/tests/static/css/one.css similarity index 100% rename from compressor/tests/media/css/one.css rename to compressor/tests/static/css/one.css diff --git a/compressor/tests/media/css/two.css b/compressor/tests/static/css/two.css similarity index 100% rename from compressor/tests/media/css/two.css rename to compressor/tests/static/css/two.css diff --git a/compressor/tests/media/css/url/2/url2.css b/compressor/tests/static/css/url/2/url2.css similarity index 100% rename from compressor/tests/media/css/url/2/url2.css rename to compressor/tests/static/css/url/2/url2.css diff --git a/compressor/tests/media/css/url/nonasc.css b/compressor/tests/static/css/url/nonasc.css similarity index 100% rename from compressor/tests/media/css/url/nonasc.css rename to compressor/tests/static/css/url/nonasc.css diff --git a/compressor/tests/static/css/url/test.css b/compressor/tests/static/css/url/test.css new file mode 100644 index 0000000..0d4a22b --- /dev/null +++ b/compressor/tests/static/css/url/test.css @@ -0,0 +1 @@ +p { background: url('/static/images/image.gif') } \ No newline at end of file diff --git a/compressor/tests/media/css/url/url1.css b/compressor/tests/static/css/url/url1.css similarity index 100% rename from compressor/tests/media/css/url/url1.css rename to compressor/tests/static/css/url/url1.css diff --git a/compressor/tests/media/img/add.png b/compressor/tests/static/img/add.png similarity index 100% rename from compressor/tests/media/img/add.png rename to compressor/tests/static/img/add.png diff --git a/compressor/tests/media/img/python.png b/compressor/tests/static/img/python.png similarity index 100% rename from compressor/tests/media/img/python.png rename to compressor/tests/static/img/python.png diff --git a/compressor/tests/media/js/nonasc-latin1.js b/compressor/tests/static/js/nonasc-latin1.js similarity index 100% rename from compressor/tests/media/js/nonasc-latin1.js rename to compressor/tests/static/js/nonasc-latin1.js diff --git a/compressor/tests/media/js/nonasc.js b/compressor/tests/static/js/nonasc.js similarity index 100% rename from compressor/tests/media/js/nonasc.js rename to compressor/tests/static/js/nonasc.js diff --git a/compressor/tests/media/js/one.coffee b/compressor/tests/static/js/one.coffee similarity index 100% rename from compressor/tests/media/js/one.coffee rename to compressor/tests/static/js/one.coffee diff --git a/compressor/tests/media/js/one.js b/compressor/tests/static/js/one.js similarity index 100% rename from compressor/tests/media/js/one.js rename to compressor/tests/static/js/one.js diff --git a/compressor/tests/test_base.py b/compressor/tests/test_base.py index 25791da..8678e32 100644 --- a/compressor/tests/test_base.py +++ b/compressor/tests/test_base.py @@ -39,21 +39,21 @@ class CompressorTestCase(TestCase): settings.COMPRESS_PRECOMPILERS = {} settings.COMPRESS_DEBUG_TOGGLE = 'nocompress' self.css = """\ - + -""" +""" self.css_node = CssCompressor(self.css) self.js = """\ - + """ self.js_node = JsCompressor(self.js) def test_css_split(self): out = [ - (SOURCE_FILE, os.path.join(settings.COMPRESS_ROOT, u'css', u'one.css'), u'css/one.css', u''), + (SOURCE_FILE, os.path.join(settings.COMPRESS_ROOT, u'css', u'one.css'), u'css/one.css', u''), (SOURCE_HUNK, u'p { border:5px solid green;}', None, u''), - (SOURCE_FILE, os.path.join(settings.COMPRESS_ROOT, u'css', u'two.css'), u'css/two.css', u''), + (SOURCE_FILE, os.path.join(settings.COMPRESS_ROOT, u'css', u'two.css'), u'css/two.css', u''), ] split = self.css_node.split_contents() split = [(x[0], x[1], x[2], self.css_node.parser.elem_str(x[3])) for x in split] @@ -84,12 +84,12 @@ class CompressorTestCase(TestCase): "cachekey is returning something that doesn't look like r'\w{12}'") def test_css_return_if_on(self): - output = css_tag('/media/CACHE/css/e41ba2cc6982.css') + output = css_tag('/static/CACHE/css/e41ba2cc6982.css') self.assertEqual(output, self.css_node.output().strip()) def test_js_split(self): out = [ - (SOURCE_FILE, os.path.join(settings.COMPRESS_ROOT, u'js', u'one.js'), u'js/one.js', ''), + (SOURCE_FILE, os.path.join(settings.COMPRESS_ROOT, u'js', u'one.js'), u'js/one.js', ''), (SOURCE_HUNK, u'obj.value = "value";', None, ''), ] split = self.js_node.split_contents() @@ -101,17 +101,17 @@ class CompressorTestCase(TestCase): self.assertEqual(out, list(self.js_node.hunks())) def test_js_output(self): - out = u'' + out = u'' self.assertEqual(out, self.js_node.output()) def test_js_override_url(self): self.js_node.context.update({'url': u'This is not a url, just a text'}) - out = u'' + out = u'' self.assertEqual(out, self.js_node.output()) def test_css_override_url(self): self.css_node.context.update({'url': u'This is not a url, just a text'}) - output = css_tag('/media/CACHE/css/e41ba2cc6982.css') + output = css_tag('/static/CACHE/css/e41ba2cc6982.css') self.assertEqual(output, self.css_node.output().strip()) def test_js_return_if_off(self): @@ -126,20 +126,20 @@ class CompressorTestCase(TestCase): settings.COMPRESS_PRECOMPILERS = precompilers def test_js_return_if_on(self): - output = u'' + output = u'' self.assertEqual(output, self.js_node.output()) def test_custom_output_dir(self): try: old_output_dir = settings.COMPRESS_OUTPUT_DIR settings.COMPRESS_OUTPUT_DIR = 'custom' - output = u'' + output = u'' self.assertEqual(output, JsCompressor(self.js).output()) settings.COMPRESS_OUTPUT_DIR = '' - output = u'' + output = u'' self.assertEqual(output, JsCompressor(self.js).output()) settings.COMPRESS_OUTPUT_DIR = '/custom/nested/' - output = u'' + output = u'' self.assertEqual(output, JsCompressor(self.js).output()) finally: settings.COMPRESS_OUTPUT_DIR = old_output_dir @@ -175,9 +175,9 @@ class CompressorTestCase(TestCase): class CssMediaTestCase(TestCase): def setUp(self): self.css = """\ - + - + """ def test_css_output(self): @@ -201,12 +201,12 @@ class CssMediaTestCase(TestCase): ('text/foobar', 'python %s {infile} {outfile}' % os.path.join(test_dir, 'precompiler.py')), ) css = """\ - - + + """ css_node = CssCompressor(css) output = BeautifulSoup(css_node.output()).findAll(['link', 'style']) - self.assertEqual([u'/media/css/one.css', u'/media/css/two.css', None], + self.assertEqual([u'/static/css/one.css', u'/static/css/two.css', None], [l.get('href', None) for l in output]) self.assertEqual([u'screen', u'screen', u'screen'], [l.get('media', None) for l in output]) diff --git a/compressor/tests/test_filters.py b/compressor/tests/test_filters.py index 4c8b47c..1dc1bdd 100644 --- a/compressor/tests/test_filters.py +++ b/compressor/tests/test_filters.py @@ -37,7 +37,7 @@ CssTidyTestCase = skipIf( class PrecompilerTestCase(TestCase): def setUp(self): - self.filename = os.path.join(test_dir, 'media/css/one.css') + self.filename = os.path.join(test_dir, 'static/css/one.css') with open(self.filename) as f: self.content = f.read() self.test_precompiler = os.path.join(test_dir, 'precompiler.py') @@ -93,11 +93,11 @@ class CssAbsolutizingTestCase(TestCase): self.old_url = settings.COMPRESS_URL self.old_hashing_method = settings.COMPRESS_CSS_HASHING_METHOD settings.COMPRESS_ENABLED = True - settings.COMPRESS_URL = '/media/' + settings.COMPRESS_URL = '/static/' settings.COMPRESS_CSS_HASHING_METHOD = self.hashing_method self.css = """ - - + + """ self.css_node = CssCompressor(self.css) @@ -117,7 +117,7 @@ class CssAbsolutizingTestCase(TestCase): "p { filter: Alpha(src='%(url)simg/python.png?%(hash)s') }") % params filter = CssAbsoluteFilter(self.content) self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css')) - settings.COMPRESS_URL = params['url'] = 'http://media.example.com/' + settings.COMPRESS_URL = params['url'] = 'http://static.example.com/' filter = CssAbsoluteFilter(self.content) filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css') output = ("p { background: url('%(url)simg/python.png?%(hash)s') }" @@ -135,7 +135,7 @@ class CssAbsolutizingTestCase(TestCase): "p { filter: Alpha(src='%(url)simg/python.png?%(hash)s') }") % params filter = CssAbsoluteFilter(self.content) self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css')) - settings.COMPRESS_URL = params['url'] = 'https://media.example.com/' + settings.COMPRESS_URL = params['url'] = 'https://static.example.com/' filter = CssAbsoluteFilter(self.content) filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css') output = ("p { background: url('%(url)simg/python.png?%(hash)s') }" @@ -143,7 +143,7 @@ class CssAbsolutizingTestCase(TestCase): self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css')) def test_css_absolute_filter_relative_path(self): - filename = os.path.join(settings.TEST_DIR, 'whatever', '..', 'media', 'whatever/../css/url/test.css') + filename = os.path.join(settings.TEST_DIR, 'whatever', '..', 'static', 'whatever/../css/url/test.css') imagefilename = os.path.join(settings.COMPRESS_ROOT, 'img/python.png') params = { 'url': settings.COMPRESS_URL, @@ -153,7 +153,7 @@ class CssAbsolutizingTestCase(TestCase): "p { filter: Alpha(src='%(url)simg/python.png?%(hash)s') }") % params filter = CssAbsoluteFilter(self.content) self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css')) - settings.COMPRESS_URL = params['url'] = 'https://media.example.com/' + settings.COMPRESS_URL = params['url'] = 'https://static.example.com/' filter = CssAbsoluteFilter(self.content) output = ("p { background: url('%(url)simg/python.png?%(hash)s') }" "p { filter: Alpha(src='%(url)simg/python.png?%(hash)s') }") % params @@ -165,22 +165,22 @@ class CssAbsolutizingTestCase(TestCase): 'hash2': self.hashing_func(os.path.join(settings.COMPRESS_ROOT, 'img/add.png')), } self.assertEqual([u"""\ -p { background: url('/media/img/python.png?%(hash1)s'); } -p { background: url('/media/img/python.png?%(hash1)s'); } -p { background: url('/media/img/python.png?%(hash1)s'); } -p { background: url('/media/img/python.png?%(hash1)s'); } -p { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/media/img/python.png?%(hash1)s'); } +p { background: url('/static/img/python.png?%(hash1)s'); } +p { background: url('/static/img/python.png?%(hash1)s'); } +p { background: url('/static/img/python.png?%(hash1)s'); } +p { background: url('/static/img/python.png?%(hash1)s'); } +p { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/static/img/python.png?%(hash1)s'); } """ % hash_dict, u"""\ -p { background: url('/media/img/add.png?%(hash2)s'); } -p { background: url('/media/img/add.png?%(hash2)s'); } -p { background: url('/media/img/add.png?%(hash2)s'); } -p { background: url('/media/img/add.png?%(hash2)s'); } -p { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/media/img/add.png?%(hash2)s'); } +p { background: url('/static/img/add.png?%(hash2)s'); } +p { background: url('/static/img/add.png?%(hash2)s'); } +p { background: url('/static/img/add.png?%(hash2)s'); } +p { background: url('/static/img/add.png?%(hash2)s'); } +p { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/static/img/add.png?%(hash2)s'); } """ % hash_dict], list(self.css_node.hunks())) def test_guess_filename(self): - for base_url in ('/media/', 'http://media.example.com/'): + for base_url in ('/static/', 'http://static.example.com/'): settings.COMPRESS_URL = base_url url = '%s/img/python.png' % settings.COMPRESS_URL.rstrip('/') path = os.path.join(settings.COMPRESS_ROOT, 'img/python.png') @@ -196,8 +196,8 @@ class CssAbsolutizingTestCaseWithHash(CssAbsolutizingTestCase): def setUp(self): super(CssAbsolutizingTestCaseWithHash, self).setUp() self.css = """ - - + + """ self.css_node = CssCompressor(self.css) @@ -209,10 +209,10 @@ class CssDataUriTestCase(TestCase): 'compressor.filters.css_default.CssAbsoluteFilter', 'compressor.filters.datauri.CssDataUriFilter', ] - settings.COMPRESS_URL = '/media/' + settings.COMPRESS_URL = '/static/' settings.COMPRESS_CSS_HASHING_METHOD = 'mtime' self.css = """ - + """ self.css_node = CssCompressor(self.css) @@ -220,7 +220,7 @@ class CssDataUriTestCase(TestCase): datauri_hash = get_hashed_mtime(os.path.join(settings.COMPRESS_ROOT, 'img/python.png')) out = [u'''.add { background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJvSURBVDjLpZPrS5NhGIf9W7YvBYOkhlkoqCklWChv2WyKik7blnNris72bi6dus0DLZ0TDxW1odtopDs4D8MDZuLU0kXq61CijSIIasOvv94VTUfLiB74fXngup7nvrnvJABJ/5PfLnTTdcwOj4RsdYmo5glBWP6iOtzwvIKSWstI0Wgx80SBblpKtE9KQs/We7EaWoT/8wbWP61gMmCH0lMDvokT4j25TiQU/ITFkek9Ow6+7WH2gwsmahCPdwyw75uw9HEO2gUZSkfyI9zBPCJOoJ2SMmg46N61YO/rNoa39Xi41oFuXysMfh36/Fp0b7bAfWAH6RGi0HglWNCbzYgJaFjRv6zGuy+b9It96N3SQvNKiV9HvSaDfFEIxXItnPs23BzJQd6DDEVM0OKsoVwBG/1VMzpXVWhbkUM2K4oJBDYuGmbKIJ0qxsAbHfRLzbjcnUbFBIpx/qH3vQv9b3U03IQ/HfFkERTzfFj8w8jSpR7GBE123uFEYAzaDRIqX/2JAtJbDat/COkd7CNBva2cMvq0MGxp0PRSCPF8BXjWG3FgNHc9XPT71Ojy3sMFdfJRCeKxEsVtKwFHwALZfCUk3tIfNR8XiJwc1LmL4dg141JPKtj3WUdNFJqLGFVPC4OkR4BxajTWsChY64wmCnMxsWPCHcutKBxMVp5mxA1S+aMComToaqTRUQknLTH62kHOVEE+VQnjahscNCy0cMBWsSI0TCQcZc5ALkEYckL5A5noWSBhfm2AecMAjbcRWV0pUTh0HE64TNf0mczcnnQyu/MilaFJCae1nw2fbz1DnVOxyGTlKeZft/Ff8x1BRssfACjTwQAAAABJRU5ErkJggg=="); } .add-with-hash { background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJvSURBVDjLpZPrS5NhGIf9W7YvBYOkhlkoqCklWChv2WyKik7blnNris72bi6dus0DLZ0TDxW1odtopDs4D8MDZuLU0kXq61CijSIIasOvv94VTUfLiB74fXngup7nvrnvJABJ/5PfLnTTdcwOj4RsdYmo5glBWP6iOtzwvIKSWstI0Wgx80SBblpKtE9KQs/We7EaWoT/8wbWP61gMmCH0lMDvokT4j25TiQU/ITFkek9Ow6+7WH2gwsmahCPdwyw75uw9HEO2gUZSkfyI9zBPCJOoJ2SMmg46N61YO/rNoa39Xi41oFuXysMfh36/Fp0b7bAfWAH6RGi0HglWNCbzYgJaFjRv6zGuy+b9It96N3SQvNKiV9HvSaDfFEIxXItnPs23BzJQd6DDEVM0OKsoVwBG/1VMzpXVWhbkUM2K4oJBDYuGmbKIJ0qxsAbHfRLzbjcnUbFBIpx/qH3vQv9b3U03IQ/HfFkERTzfFj8w8jSpR7GBE123uFEYAzaDRIqX/2JAtJbDat/COkd7CNBva2cMvq0MGxp0PRSCPF8BXjWG3FgNHc9XPT71Ojy3sMFdfJRCeKxEsVtKwFHwALZfCUk3tIfNR8XiJwc1LmL4dg141JPKtj3WUdNFJqLGFVPC4OkR4BxajTWsChY64wmCnMxsWPCHcutKBxMVp5mxA1S+aMComToaqTRUQknLTH62kHOVEE+VQnjahscNCy0cMBWsSI0TCQcZc5ALkEYckL5A5noWSBhfm2AecMAjbcRWV0pUTh0HE64TNf0mczcnnQyu/MilaFJCae1nw2fbz1DnVOxyGTlKeZft/Ff8x1BRssfACjTwQAAAABJRU5ErkJggg=="); } -.python { background-image: url("/media/img/python.png?%s"); } +.python { background-image: url("/static/img/python.png?%s"); } .datauri { background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IAAAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1JREFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jqch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0 vr4MkhoXe0rZigAAAABJRU5ErkJggg=="); } ''' % datauri_hash] self.assertEqual(out, list(self.css_node.hunks())) diff --git a/compressor/tests/test_jinja2ext.py b/compressor/tests/test_jinja2ext.py index 9f1a0dc..cb2e012 100644 --- a/compressor/tests/test_jinja2ext.py +++ b/compressor/tests/test_jinja2ext.py @@ -55,61 +55,61 @@ class TestJinja2CompressorExtension(TestCase): def test_empty_tag(self): template = self.env.from_string(u"""{% compress js %}{% block js %} {% endblock %}{% endcompress %}""") - context = {'MEDIA_URL': settings.COMPRESS_URL} + context = {'STATIC_URL': settings.COMPRESS_URL} self.assertEqual(u'', template.render(context)) def test_css_tag(self): template = self.env.from_string(u"""{% compress css -%} - + - + {% endcompress %}""") - context = {'MEDIA_URL': settings.COMPRESS_URL} - out = css_tag("/media/CACHE/css/e41ba2cc6982.css") + context = {'STATIC_URL': settings.COMPRESS_URL} + out = css_tag("/static/CACHE/css/e41ba2cc6982.css") self.assertEqual(out, template.render(context)) def test_nonascii_css_tag(self): template = self.env.from_string(u"""{% compress css -%} - + {% endcompress %}""") - context = {'MEDIA_URL': settings.COMPRESS_URL} - out = css_tag("/media/CACHE/css/799f6defe43c.css") + context = {'STATIC_URL': settings.COMPRESS_URL} + out = css_tag("/static/CACHE/css/799f6defe43c.css") self.assertEqual(out, template.render(context)) def test_js_tag(self): template = self.env.from_string(u"""{% compress js -%} - + {% endcompress %}""") - context = {'MEDIA_URL': settings.COMPRESS_URL} - out = u'' + context = {'STATIC_URL': settings.COMPRESS_URL} + out = u'' self.assertEqual(out, template.render(context)) def test_nonascii_js_tag(self): template = self.env.from_string(u"""{% compress js -%} - + {% endcompress %}""") - context = {'MEDIA_URL': settings.COMPRESS_URL} - out = u'' + context = {'STATIC_URL': settings.COMPRESS_URL} + out = u'' self.assertEqual(out, template.render(context)) def test_nonascii_latin1_js_tag(self): template = self.env.from_string(u"""{% compress js -%} - + {% endcompress %}""") - context = {'MEDIA_URL': settings.COMPRESS_URL} - out = u'' + context = {'STATIC_URL': settings.COMPRESS_URL} + out = u'' self.assertEqual(out, template.render(context)) def test_css_inline(self): template = self.env.from_string(u"""{% compress css, inline -%} - + {% endcompress %}""") - context = {'MEDIA_URL': settings.COMPRESS_URL} + context = {'STATIC_URL': settings.COMPRESS_URL} out = '\n'.join([ '', @@ -118,10 +118,10 @@ class TestJinja2CompressorExtension(TestCase): def test_js_inline(self): template = self.env.from_string(u"""{% compress js, inline -%} - + {% endcompress %}""") - context = {'MEDIA_URL': settings.COMPRESS_URL} + context = {'STATIC_URL': settings.COMPRESS_URL} out = '' self.assertEqual(out, template.render(context)) @@ -132,7 +132,7 @@ class TestJinja2CompressorExtension(TestCase): u'{% endcompress %}') - out = u'' + out = u'' settings.COMPRESS_ENABLED = org_COMPRESS_ENABLED - context = {'MEDIA_URL': settings.COMPRESS_URL} + context = {'STATIC_URL': settings.COMPRESS_URL} self.assertEqual(out, template.render(context)) diff --git a/compressor/tests/test_offline.py b/compressor/tests/test_offline.py index 304ea61..e9f706f 100644 --- a/compressor/tests/test_offline.py +++ b/compressor/tests/test_offline.py @@ -55,7 +55,7 @@ class OfflineTestCaseMixin(object): count, result = CompressCommand().compress(log=self.log, verbosity=self.verbosity) self.assertEqual(1, count) self.assertEqual([ - u'' % (self.expected_hash, ), + u'' % (self.expected_hash, ), ], result) rendered_template = self.template.render(Context(settings.COMPRESS_OFFLINE_CONTEXT)) self.assertEqual(rendered_template, "".join(result) + "\n") @@ -97,8 +97,8 @@ class OfflineGenerationBlockSuperTestCaseWithExtraContent(OfflineTestCaseMixin, count, result = CompressCommand().compress(log=self.log, verbosity=self.verbosity) self.assertEqual(2, count) self.assertEqual([ - u'', - u'' + u'', + u'' ], result) rendered_template = self.template.render(Context(settings.COMPRESS_OFFLINE_CONTEXT)) self.assertEqual(rendered_template, "".join(result) + "\n") @@ -156,8 +156,8 @@ class OfflineGenerationTestCaseErrors(OfflineTestCaseMixin, TestCase): def test_offline(self): count, result = CompressCommand().compress(log=self.log, verbosity=self.verbosity) self.assertEqual(2, count) - self.assertIn(u'', result) - self.assertIn(u'', result) + self.assertIn(u'', result) + self.assertIn(u'', result) class OfflineGenerationTestCaseWithError(OfflineTestCaseMixin, TestCase): @@ -209,7 +209,7 @@ class OfflineGenerationTestCase(OfflineTestCaseMixin, TestCase): default_storage.delete(manifest_path) self.assertEqual(1, count) self.assertEqual([ - u'' % (self.expected_hash, ), + u'' % (self.expected_hash, ), ], result) rendered_template = self.template.render(Context(settings.COMPRESS_OFFLINE_CONTEXT)) self.assertEqual(rendered_template, "".join(result) + "\n") diff --git a/compressor/tests/test_parsers.py b/compressor/tests/test_parsers.py index 6d0e658..04ec924 100644 --- a/compressor/tests/test_parsers.py +++ b/compressor/tests/test_parsers.py @@ -47,16 +47,16 @@ class Html5LibParserTests(ParserTestCase, CompressorTestCase): super(Html5LibParserTests, self).setUp() # special version of the css since the parser sucks self.css = """\ - + -""" +""" self.css_node = CssCompressor(self.css) def test_css_split(self): out = [ - (SOURCE_FILE, os.path.join(settings.COMPRESS_ROOT, u'css', u'one.css'), u'css/one.css', u''), + (SOURCE_FILE, os.path.join(settings.COMPRESS_ROOT, u'css', u'one.css'), u'css/one.css', u''), (SOURCE_HUNK, u'p { border:5px solid green;}', None, u''), - (SOURCE_FILE, os.path.join(settings.COMPRESS_ROOT, u'css', u'two.css'), u'css/two.css', u''), + (SOURCE_FILE, os.path.join(settings.COMPRESS_ROOT, u'css', u'two.css'), u'css/two.css', u''), ] split = self.css_node.split_contents() split = [(x[0], x[1], x[2], self.css_node.parser.elem_str(x[3])) for x in split] @@ -64,7 +64,7 @@ class Html5LibParserTests(ParserTestCase, CompressorTestCase): def test_js_split(self): out = [ - (SOURCE_FILE, os.path.join(settings.COMPRESS_ROOT, u'js', u'one.js'), u'js/one.js', u''), + (SOURCE_FILE, os.path.join(settings.COMPRESS_ROOT, u'js', u'one.js'), u'js/one.js', u''), (SOURCE_HUNK, u'obj.value = "value";', None, u''), ] split = self.js_node.split_contents() diff --git a/compressor/tests/test_signals.py b/compressor/tests/test_signals.py index 529d0b0..b4ece9c 100644 --- a/compressor/tests/test_signals.py +++ b/compressor/tests/test_signals.py @@ -14,13 +14,13 @@ class PostCompressSignalTestCase(TestCase): settings.COMPRESS_PRECOMPILERS = {} settings.COMPRESS_DEBUG_TOGGLE = 'nocompress' self.css = """\ - + -""" +""" self.css_node = CssCompressor(self.css) self.js = """\ - + """ self.js_node = JsCompressor(self.js) @@ -55,9 +55,9 @@ class PostCompressSignalTestCase(TestCase): def test_css_signal_multiple_media_attributes(self): css = """\ - + -""" +""" css_node = CssCompressor(css) def listener(sender, **kwargs): diff --git a/compressor/tests/test_storages.py b/compressor/tests/test_storages.py index 6a6f4d6..713002e 100644 --- a/compressor/tests/test_storages.py +++ b/compressor/tests/test_storages.py @@ -24,13 +24,13 @@ class StorageTestCase(TestCase): def test_css_tag_with_storage(self): template = u"""{% load compress %}{% compress css %} - + - + {% endcompress %} """ - context = {'MEDIA_URL': settings.COMPRESS_URL} - out = css_tag("/media/CACHE/css/1d4424458f88.css") + context = {'STATIC_URL': settings.COMPRESS_URL} + out = css_tag("/static/CACHE/css/1d4424458f88.css") self.assertEqual(out, render(template, context)) def test_race_condition_handling(self): diff --git a/compressor/tests/test_templatetags.py b/compressor/tests/test_templatetags.py index f476893..151b785 100644 --- a/compressor/tests/test_templatetags.py +++ b/compressor/tests/test_templatetags.py @@ -28,7 +28,7 @@ class TemplatetagTestCase(TestCase): def setUp(self): self.old_enabled = settings.COMPRESS_ENABLED settings.COMPRESS_ENABLED = True - self.context = {'MEDIA_URL': settings.COMPRESS_URL} + self.context = {'STATIC_URL': settings.COMPRESS_URL} def tearDown(self): settings.COMPRESS_ENABLED = self.old_enabled @@ -40,58 +40,58 @@ class TemplatetagTestCase(TestCase): def test_css_tag(self): template = u"""{% load compress %}{% compress css %} - + - + {% endcompress %}""" - out = css_tag("/media/CACHE/css/e41ba2cc6982.css") + out = css_tag("/static/CACHE/css/e41ba2cc6982.css") self.assertEqual(out, render(template, self.context)) maxDiff = None def test_uppercase_rel(self): template = u"""{% load compress %}{% compress css %} - + - + {% endcompress %}""" - out = css_tag("/media/CACHE/css/e41ba2cc6982.css") + out = css_tag("/static/CACHE/css/e41ba2cc6982.css") self.assertEqual(out, render(template, self.context)) def test_nonascii_css_tag(self): template = u"""{% load compress %}{% compress css %} - + {% endcompress %} """ - out = css_tag("/media/CACHE/css/799f6defe43c.css") + out = css_tag("/static/CACHE/css/799f6defe43c.css") self.assertEqual(out, render(template, self.context)) def test_js_tag(self): template = u"""{% load compress %}{% compress js %} - + {% endcompress %} """ - out = u'' + out = u'' self.assertEqual(out, render(template, self.context)) def test_nonascii_js_tag(self): template = u"""{% load compress %}{% compress js %} - + {% endcompress %} """ - out = u'' + out = u'' self.assertEqual(out, render(template, self.context)) def test_nonascii_latin1_js_tag(self): template = u"""{% load compress %}{% compress js %} - + {% endcompress %} """ - out = u'' + out = u'' self.assertEqual(out, render(template, self.context)) def test_compress_tag_with_illegal_arguments(self): @@ -102,7 +102,7 @@ class TemplatetagTestCase(TestCase): def test_debug_toggle(self): template = u"""{% load compress %}{% compress js %} - + {% endcompress %} """ @@ -111,7 +111,7 @@ class TemplatetagTestCase(TestCase): GET = {settings.COMPRESS_DEBUG_TOGGLE: 'true'} context = dict(self.context, request=MockDebugRequest()) - out = u""" + out = u""" """ self.assertEqual(out, render(template, context)) @@ -144,7 +144,7 @@ class PrecompilerTemplatetagTestCase(TestCase): ('text/coffeescript', '%s %s' % (python, precompiler)), ('text/less', '%s %s' % (python, precompiler)), ) - self.context = {'MEDIA_URL': settings.COMPRESS_URL} + self.context = {'STATIC_URL': settings.COMPRESS_URL} def tearDown(self): settings.COMPRESS_ENABLED = self.old_enabled @@ -154,7 +154,7 @@ class PrecompilerTemplatetagTestCase(TestCase): template = u"""{% load compress %}{% compress js %} {% endcompress %}""" - out = script(src="/media/CACHE/js/e920d58f166d.js") + out = script(src="/static/CACHE/js/e920d58f166d.js") self.assertEqual(out, render(template, self.context)) def test_compress_coffeescript_tag_and_javascript_tag(self): @@ -162,7 +162,7 @@ class PrecompilerTemplatetagTestCase(TestCase): {% endcompress %}""" - out = script(src="/media/CACHE/js/ef6b32a54575.js") + out = script(src="/static/CACHE/js/ef6b32a54575.js") self.assertEqual(out, render(template, self.context)) def test_coffeescript_and_js_tag_with_compress_enabled_equals_false(self): @@ -197,11 +197,11 @@ class PrecompilerTemplatetagTestCase(TestCase): try: template = u""" {% load compress %}{% compress js %} - {% endcompress %}""" - out = script(src="/media/CACHE/js/one.95cfb869eead.js") + out = script(src="/static/CACHE/js/one.95cfb869eead.js") self.assertEqual(out, render(template, self.context)) finally: settings.COMPRESS_ENABLED = self.old_enabled @@ -212,16 +212,16 @@ class PrecompilerTemplatetagTestCase(TestCase): try: template = u""" {% load compress %}{% compress js %} - - - + {% endcompress %}""" - out = '\n'.join([script(src="/media/CACHE/js/one.95cfb869eead.js"), - script(scripttype="", src="/media/js/one.js"), - script(src="/media/CACHE/js/one.81a2cd965815.js")]) + out = '\n'.join([script(src="/static/CACHE/js/one.95cfb869eead.js"), + script(scripttype="", src="/static/js/one.js"), + script(src="/static/CACHE/js/one.81a2cd965815.js")]) self.assertEqual(out, render(template, self.context)) finally: @@ -234,12 +234,12 @@ class PrecompilerTemplatetagTestCase(TestCase): try: template = u""" {% load compress %}{% compress css %} - - + + {% endcompress %}""" - out = ''.join(['', - '']) + out = ''.join(['', + '']) self.assertEqual(out, render(template, self.context)) finally: @@ -252,14 +252,14 @@ class PrecompilerTemplatetagTestCase(TestCase): try: template = u""" {% load compress %}{% compress css %} - - - + + + {% endcompress %}""" - out = ''.join(['', - '', - '']) + out = ''.join(['', + '', + '']) self.assertEqual(out, render(template, self.context)) finally: settings.COMPRESS_ENABLED = self.old_enabled diff --git a/docs/quickstart.txt b/docs/quickstart.txt index f32c52c..d922c8b 100644 --- a/docs/quickstart.txt +++ b/docs/quickstart.txt @@ -18,7 +18,7 @@ Installation * See the list of :ref:`settings` to modify Django Compressor's default behaviour and make adjustments for your website. -* In case you use Django 1.3's staticfiles_ contrib app (or its standalone +* In case you use Django's staticfiles_ contrib app (or its standalone counterpart django-staticfiles_) you have to add Django Compressor's file finder to the ``STATICFILES_FINDERS`` setting, for example with ``django.contrib.staticfiles``: diff --git a/docs/remote-storages.txt b/docs/remote-storages.txt index 2f4d784..91e7c2e 100644 --- a/docs/remote-storages.txt +++ b/docs/remote-storages.txt @@ -39,7 +39,7 @@ The storage backend to save the compressed files needs to be changed, too:: Using staticfiles ^^^^^^^^^^^^^^^^^ -If you are using Django 1.3's staticfiles_ contrib app or the standalone +If you are using Django's staticfiles_ contrib app or the standalone app django-staticfiles_, you'll need to use a temporary filesystem cache for Django Compressor to know which files to compress. Since staticfiles provides a management command to collect static files from various diff --git a/docs/settings.txt b/docs/settings.txt index 81a29b6..35e1fb4 100644 --- a/docs/settings.txt +++ b/docs/settings.txt @@ -43,30 +43,20 @@ Base settings .. attribute:: COMPRESS_URL - :Default: ``STATIC_URL`` (``MEDIA_URL`` for older Django versions) + :Default: ``STATIC_URL`` Controls the URL that linked files will be read from and compressed files will be written to. - .. note:: - - This setting defaults to ``MEDIA_URL`` in case ``STATIC_URL`` - is not given or empty, e.g. on older Django versions (< 1.3). - .. attribute:: COMPRESS_ROOT - :Default: ``STATIC_ROOT`` (``MEDIA_ROOT`` for older Django versions) + :Default: ``STATIC_ROOT`` Controls the absolute file path that linked static will be read from and compressed static will be written to when using the default :attr:`~django.conf.settings.COMPRESS_STORAGE` ``compressor.storage.CompressorFileStorage``. - .. note:: - - This setting defaults to ``MEDIA_ROOT`` in case ``STATIC_ROOT`` - is not given, e.g. on older Django versions (< 1.3). - .. attribute:: COMPRESS_OUTPUT_DIR :Default: ``'CACHE'`` @@ -422,7 +412,7 @@ Offline settings .. attribute:: COMPRESS_OFFLINE_CONTEXT - :Default: ``{'MEDIA_URL': settings.MEDIA_URL}`` + :Default: ``{'STATIC_URL': settings.STATIC_URL}`` The context to be used by the ``compress`` management command when rendering the contents of ``{% compress %}`` template tags and saving the result in the diff --git a/docs/usage.txt b/docs/usage.txt index 41f0aeb..bfdffcd 100644 --- a/docs/usage.txt +++ b/docs/usage.txt @@ -145,8 +145,7 @@ command:: } If not specified, the ``COMPRESS_OFFLINE_CONTEXT`` will by default contain -the commonly used setting to refer to saved files ``MEDIA_URL`` and -``STATIC_URL`` (if specified in the settings). +the commonly used setting to refer to saved files ``STATIC_URL``. The result of running the ``compress`` management command will be cached in a file called ``manifest.json`` using the :attr:`configured storage