Commit 70cc7aa3 authored by Jannis Leidel's avatar Jannis Leidel

Import settings from compressor.conf again instead of django.conf to make sure...

Import settings from compressor.conf again instead of django.conf to make sure they are loaded correctly.
parent f57e4959
......@@ -2,7 +2,6 @@ from __future__ import with_statement
import os
import codecs
from django.conf import settings
from django.core.files.base import ContentFile
from django.template import Context
from django.template.loader import render_to_string
......@@ -10,6 +9,7 @@ from django.utils.encoding import smart_unicode
from compressor.cache import get_hexdigest, get_mtime
from compressor.conf import settings
from compressor.exceptions import CompressorError, UncompressableFileError
from compressor.filters import CompilerFilter
from compressor.storage import default_storage
......
......@@ -2,13 +2,13 @@ import os
import socket
import time
from django.conf import settings
from django.core.cache import get_cache
from django.utils.encoding import smart_str
from django.utils.functional import SimpleLazyObject
from django.utils.hashcompat import md5_constructor
from django.utils.importlib import import_module
from compressor.conf import settings
from compressor.utils import get_mod_func
_cachekey_func = None
......
import os
from django import VERSION as DJANGO_VERSION
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from appconf import AppConf
class CompressorConf(AppConf):
# Main switch
ENABLED = False
# Allows changing verbosity from the settings.
VERBOSE = False
# GET variable that disables compressor e.g. "nocompress"
DEBUG_TOGGLE = "None"
# the backend to use when parsing the JavaScript or Stylesheet files
PARSER = 'compressor.parser.AutoSelectParser'
OUTPUT_DIR = 'CACHE'
STORAGE = 'compressor.storage.CompressorFileStorage'
CSS_COMPRESSOR = "compressor.css.CssCompressor"
JS_COMPRESSOR = "compressor.js.JsCompressor"
URL = None
ROOT = None
CSS_FILTERS = ['compressor.filters.css_default.CssAbsoluteFilter']
CSS_HASHING_METHOD = 'mtime'
JS_FILTERS = ['compressor.filters.jsmin.JSMinFilter']
PRECOMPILERS = (
# ('text/coffeescript', 'coffee --compile --stdio'),
# ('text/less', 'lessc {infile} {outfile}'),
# ('text/x-sass', 'sass {infile} {outfile}'),
# ('text/x-scss', 'sass --scss {infile} {outfile}'),
)
CLOSURE_COMPILER_BINARY = 'java -jar compiler.jar'
CLOSURE_COMPILER_ARGUMENTS = ''
CSSTIDY_BINARY = 'csstidy'
CSSTIDY_ARGUMENTS = '--template=highest'
YUI_BINARY = 'java -jar yuicompressor.jar'
YUI_CSS_ARGUMENTS = ''
YUI_JS_ARGUMENTS = ''
DATA_URI_MAX_SIZE = 1024
# the cache backend to use
CACHE_BACKEND = None
# the dotted path to the function that creates the cache key
CACHE_KEY_FUNCTION = 'compressor.cache.simple_cachekey'
# rebuilds the cache every 30 days if nothing has changed.
REBUILD_TIMEOUT = 60 * 60 * 24 * 30 # 30 days
# the upper bound on how long any compression should take to be generated
# (used against dog piling, should be a lot smaller than REBUILD_TIMEOUT
MINT_DELAY = 30 # seconds
# check for file changes only after a delay
MTIME_DELAY = 10 # seconds
# enables the offline cache -- also filled by the compress command
OFFLINE = False
# invalidates the offline cache after one year
OFFLINE_TIMEOUT = 60 * 60 * 24 * 365 # 1 year
# The context to be used when compressing the files "offline"
OFFLINE_CONTEXT = {}
class Meta:
prefix = 'compress'
def configure_enabled(self, value):
return value or not settings.DEBUG
def configure_root(self, value):
if value is None:
value = getattr(settings, 'STATIC_ROOT', None)
if not value:
value = settings.MEDIA_ROOT
if not value:
raise ImproperlyConfigured(
"The COMPRESS_ROOT setting must be set.")
return os.path.normcase(os.path.abspath(value))
def configure_url(self, value):
# Uses Django 1.3's STATIC_URL by default or falls back to MEDIA_URL
if value is None:
value = getattr(settings, "STATIC_URL", None)
if not value:
value = settings.MEDIA_URL
if not value.endswith("/"):
raise ImproperlyConfigured("The URL settings (e.g. COMPRESS_URL) "
"must have a trailing slash.")
return value
def configure_cache_backend(self, value):
if value is None:
# If we are on Django 1.3 AND using the new CACHES setting...
if DJANGO_VERSION[:2] >= (1, 3) and hasattr(settings, "CACHES"):
value = "default"
else:
# falling back to the old CACHE_BACKEND setting
value = getattr(settings, "CACHE_BACKEND", None)
if not value:
raise ImproperlyConfigured(
"Please specify a cache backend in your settings.")
return value
def configure_offline_context(self, value):
if not value:
value = {
"MEDIA_URL": settings.MEDIA_URL,
}
# Adds the 1.3 STATIC_URL setting to the context if available
if getattr(settings, "STATIC_URL", None):
value["STATIC_URL"] = settings.STATIC_URL
return value
def configure_precompilers(self, value):
if not isinstance(value, (list, tuple)):
raise ImproperlyConfigured("The COMPRESS_PRECOMPILERS setting "
"must be a list or tuple. Check for missing commas.")
return value
from django.conf import settings
from compressor.base import Compressor, SOURCE_HUNK, SOURCE_FILE
from compressor.conf import settings
from compressor.exceptions import UncompressableFileError
......
......@@ -3,11 +3,11 @@ import os
import logging
import subprocess
import tempfile
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.core.files.temp import NamedTemporaryFile
from django.utils.importlib import import_module
from compressor.conf import settings
from compressor.exceptions import FilterError
from compressor.utils import get_mod_func
from compressor.utils.stringformat import FormattableString as fstr
......
from django.conf import settings
from compressor.conf import settings
from compressor.filters import CompilerFilter
......
......@@ -2,9 +2,8 @@ import os
import re
import posixpath
from django.conf import settings
from compressor.cache import get_hexdigest, get_hashed_mtime
from compressor.conf import settings
from compressor.filters import FilterBase
from compressor.utils import staticfiles
......
from django.conf import settings
from compressor.conf import settings
from compressor.filters import CompilerFilter
......
......@@ -3,8 +3,7 @@ import re
import mimetypes
from base64 import b64encode
from django.conf import settings
from compressor.conf import settings
from compressor.filters import FilterBase
......
from django.conf import settings
from compressor.conf import settings
from compressor.filters import CompilerFilter
......
from django.conf import settings
from compressor.conf import settings
from compressor.base import Compressor, SOURCE_HUNK, SOURCE_FILE
from compressor.exceptions import UncompressableFileError
......
......@@ -9,7 +9,6 @@ try:
except ImportError:
from StringIO import StringIO
from django.conf import settings
from django.core.management.base import NoArgsCommand, CommandError
from django.template import Context, Template, TemplateDoesNotExist, TemplateSyntaxError
from django.utils.datastructures import SortedDict
......@@ -23,6 +22,7 @@ except ImportError:
CachedLoader = None
from compressor.cache import cache, get_offline_cachekey
from compressor.conf import settings
from compressor.exceptions import OfflineGenerationError
from compressor.templatetags.compress import CompressorNode
from compressor.utils import walk, any
......
......@@ -2,9 +2,9 @@ import fnmatch
import os
from optparse import make_option
from django.conf import settings
from django.core.management.base import NoArgsCommand, CommandError
from compressor.conf import settings
from compressor.cache import cache, get_mtime, get_mtime_cachekey
from compressor.utils import walk
......
import os
from django import VERSION as DJANGO_VERSION
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from appconf import AppConf
class CompressorConf(AppConf):
# Main switch
ENABLED = False
# Allows changing verbosity from the settings.
VERBOSE = False
# GET variable that disables compressor e.g. "nocompress"
DEBUG_TOGGLE = "None"
# the backend to use when parsing the JavaScript or Stylesheet files
PARSER = 'compressor.parser.AutoSelectParser'
OUTPUT_DIR = 'CACHE'
STORAGE = 'compressor.storage.CompressorFileStorage'
CSS_COMPRESSOR = "compressor.css.CssCompressor"
JS_COMPRESSOR = "compressor.js.JsCompressor"
URL = None
ROOT = None
CSS_FILTERS = ['compressor.filters.css_default.CssAbsoluteFilter']
CSS_HASHING_METHOD = 'mtime'
JS_FILTERS = ['compressor.filters.jsmin.JSMinFilter']
PRECOMPILERS = (
# ('text/coffeescript', 'coffee --compile --stdio'),
# ('text/less', 'lessc {infile} {outfile}'),
# ('text/x-sass', 'sass {infile} {outfile}'),
# ('text/x-scss', 'sass --scss {infile} {outfile}'),
)
CLOSURE_COMPILER_BINARY = 'java -jar compiler.jar'
CLOSURE_COMPILER_ARGUMENTS = ''
CSSTIDY_BINARY = 'csstidy'
CSSTIDY_ARGUMENTS = '--template=highest'
YUI_BINARY = 'java -jar yuicompressor.jar'
YUI_CSS_ARGUMENTS = ''
YUI_JS_ARGUMENTS = ''
DATA_URI_MAX_SIZE = 1024
# the cache backend to use
CACHE_BACKEND = None
# the dotted path to the function that creates the cache key
CACHE_KEY_FUNCTION = 'compressor.cache.simple_cachekey'
# rebuilds the cache every 30 days if nothing has changed.
REBUILD_TIMEOUT = 60 * 60 * 24 * 30 # 30 days
# the upper bound on how long any compression should take to be generated
# (used against dog piling, should be a lot smaller than REBUILD_TIMEOUT
MINT_DELAY = 30 # seconds
# check for file changes only after a delay
MTIME_DELAY = 10 # seconds
# enables the offline cache -- also filled by the compress command
OFFLINE = False
# invalidates the offline cache after one year
OFFLINE_TIMEOUT = 60 * 60 * 24 * 365 # 1 year
# The context to be used when compressing the files "offline"
OFFLINE_CONTEXT = {}
class Meta:
prefix = 'compress'
def configure_enabled(self, value):
return value or not settings.DEBUG
def configure_root(self, value):
if value is None:
value = getattr(settings, 'STATIC_ROOT', None)
if not value:
value = settings.MEDIA_ROOT
if not value:
raise ImproperlyConfigured(
"The COMPRESS_ROOT setting must be set.")
return os.path.normcase(os.path.abspath(value))
def configure_url(self, value):
# Uses Django 1.3's STATIC_URL by default or falls back to MEDIA_URL
if value is None:
value = getattr(settings, "STATIC_URL", None)
if not value:
value = settings.MEDIA_URL
if not value.endswith("/"):
raise ImproperlyConfigured("The URL settings (e.g. COMPRESS_URL) "
"must have a trailing slash.")
return value
def configure_cache_backend(self, value):
if value is None:
# If we are on Django 1.3 AND using the new CACHES setting...
if DJANGO_VERSION[:2] >= (1, 3) and hasattr(settings, "CACHES"):
value = "default"
else:
# falling back to the old CACHE_BACKEND setting
value = getattr(settings, "CACHE_BACKEND", None)
if not value:
raise ImproperlyConfigured(
"Please specify a cache backend in your settings.")
return value
def configure_offline_context(self, value):
if not value:
value = {
"MEDIA_URL": settings.MEDIA_URL,
}
# Adds the 1.3 STATIC_URL setting to the context if available
if getattr(settings, "STATIC_URL", None):
value["STATIC_URL"] = settings.STATIC_URL
return value
def configure_precompilers(self, value):
if not isinstance(value, (list, tuple)):
raise ImproperlyConfigured("The COMPRESS_PRECOMPILERS setting "
"must be a list or tuple. Check for missing commas.")
return value
......@@ -2,10 +2,11 @@ import gzip
from os import path
from datetime import datetime
from django.conf import settings
from django.core.files.storage import FileSystemStorage, get_storage_class
from django.utils.functional import LazyObject
from compressor.conf import settings
class CompressorFileStorage(FileSystemStorage):
"""
......
from django import template
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from compressor.cache import (cache, cache_get, cache_set,
get_offline_cachekey, get_templatetag_cachekey)
from compressor.conf import settings
from compressor.utils import get_class
register = template.Library()
......
from __future__ import absolute_import
from django.conf import settings as django_settings
from django.core.exceptions import ImproperlyConfigured
INSTALLED = ("staticfiles" in django_settings.INSTALLED_APPS or
"django.contrib.staticfiles" in django_settings.INSTALLED_APPS)
from compressor.conf import settings
INSTALLED = ("staticfiles" in settings.INSTALLED_APPS or
"django.contrib.staticfiles" in settings.INSTALLED_APPS)
finders = None
settings = None
if INSTALLED:
if "django.contrib.staticfiles" in django_settings.INSTALLED_APPS:
if "django.contrib.staticfiles" in settings.INSTALLED_APPS:
from django.contrib.staticfiles import finders
settings = django_settings
else:
try:
from staticfiles import finders
from staticfiles.conf import settings
except ImportError:
# Old (pre 1.0) and incompatible version of staticfiles
INSTALLED = False
......
......@@ -4,11 +4,11 @@ import re
from BeautifulSoup import BeautifulSoup
from django.conf import settings
from django.core.cache.backends import locmem
from django.test import TestCase
from compressor.base import SOURCE_HUNK, SOURCE_FILE
from compressor.conf import settings
from compressor.css import CssCompressor
from compressor.js import JsCompressor
......
......@@ -3,10 +3,10 @@ import os
import sys
from unittest2 import skipIf
from django.conf import settings
from django.test import TestCase
from compressor.cache import get_hashed_mtime
from compressor.conf import settings
from compressor.css import CssCompressor
from compressor.utils import find_command
from compressor.filters.base import CompilerFilter
......
from __future__ import with_statement
import os
from django.conf import settings
from django.template import Template, Context
from django.test import TestCase
from compressor.conf import settings
from compressor.management.commands.compress import Command as CompressCommand
from .base import test_dir, css_tag
......
......@@ -18,9 +18,8 @@ except ImportError:
BeautifulSoup = None
from django.conf import settings
from compressor.base import SOURCE_HUNK, SOURCE_FILE
from compressor.conf import settings
from .base import CompressorTestCase
......
from __future__ import with_statement
from django.conf import settings
from django.core.files.storage import get_storage_class
from django.test import TestCase
from compressor import base
from compressor.conf import settings
from .base import css_tag
from .templatetags import render
......
from __future__ import with_statement
from django.conf import settings
from django.template import Template, Context, TemplateSyntaxError
from django.test import TestCase
from .base import css_tag
from compressor.conf import settings
from .base import css_tag
def render(template_string, context_dict=None):
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment