Fixed PEP8 issues.

This commit is contained in:
Jannis Leidel
2011-10-07 17:46:40 +02:00
parent b2b8708920
commit 37440d6cd3
3 changed files with 14 additions and 11 deletions

View File

@@ -36,7 +36,8 @@ def get_cachekey(*args, **kwargs):
global _cachekey_func global _cachekey_func
if _cachekey_func is None: if _cachekey_func is None:
try: try:
mod_name, func_name = get_mod_func(settings.COMPRESS_CACHE_KEY_FUNCTION) mod_name, func_name = get_mod_func(
settings.COMPRESS_CACHE_KEY_FUNCTION)
_cachekey_func = getattr(import_module(mod_name), func_name) _cachekey_func = getattr(import_module(mod_name), func_name)
except (AttributeError, ImportError), e: except (AttributeError, ImportError), e:
raise ImportError("Couldn't import cache key function %s: %s" % raise ImportError("Couldn't import cache key function %s: %s" %
@@ -47,9 +48,11 @@ def get_cachekey(*args, **kwargs):
def get_mtime_cachekey(filename): def get_mtime_cachekey(filename):
return get_cachekey("mtime.%s" % get_hexdigest(filename)) return get_cachekey("mtime.%s" % get_hexdigest(filename))
def get_offline_hexdigest(source): def get_offline_hexdigest(source):
return get_hexdigest([smart_str(getattr(s, 's', s)) for s in source]) return get_hexdigest([smart_str(getattr(s, 's', s)) for s in source])
def get_offline_cachekey(source): def get_offline_cachekey(source):
return get_cachekey("offline.%s" % get_offline_hexdigest(source)) return get_cachekey("offline.%s" % get_offline_hexdigest(source))
@@ -58,6 +61,7 @@ def get_offline_manifest_filename():
output_dir = settings.COMPRESS_OUTPUT_DIR.strip('/') output_dir = settings.COMPRESS_OUTPUT_DIR.strip('/')
return os.path.join(output_dir, 'manifest.json') return os.path.join(output_dir, 'manifest.json')
def get_offline_manifest(): def get_offline_manifest():
filename = get_offline_manifest_filename() filename = get_offline_manifest_filename()
if default_storage.exists(filename): if default_storage.exists(filename):
@@ -65,11 +69,13 @@ def get_offline_manifest():
else: else:
return {} return {}
def write_offline_manifest(manifest): def write_offline_manifest(manifest):
filename = get_offline_manifest_filename() filename = get_offline_manifest_filename()
default_storage.save(filename, default_storage.save(filename,
ContentFile(simplejson.dumps(manifest, indent=2))) ContentFile(simplejson.dumps(manifest, indent=2)))
def get_templatetag_cachekey(compressor, mode, kind): def get_templatetag_cachekey(compressor, mode, kind):
return get_cachekey( return get_cachekey(
"templatetag.%s.%s.%s" % (compressor.cachekey, mode, kind)) "templatetag.%s.%s.%s" % (compressor.cachekey, mode, kind))

View File

@@ -13,7 +13,6 @@ from django.core.management.base import NoArgsCommand, CommandError
from django.template import Context, Template, TemplateDoesNotExist, TemplateSyntaxError from django.template import Context, Template, TemplateDoesNotExist, TemplateSyntaxError
from django.utils.datastructures import SortedDict from django.utils.datastructures import SortedDict
from django.utils.importlib import import_module from django.utils.importlib import import_module
from django.template.loader import get_template
from django.template.loader_tags import ExtendsNode, BlockNode, BLOCK_CONTEXT_KEY from django.template.loader_tags import ExtendsNode, BlockNode, BLOCK_CONTEXT_KEY
try: try:
@@ -21,7 +20,7 @@ try:
except ImportError: except ImportError:
CachedLoader = None CachedLoader = None
from compressor.cache import cache, get_offline_hexdigest, write_offline_manifest from compressor.cache import get_offline_hexdigest, write_offline_manifest
from compressor.conf import settings from compressor.conf import settings
from compressor.exceptions import OfflineGenerationError from compressor.exceptions import OfflineGenerationError
from compressor.templatetags.compress import CompressorNode from compressor.templatetags.compress import CompressorNode
@@ -256,4 +255,3 @@ class Command(NoArgsCommand):
"Offline compressiong is disabled. Set " "Offline compressiong is disabled. Set "
"COMPRESS_OFFLINE or use the --force to override.") "COMPRESS_OFFLINE or use the --force to override.")
self.compress(sys.stdout, **options) self.compress(sys.stdout, **options)

View File

@@ -1,9 +1,8 @@
from django import template from django import template
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from compressor.cache import (cache, cache_get, cache_set, from compressor.cache import (cache_get, cache_set, get_offline_hexdigest,
get_offline_hexdigest, get_offline_manifest, get_offline_manifest, get_templatetag_cachekey)
get_templatetag_cachekey)
from compressor.conf import settings from compressor.conf import settings
from compressor.exceptions import OfflineGenerationError from compressor.exceptions import OfflineGenerationError
from compressor.utils import get_class from compressor.utils import get_class
@@ -14,6 +13,7 @@ OUTPUT_FILE = 'file'
OUTPUT_INLINE = 'inline' OUTPUT_INLINE = 'inline'
OUTPUT_MODES = (OUTPUT_FILE, OUTPUT_INLINE) OUTPUT_MODES = (OUTPUT_FILE, OUTPUT_INLINE)
class CompressorNode(template.Node): class CompressorNode(template.Node):
def __init__(self, nodelist, kind=None, mode=OUTPUT_FILE, name=None): def __init__(self, nodelist, kind=None, mode=OUTPUT_FILE, name=None):
@@ -23,7 +23,7 @@ class CompressorNode(template.Node):
self.name = name self.name = name
def compressor_cls(self, *args, **kwargs): def compressor_cls(self, *args, **kwargs):
compressors = { compressors = {
"css": settings.COMPRESS_CSS_COMPRESSOR, "css": settings.COMPRESS_CSS_COMPRESSOR,
"js": settings.COMPRESS_JS_COMPRESSOR, "js": settings.COMPRESS_JS_COMPRESSOR,
} }
@@ -55,7 +55,6 @@ class CompressorNode(template.Node):
else: else:
raise OfflineGenerationError('You have offline compression enabled but key "%s" is missing from offline manifest. You may need to run "python manage.py compress".' % key) raise OfflineGenerationError('You have offline compression enabled but key "%s" is missing from offline manifest. You may need to run "python manage.py compress".' % key)
def render_cached(self, compressor, forced): def render_cached(self, compressor, forced):
""" """
If enabled checks the cache for the given compressor's cache key If enabled checks the cache for the given compressor's cache key
@@ -74,7 +73,7 @@ class CompressorNode(template.Node):
return self.nodelist.render(context) return self.nodelist.render(context)
# Prepare the compressor # Prepare the compressor
context.update({'name': self.name}) context.update({'name': self.name})
compressor = self.compressor_cls(content=self.nodelist.render(context), compressor = self.compressor_cls(content=self.nodelist.render(context),
context=context) context=context)
@@ -82,7 +81,7 @@ class CompressorNode(template.Node):
cached_offline = self.render_offline(compressor, forced) cached_offline = self.render_offline(compressor, forced)
if cached_offline: if cached_offline:
return cached_offline return cached_offline
# Check cache # Check cache
cache_key, cache_content = self.render_cached(compressor, forced) cache_key, cache_content = self.render_cached(compressor, forced)
if cache_content is not None: if cache_content is not None: