Repository: django-compressor/django-compressor

Issue:
Add option for CssAbsoluteFilter COMPRESS_CSS_HASHING_METHOD to be None
I am currently versioning my static files by application version in my static root.  I don't need to add ?hash to my files.  It would be preferable to be able to disable appending a querystring to file names.



Discussion:
I would also like if this solution comes in the django_compress because I had this question also on [StackOverflow](http://stackoverflow.com/questions/15685469/remove-query-string-from-inline-css) too.
:+1:

I've done this in a fork.  I will try to put a pull request together soon if it will help other people.  I was waiting until I completed some fixes dealing with the handling of line endings between Windows/Linux causing me pains.

:thumbsup: I'd love this to land as well. Using `CachedStaticFilesStorage` (from staticfiles) with any current value of `COMPRESS_CSS_HASHING_METHOD` for 'CssAbsoluteFilter' means that the hash ends up in the url twice, with no way to get around it.


Resolving patch:
diff --git a/compressor/filters/css_default.py b/compressor/filters/css_default.py
--- a/compressor/filters/css_default.py
+++ b/compressor/filters/css_default.py
@@ -70,6 +70,8 @@ def add_suffix(self, url):
                 suffix = get_hashed_mtime(filename)
             elif settings.COMPRESS_CSS_HASHING_METHOD in ("hash", "content"):
                 suffix = get_hashed_content(filename)
+            elif settings.COMPRESS_CSS_HASHING_METHOD is None:
+                suffix = None
             else:
                 raise FilterError('COMPRESS_CSS_HASHING_METHOD is configured '
                                   'with an unknown method (%s).' %


Test patch:
diff --git a/compressor/tests/test_filters.py b/compressor/tests/test_filters.py
--- a/compressor/tests/test_filters.py
+++ b/compressor/tests/test_filters.py
@@ -123,6 +123,24 @@ def tearDown(self):
         settings.COMPRESS_URL = self.old_url
         settings.COMPRESS_CSS_HASHING_METHOD = self.old_hashing_method
 
+    def test_css_no_hash(self):
+        settings.COMPRESS_CSS_HASHING_METHOD = None
+        filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
+        params = {
+            'url': settings.COMPRESS_URL,
+        }
+        output = ("p { background: url('%(url)simg/python.png') }"
+                  "p { filter: Alpha(src='%(url)simg/python.png') }") % params
+        filter = CssAbsoluteFilter(self.content)
+        self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
+
+        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') }"
+                  "p { filter: Alpha(src='%(url)simg/python.png') }") % params
+        self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
+
     def test_css_absolute_filter(self):
         filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
         imagefilename = os.path.join(settings.COMPRESS_ROOT, 'img/python.png')
@@ -134,6 +152,7 @@ def test_css_absolute_filter(self):
                   "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://static.example.com/'
         filter = CssAbsoluteFilter(self.content)
         filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
@@ -153,6 +172,7 @@ def test_css_absolute_filter_url_fragment(self):
         output = "p { background: url('%(url)simg/python.png?%(hash)s#foo') }" % params
         filter = CssAbsoluteFilter(content)
         self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
+
         settings.COMPRESS_URL = params['url'] = 'http://media.example.com/'
         filter = CssAbsoluteFilter(content)
         filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
@@ -164,6 +184,7 @@ def test_css_absolute_filter_only_url_fragment(self):
         content = "p { background: url('#foo') }"
         filter = CssAbsoluteFilter(content)
         self.assertEqual(content, filter.input(filename=filename, basename='css/url/test.css'))
+
         settings.COMPRESS_URL = 'http://media.example.com/'
         filter = CssAbsoluteFilter(content)
         filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
@@ -181,6 +202,7 @@ def test_css_absolute_filter_querystring(self):
         output = "p { background: url('%(url)simg/python.png?foo&%(hash)s') }" % params
         filter = CssAbsoluteFilter(content)
         self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
+
         settings.COMPRESS_URL = params['url'] = 'http://media.example.com/'
         filter = CssAbsoluteFilter(content)
         filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
@@ -198,6 +220,7 @@ def test_css_absolute_filter_https(self):
                   "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://static.example.com/'
         filter = CssAbsoluteFilter(self.content)
         filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
@@ -216,6 +239,7 @@ def test_css_absolute_filter_relative_path(self):
                   "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://static.example.com/'
         filter = CssAbsoluteFilter(self.content)
         output = ("p { background: url('%(url)simg/python.png?%(hash)s') }"
@@ -256,14 +280,6 @@ class CssAbsolutizingTestCaseWithHash(CssAbsolutizingTestCase):
     hashing_method = 'content'
     hashing_func = staticmethod(get_hashed_content)
 
-    def setUp(self):
-        super(CssAbsolutizingTestCaseWithHash, self).setUp()
-        self.css = """
-        <link rel="stylesheet" href="/static/css/url/url1.css" type="text/css" charset="utf-8">
-        <link rel="stylesheet" href="/static/css/url/2/url2.css" type="text/css" charset="utf-8">
-        """
-        self.css_node = CssCompressor(self.css)
-
 
 class CssDataUriTestCase(TestCase):
     def setUp(self):