コード例 #1
0
 def render_cached(self, compressor, kind, mode):
     """
     If enabled checks the cache for the given compressor's cache key
     and return a tuple of cache key and output
     """
     cache_key = get_templatetag_cachekey(compressor, mode, kind)
     cache_content = cache_get(cache_key)
     return cache_key, cache_content
コード例 #2
0
 def render_cached(self, compressor, kind, mode):
     """
     If enabled checks the cache for the given compressor's cache key
     and return a tuple of cache key and output
     """
     cache_key = get_templatetag_cachekey(compressor, mode, kind)
     cache_content = cache_get(cache_key)
     return cache_key, cache_content
コード例 #3
0
 def render_cached(self, compressor, kind, mode, forced=False):
     """
     If enabled checks the cache for the given compressor's cache key
     and return a tuple of cache key and output
     """
     if settings.COMPRESS_ENABLED and not forced:
         cache_key = get_templatetag_cachekey(compressor, mode, kind)
         cache_content = cache_get(cache_key)
         return cache_key, cache_content
     return None, None
コード例 #4
0
ファイル: compress.py プロジェクト: jesobreira/casanova
 def render_cached(self, compressor, kind, mode, forced=False):
     """
     If enabled checks the cache for the given compressor's cache key
     and return a tuple of cache key and output
     """
     if settings.COMPRESS_ENABLED and not forced:
         cache_key = get_templatetag_cachekey(compressor, mode, kind)
         cache_content = cache_get(cache_key)
         return cache_key, cache_content
     return None, None
コード例 #5
0
def compress(cache_key, content, kind, mode):
    logger = compress.get_logger()

    if cache_get(cache_key) is not None:
        logger.debug('No update required for %s', cache_key)
        return

    compressors = CompressorMixin().compressors
    compressor = get_class(compressors.get(kind),
                           exception=ImproperlyConfigured)
    compressor = compressor(content=content)
    output = compressor.output(mode)
    cache_set(cache_key, output)

    logger.debug("Successfully updated cache key %s", cache_key)
コード例 #6
0
    def compiled_render(self, raw_content):

        if has_compressor:
            digest = hashlib.md5(smart_str(raw_content)).hexdigest()
            cached = cache_get(digest)
            if cached:
                return cached

        parser = HandlebarScriptParser()
        parser.feed(raw_content)

        non_template_content = parser.get_non_template_content()
        raw_templates = parser.get_templates()

        compile_root = tempfile.mkdtemp()

        content_parts = []
        content_parts.append('<script type="text/javascript">')
        content_parts.append('window.addEventListener("load", function() {')

        for template in raw_templates:
            compressed = compress_template(
                            compile_root,
                            template.name,
                            template.raw_content)

            content_parts.append(compressed)

        os.rmdir(compile_root)

        content_parts.append(self.get_templates_loaded_js())
        content_parts.append('});')
        content_parts.append("</script>")
        content_parts.append(non_template_content)

        compiled = "".join(content_parts)

        if has_compressor:
            cache_set(digest, compiled)
        return compiled