From 77a800a2a4e9fc967e9dcd7ed87c79516b568fff Mon Sep 17 00:00:00 2001 From: Rich Leland Date: Tue, 11 Oct 2011 12:23:08 -0400 Subject: [PATCH] Tweak how compressor gets the path when using remote storages --- compressor/base.py | 10 ++++++++-- docs/remote-storages.txt | 3 --- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/compressor/base.py b/compressor/base.py index 02e1675..502ce89 100644 --- a/compressor/base.py +++ b/compressor/base.py @@ -3,6 +3,7 @@ import os import codecs from django.core.files.base import ContentFile +from django.core.files.storage import get_storage_class from django.template import Context from django.template.loader import render_to_string from django.utils.encoding import smart_unicode @@ -69,7 +70,12 @@ class Compressor(object): # first try to find it with staticfiles (in debug mode) filename = None 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 elif self.finders: filename = self.finders.find(basename) @@ -261,6 +267,6 @@ class Compressor(object): final_context.update(self.context) final_context.update(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" % (self.type, mode), final_context) diff --git a/docs/remote-storages.txt b/docs/remote-storages.txt index 4cac09d..9e20233 100644 --- a/docs/remote-storages.txt +++ b/docs/remote-storages.txt @@ -68,9 +68,6 @@ integrated. self.local_storage._save(name, content) return name - def path(self, name): - return self.local_storage.path(name) - #. Set your :ref:`COMPRESS_STORAGE ` and STATICFILES_STORAGE_ settings to the dotted path of your custom cached storage backend, e.g. ``'mysite.storage.CachedS3BotoStorage'``.