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

View File

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