Esempio n. 1
0
    def render(self, context):
        js_name = template.Variable(self.name).resolve(context)

        try:
            js = settings.COMPRESS_JS[js_name]
        except KeyError:
            return '' # fail silently, do not return anything if an invalid group is specified
        
        if 'external_urls' in js:
            r = ''
            for url in js['external_urls']:
                r += render_js(js, url)
            return r
                    
        if settings.COMPRESS:

            version = None

            if settings.COMPRESS_AUTO:
                u, version = needs_update(js['output_filename'], 
                    js['source_filenames'])
                if u:
                    filter_js(js)
            else: 
                filename_base, filename = os.path.split(js['output_filename'])
                path_name = media_root(filename_base)
                version = get_version_from_file(path_name, filename)

            return render_js(js, js['output_filename'], version)
        else:
            # output source files
            r = ''
            for source_file in js['source_filenames']:
                r += render_js(js, source_file)
            return r
Esempio n. 2
0
    def render(self, context):
        css_name = template.Variable(self.name).resolve(context)
        actual_request = self.request.resolve(context)

        try:
            css = settings.COMPRESS_CSS[css_name]
        except KeyError:
            return ''  # fail silently, do not return anything if an invalid group is specified
        css['request'] = actual_request
        if settings.COMPRESS:

            version = None

            if settings.COMPRESS_AUTO:
                u, version = needs_update(css['output_filename'],
                                          css['source_filenames'])
                if u:
                    filter_css(css)
            else:
                filename_base, filename = os.path.split(css['output_filename'])
                path_name = media_root(filename_base)
                version = get_version_from_file(path_name, filename)

            return render_css(css, css['output_filename'], version)
        else:
            # output source files
            r = ''
            for source_file in css['source_filenames']:
                r += render_css(css, source_file)

            return r
Esempio n. 3
0
def compressed_css(css_name):
    try:
        css = settings.COMPRESS_CSS[css_name]
    except KeyError:
        return '' # fail silently, do not return anything if an invalid group is specified

    if settings.COMPRESS:

        version = None

        if settings.COMPRESS_AUTO:
            u, version = needs_update(css['output_filename'], 
                css['source_filenames'])
            if u:
                filter_css(css)
        else:
            filename_base, filename = os.path.split(css['output_filename'])
            path_name = media_root(filename_base)
            version = get_version_from_file(path_name, filename)
            
        return render_css(css, css['output_filename'], version)
    else:
        # output source files
        r = ''
        for source_file in css['source_filenames']:
            r += render_css(css, source_file)

        return r
Esempio n. 4
0
    def render(self, context):
        css_name = template.Variable(self.name).resolve(context)
        actual_request = self.request.resolve(context)

        try:
            css = settings.COMPRESS_CSS[css_name]
        except KeyError:
            return '' # fail silently, do not return anything if an invalid group is specified
        css['request'] = actual_request
        if settings.COMPRESS:

            version = None

            if settings.COMPRESS_AUTO:
                u, version = needs_update(css['output_filename'], 
                    css['source_filenames'])
                if u:
                    filter_css(css)
            else:
                filename_base, filename = os.path.split(css['output_filename'])
                path_name = media_root(filename_base)
                version = get_version_from_file(path_name, filename)
                
            return render_css(css, css['output_filename'], version)
        else:
            # output source files
            r = ''
            for source_file in css['source_filenames']:
                r += render_css(css, source_file)

            return r
    def render(self, context):
        js_name = template.Variable(self.name).resolve(context)

        try:
            js = settings.COMPRESS_JS[js_name]
        except KeyError:
            return ''  # fail silently, do not return anything if an invalid group is specified

        if 'external_urls' in js:
            r = ''
            for url in js['external_urls']:
                r += render_js(js, url)
            return r

        if settings.COMPRESS:

            version = None

            if settings.COMPRESS_AUTO:
                u, version = needs_update(js['output_filename'],
                                          js['source_filenames'])
                if u:
                    filter_js(js)
            else:
                filename_base, filename = os.path.split(js['output_filename'])
                path_name = media_root(filename_base)
                version = get_version_from_file(path_name, filename)

            return render_js(js, js['output_filename'], version)
        else:
            # output source files
            r = ''
            for source_file in js['source_filenames']:
                r += render_js(js, source_file)
            return r
Esempio n. 6
0
    def needs_update(self, output_file, source_files, version):

        output_file_name = get_output_filename(output_file, version)
        compressed_file_full = media_root(output_file_name)

        return (int(os.stat(compressed_file_full).st_mtime) <
                int(version)), version
Esempio n. 7
0
    def render(self, context):
        css_name = template.Variable(self.name).resolve(context)

        try:
            css = settings.COMPRESS_CSS[css_name]
        except KeyError:
            return '' # fail silently, do not return anything if an invalid group is specified

        if settings.COMPRESS:

            version = None

            if settings.COMPRESS_AUTO:
                u, version = needs_update(css['output_filename'], 
                    css['source_filenames'])
                if u:
                    filter_css(css)
            else:
                filename_base, filename = os.path.split(css['output_filename'])
                path_name = media_root(filename_base)
                version = get_version(path_name, filename)
            if self.variable is None:
                return render_css(css, css['output_filename'], version)
            else:
                context[self.variable] = [media_url(css['output_filename'], context.get('prefix', None))]
                return ''
        else:
            # output source files
            if self.variable is None:
                r = ''
                for source_file in css['source_filenames']:
                    r += render_css(css, source_file)
                return r
            else:
                context[self.variable] = [media_url(a_css_file, context.get('prefix', None)) for a_css_file in css['source_filenames']]
                return ''
Esempio n. 8
0
    def get_version(self, source_files):

        # Return the modification time for the newest source file
        return str(
            max([int(os.stat(media_root(f)).st_mtime) for f in source_files]))
Esempio n. 9
0
    def get_version(self, source_files):

        # Return the modification time for the newest source file
        return str(max([int(os.stat(media_root(f)).st_mtime) for f in source_files]))
Esempio n. 10
0
    def needs_update(self, output_file, source_files, version):

        output_file_name = get_output_filename(output_file, version)
        compressed_file_full = media_root(output_file_name)

        return (int(os.stat(compressed_file_full).st_mtime) < int(version)), version