Пример #1
0
 def render(self, context, compress=settings.COMPRESS, offline=settings.OFFLINE):
     if compress and offline:
         key = get_offline_cachekey(self.nodelist)
         content = cache.get(key)
         if content:
             return content
     content = self.nodelist.render(context)
     if offline or not compress or not len(content.strip()):
         return content
     if self.kind == 'css':
         compressor = CssCompressor(content)
     if self.kind == 'js':
         compressor = JsCompressor(content)
     cachekey = "%s-%s" % (compressor.cachekey, self.mode)
     output = self.cache_get(cachekey)
     if output is None:
         try:
             if self.mode == OUTPUT_FILE:
                 output = compressor.output()
             else:
                 output = compressor.output_inline()
             self.cache_set(cachekey, output)
         except:
             from traceback import format_exc
             raise Exception(format_exc())
     return output