Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use staticfiles finders to find media files if STATIC_URL is defined #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions compressor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
from django.template.loader import render_to_string
from django.core.files.base import ContentFile
from django.core.files.storage import default_storage
try:
from django.contrib.staticfiles import finders
except ImportError:
finders = None

from compressor.conf import settings
from compressor import filters
Expand Down Expand Up @@ -62,6 +66,10 @@ def split_contents(self):
raise NotImplementedError('split_contents must be defined in a subclass')

def get_filename(self, url):
if getattr(django_settings,'STATIC_URL') and finders:
# if using staticfiles
basename = url[len(self.media_url):]
return finders.find(basename)
if not url.startswith(self.media_url):
raise UncompressableFileError('"%s" is not in COMPRESS_URL ("%s") and can not be compressed' % (url, self.media_url))
url = os.path.realpath(url)
Expand Down
2 changes: 1 addition & 1 deletion compressor/management/commands/css_slate.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os
from optparse import make_option, OptionError
from django.conf import settings
from django.core.management.base import BaseCommand
from django.core.exceptions import ImproperlyConfigured

from compressor import CssCompressor
from compressor.conf import settings

class Command(BaseCommand):
option_list = BaseCommand.option_list + (
Expand Down