Introduced a default extra_context dictionary.

This commit is contained in:
Jannis Leidel
2011-02-16 19:16:53 +01:00
parent bda59c0ce3
commit 95da02af0b
2 changed files with 12 additions and 7 deletions

View File

@@ -13,6 +13,7 @@ class Compressor(object):
def __init__(self, content=None, output_prefix="compressed"): def __init__(self, content=None, output_prefix="compressed"):
self.content = content or "" self.content = content or ""
self.extra_context = {}
self.type = None self.type = None
self.output_prefix = output_prefix self.output_prefix = output_prefix
self.split_content = [] self.split_content = []
@@ -131,13 +132,17 @@ class Compressor(object):
def output(self): def output(self):
if not settings.COMPRESS_ENABLED: if not settings.COMPRESS_ENABLED:
return self.content return self.content
self.save_file() context = {
context = getattr(self, 'extra_context', {}) "saved": self.save_file(),
context['url'] = self.storage.url(self.new_filepath) "url": self.storage.url(self.new_filepath),
}
context.update(self.extra_context)
return render_to_string(self.template_name, context) return render_to_string(self.template_name, context)
def output_inline(self): def output_inline(self):
context = {'content': settings.COMPRESS_ENABLED and self.combined or self.concat()} if settings.COMPRESS_ENABLED:
if hasattr(self, 'extra_context'): content = self.combined
context.update(self.extra_context) else:
content = self.concat()
context = dict(content=content, **self.extra_context)
return render_to_string(self.template_name_inline, context) return render_to_string(self.template_name_inline, context)

View File

@@ -49,6 +49,6 @@ class CssCompressor(Compressor):
return self.content return self.content
ret = [] ret = []
for media, subnode in self.media_nodes: for media, subnode in self.media_nodes:
subnode.extra_context = {'media': media} subnode.extra_context.update({'media': media})
ret.append(subnode.output()) ret.append(subnode.output())
return ''.join(ret) return ''.join(ret)