Permalink
Browse files

Add a hook to allow developers to completely bypass offline compressi…

…on if they want to in CompressorNode subclasses
  • Loading branch information...
diox committed Jan 27, 2012
1 parent ab97095 commit cdf8d8b8b6f2dbc34f1bfce94aa56eb77754f3c5
Showing with 15 additions and 5 deletions.
  1. +1 −1 compressor/management/commands/compress.py
  2. +14 −4 compressor/templatetags/compress.py
@@ -243,7 +243,7 @@ def walk_nodes(self, node, block_name=None):
for node in self.get_nodelist(node):
if isinstance(node, BlockNode):
block_name = node.name
- if isinstance(node, CompressorNode):
+ if isinstance(node, CompressorNode) and node.is_offline_compression_enabled(forced=True):
node._block_name = block_name
yield node
else:
@@ -41,13 +41,23 @@ def debug_mode(self, context):
if request is not None:
return settings.COMPRESS_DEBUG_TOGGLE in request.GET
+ def is_offline_compression_enabled(self, forced):
+ """
+ Check if offline compression is enabled or forced
+
+ Defaults to just checking the settings and forced argument,
+ but can be overriden to completely disable compression for
+ a subclass, for instance.
+ """
+ rval = (settings.COMPRESS_ENABLED and settings.COMPRESS_OFFLINE) or forced
+ return rval
+
def render_offline(self, context, forced):
"""
- If enabled and in offline mode, and not forced or in debug mode
- check the offline cache and return the result if given
+ If enabled and in offline mode, and not forced check the offline cache
+ and return the result if given
"""
- if (settings.COMPRESS_ENABLED and
- settings.COMPRESS_OFFLINE) and not forced:
+ if self.is_offline_compression_enabled(forced) and not forced:
key = get_offline_hexdigest(self.nodelist.render(context))
offline_manifest = get_offline_manifest()
if key in offline_manifest:

0 comments on commit cdf8d8b

Please sign in to comment.