Last active
June 5, 2016 10:41
-
-
Save Chronial/45ce9f33615a3b24c51f to your computer and use it in GitHub Desktop.
Whitenoise support for django compressor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf import settings | |
from whitenoise.django import DjangoWhiteNoise | |
class DjangoCompressWhiteNoise(DjangoWhiteNoise): | |
def __call__(self, environ, start_response): | |
# Handle files generated on the fly by django-compressor | |
url = environ['PATH_INFO'] | |
if url.startswith(self.static_prefix) and url not in self.files: | |
if self.is_compressed_file(url): | |
self.files[url] = self.find_file(url) | |
return super().__call__(environ, start_response) | |
def is_compressed_file(self, url): | |
if not url.startswith(self.static_prefix): | |
return False | |
path = url[len(self.static_prefix):] | |
return path.startswith(settings.COMPRESS_OUTPUT_DIR + "/") | |
def is_immutable_file(self, path, url): | |
if self.is_compressed_file(url): | |
return True | |
else: | |
return super().is_immutable_file(path, url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment