Tweak how compressor gets the path when using remote storages
This commit is contained in:
@@ -3,6 +3,7 @@ import os
|
|||||||
import codecs
|
import codecs
|
||||||
|
|
||||||
from django.core.files.base import ContentFile
|
from django.core.files.base import ContentFile
|
||||||
|
from django.core.files.storage import get_storage_class
|
||||||
from django.template import Context
|
from django.template import Context
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.utils.encoding import smart_unicode
|
from django.utils.encoding import smart_unicode
|
||||||
@@ -69,7 +70,12 @@ class Compressor(object):
|
|||||||
# first try to find it with staticfiles (in debug mode)
|
# first try to find it with staticfiles (in debug mode)
|
||||||
filename = None
|
filename = None
|
||||||
if self.storage.exists(basename):
|
if self.storage.exists(basename):
|
||||||
filename = self.storage.path(basename)
|
try:
|
||||||
|
filename = self.storage.path(basename)
|
||||||
|
except NotImplementedError:
|
||||||
|
# remote storages don't implement path, access the file locally
|
||||||
|
local_storage = get_storage_class('compressor.storage.CompressorFileStorage')()
|
||||||
|
filename = local_storage.path(basename)
|
||||||
# secondly try finding the file in the root
|
# secondly try finding the file in the root
|
||||||
elif self.finders:
|
elif self.finders:
|
||||||
filename = self.finders.find(basename)
|
filename = self.finders.find(basename)
|
||||||
@@ -261,6 +267,6 @@ class Compressor(object):
|
|||||||
final_context.update(self.context)
|
final_context.update(self.context)
|
||||||
final_context.update(context)
|
final_context.update(context)
|
||||||
final_context.update(self.extra_context)
|
final_context.update(self.extra_context)
|
||||||
post_compress.send(sender='django-compressor', type=self.type, mode=mode, context=final_context)
|
post_compress.send(sender='django-compressor', type=self.type, mode=mode, context=final_context)
|
||||||
return render_to_string("compressor/%s_%s.html" %
|
return render_to_string("compressor/%s_%s.html" %
|
||||||
(self.type, mode), final_context)
|
(self.type, mode), final_context)
|
||||||
|
@@ -68,9 +68,6 @@ integrated.
|
|||||||
self.local_storage._save(name, content)
|
self.local_storage._save(name, content)
|
||||||
return name
|
return name
|
||||||
|
|
||||||
def path(self, name):
|
|
||||||
return self.local_storage.path(name)
|
|
||||||
|
|
||||||
#. Set your :ref:`COMPRESS_STORAGE <compress_storage>` and STATICFILES_STORAGE_
|
#. Set your :ref:`COMPRESS_STORAGE <compress_storage>` and STATICFILES_STORAGE_
|
||||||
settings to the dotted path of your custom cached storage backend, e.g.
|
settings to the dotted path of your custom cached storage backend, e.g.
|
||||||
``'mysite.storage.CachedS3BotoStorage'``.
|
``'mysite.storage.CachedS3BotoStorage'``.
|
||||||
|
Reference in New Issue
Block a user