コード例 #1
0
    def test_get_class_import_exception(self):
        with self.assertRaises(FilterError) as context:
            get_class("common.uglify.JsUglifySourcemapCompressor")

        self.assertTrue(
            ("Failed to import common.uglify.JsUglifySourcemapCompressor. "
             "ImportError is: No module named" in str(context.exception)))
コード例 #2
0
    def _compress(self, kind, mode, nodelist_string, caller):
        mode = mode or OUTPUT_FILE
        Compressor = get_class(self.compressors.get(kind),
            exception=ImproperlyConfigured)
        original_content = caller()
        compressor = Compressor(original_content)

        forced = getattr(self.environment, '_django_compressor_offline_forced', False)

        # See if it has been rendered offline
        cached_offline = self.render_offline(kind, mode, compressor, forced, nodelist_string)
        if cached_offline:
            return cached_offline

        # Prepare the actual compressor and check cache
        cache_key, cache_content = self.render_cached(kind, mode, compressor,
            forced)
        if cache_content is not None:
            return cache_content

        # call compressor output method and handle exceptions
        try:
            rendered_output = compressor.output(mode, forced)
            if cache_key:
                cache_set(cache_key, rendered_output)
            return rendered_output
        except Exception, e:
            if settings.DEBUG:
                raise e
コード例 #3
0
 def __init__(self, nodelist, kind=None, mode=OUTPUT_FILE, name=None):
     self.nodelist = nodelist
     self.kind = kind
     self.mode = mode
     self.name = name
     self.compressor_cls = get_class(
         COMPRESSORS.get(self.kind), exception=ImproperlyConfigured)
コード例 #4
0
ファイル: jinja2ext.py プロジェクト: eiritana/canvas
    def _compress(self, kind, mode, nodelist_string, caller):
        mode = mode or OUTPUT_FILE
        Compressor = get_class(self.compressors.get(kind),
                               exception=ImproperlyConfigured)
        original_content = caller()
        compressor = Compressor(original_content)

        forced = getattr(self.environment, '_django_compressor_offline_forced',
                         False)

        # See if it has been rendered offline
        cached_offline = self.render_offline(kind, mode, compressor, forced,
                                             nodelist_string)
        if cached_offline:
            return cached_offline

        # Prepare the actual compressor and check cache
        cache_key, cache_content = self.render_cached(kind, mode, compressor,
                                                      forced)
        if cache_content is not None:
            return cache_content

        # call compressor output method and handle exceptions
        try:
            rendered_output = compressor.output(mode, forced)
            if cache_key:
                cache_set(cache_key, rendered_output)
            return rendered_output
        except Exception, e:
            if settings.DEBUG:
                raise e
コード例 #5
0
 def compressor_cls(self, kind):
     if kind not in self.compressors.keys():
         raise template.TemplateSyntaxError(
             "The compress tag's argument must be one of: %s." %
             ', '.join(map(repr, self.compressors.keys())))
     return get_class(self.compressors.get(kind),
                      exception=ImproperlyConfigured)
コード例 #6
0
ファイル: compress.py プロジェクト: JustynaJBroniszewska/Blog
 def compressor_cls(self, kind, *args, **kwargs):
     if kind not in self.compressors.keys():
         raise template.TemplateSyntaxError(
             "The compress tag's argument must be 'js' or 'css'."
         )
     return get_class(self.compressors.get(kind), exception=ImproperlyConfigured)(
         *args, **kwargs
     )
コード例 #7
0
 def compressor_cls(self, *args, **kwargs):
     compressors = {
         "css": settings.COMPRESS_CSS_COMPRESSOR,
         "js": settings.COMPRESS_JS_COMPRESSOR,
     }
     if self.kind not in compressors.keys():
         raise template.TemplateSyntaxError(
             "The compress tag's argument must be 'js' or 'css'.")
     return get_class(compressors.get(self.kind),
                      exception=ImproperlyConfigured)(*args, **kwargs)
コード例 #8
0
 def compressor_cls(self, *args, **kwargs):
     compressors = {
         "css": settings.COMPRESS_CSS_COMPRESSOR,
         "js": settings.COMPRESS_JS_COMPRESSOR,
     }
     if self.kind not in compressors.keys():
         raise template.TemplateSyntaxError(
             "The compress tag's argument must be 'js' or 'css'.")
     return get_class(compressors.get(self.kind),
                      exception=ImproperlyConfigured)(*args, **kwargs)
コード例 #9
0
def compress(context, data, name):
    """
    Data is the string from the template (the list of js files in this case)
    Name is either 'js' or 'css' (the sekizai namespace)
    Basically passes the string through the {% compress 'js' %} template tag
    """
    # separate compressable from uncompressable files
    parser = get_class(settings.COMPRESS_PARSER)(data)
    compressor = Compressor()
    compressable_elements, expanded_elements, deferred_elements = [], [], []
    if name == 'js':
        for elem in parser.js_elems():
            attribs = parser.elem_attribs(elem)
            try:
                if 'src' in attribs:
                    compressor.get_basename(attribs['src'])
            except UncompressableFileError:
                if 'defer' in attribs:
                    deferred_elements.append(elem)
                else:
                    expanded_elements.append(elem)
            else:
                compressable_elements.append(elem)
    elif name == 'css':
        for elem in parser.css_elems():
            attribs = parser.elem_attribs(elem)
            try:
                if parser.elem_name(elem) == 'link' and attribs['rel'].lower(
                ) == 'stylesheet':
                    compressor.get_basename(attribs['href'])
            except UncompressableFileError:
                expanded_elements.append(elem)
            else:
                compressable_elements.append(elem)

    # reconcatenate them
    data = ''.join(parser.elem_str(e) for e in expanded_elements)
    expanded_node = CompressorNode(nodelist=TextNode(data),
                                   kind=name,
                                   mode='file')
    data = ''.join(parser.elem_str(e) for e in compressable_elements)
    compressable_node = CompressorNode(nodelist=TextNode(data),
                                       kind=name,
                                       mode='file')
    data = ''.join(parser.elem_str(e) for e in deferred_elements)
    deferred_node = CompressorNode(nodelist=TextNode(data),
                                   kind=name,
                                   mode='file')

    return '\n'.join([
        expanded_node.get_original_content(context=context),
        compressable_node.render(context=context),
        deferred_node.get_original_content(context=context),
    ])
コード例 #10
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)
コード例 #11
0
def compress(context, data, name):
    """
    Data is the string from the template (the list of js files in this case)
    Name is either 'js' or 'css' (the sekizai namespace)
    Basically passes the string through the {% compress 'js' %} template tag
    """
    # separate compressable from uncompressable files
    parser = get_class(settings.COMPRESS_PARSER)(data)
    compressor = Compressor()
    compressable_elements, expanded_elements, deferred_elements = [], [], []
    if name == 'js':
        for elem in parser.js_elems():
            attribs = parser.elem_attribs(elem)
            try:
                if 'src' in attribs:
                    compressor.get_basename(attribs['src'])
            except UncompressableFileError:
                if 'defer' in attribs:
                    deferred_elements.append(elem)
                else:
                    expanded_elements.append(elem)
            else:
                compressable_elements.append(elem)
    elif name == 'css':
        for elem in parser.css_elems():
            attribs = parser.elem_attribs(elem)
            try:
                if parser.elem_name(elem) == 'link' and attribs['rel'].lower() == 'stylesheet':
                    compressor.get_basename(attribs['href'])
            except UncompressableFileError:
                expanded_elements.append(elem)
            else:
                compressable_elements.append(elem)

    # reconcatenate them
    data = ''.join(parser.elem_str(e) for e in expanded_elements)
    expanded_node = CompressorNode(nodelist=TextNode(data), kind=name, mode='file')
    data = ''.join(parser.elem_str(e) for e in compressable_elements)
    compressable_node = CompressorNode(nodelist=TextNode(data), kind=name, mode='file')
    data = ''.join(parser.elem_str(e) for e in deferred_elements)
    deferred_node = CompressorNode(nodelist=TextNode(data), kind=name, mode='file')

    return '\n'.join([
        expanded_node.get_original_content(context=context),
        compressable_node.render(context=context),
        deferred_node.get_original_content(context=context),
    ])
コード例 #12
0
ファイル: compress.py プロジェクト: rossowl/django-jimross
    def _compress(self, kind, mode, caller):
        mode = mode or OUTPUT_FILE
        Compressor = get_class(COMPRESSORS.get(kind))
        original_content = caller()
        compressor = Compressor(original_content)
        # This extension assumes that we won't force compression
        forced = False

        # Prepare the actual compressor and check cache
        cache_key, cache_content = self.render_cached(kind, mode, compressor,
            forced)
        if cache_content is not None:
            return cache_content

        # call compressor output method and handle exceptions
        try:
            rendered_output = compressor.output(mode, forced)
            if cache_key:
                cache_set(cache_key, rendered_output)
            return rendered_output
        except Exception, e:
            pass
コード例 #13
0
    def _compress(self, kind, mode, caller):
        mode = mode or OUTPUT_FILE
        Compressor = get_class(self.compressors.get(kind),
            exception=ImproperlyConfigured)
        original_content = caller()
        compressor = Compressor(original_content)
        # This extension assumes that we won't force compression
        forced = False

        # Prepare the actual compressor and check cache
        cache_key, cache_content = self.render_cached(kind, mode, compressor,
            forced)
        if cache_content is not None:
            return cache_content

        # call compressor output method and handle exceptions
        try:
            rendered_output = compressor.output(mode, forced)
            if cache_key:
                cache_set(cache_key, rendered_output)
            return rendered_output
        except Exception, e:
            if settings.DEBUG:
                raise e
コード例 #14
0
ファイル: common_tags.py プロジェクト: morale/sapl
def model_verbose_name_plural(class_name):
    model = get_class(class_name)
    return model._meta.verbose_name_plural
コード例 #15
0
ファイル: common_tags.py プロジェクト: morale/sapl
def fieldclass_verbose_name(class_name, field_name):
    cls = get_class(class_name)
    return cls._meta.get_field(field_name).verbose_name
コード例 #16
0
ファイル: common_tags.py プロジェクト: Danpeli/sapl
def model_verbose_name_plural(class_name):
    model = get_class(class_name)
    return model._meta.verbose_name_plural
コード例 #17
0
ファイル: common_tags.py プロジェクト: Danpeli/sapl
def fieldclass_verbose_name(class_name, field_name):
    cls = get_class(class_name)
    return cls._meta.get_field(field_name).verbose_name
コード例 #18
0
ファイル: base.py プロジェクト: repos-db/mongoadmin
 def parser(self):
     return get_class(settings.COMPRESS_PARSER)(self.content)
コード例 #19
0
def compress(context, data, name):
    """
    Data is the string from the template (the list of js files in this case)
    Name is either 'js' or 'css' (the sekizai namespace)
    Basically passes the string through the {% compress 'js' %} template tag
    Alternatively, if the block can contain a html comment structured like:
    <!-- compress_options [params] -->
    params can be: one of ['js','css'] and one or multiple of ['file','preload','inline']
    """
    # separate compressable from uncompressable files
    options = []
    kind = name
    m = re.search('<!-- *compress_options *([a-z ]+?) *-->', data)
    if m is not None:
        options_clean = re.sub(' +', ' ', m.groups()[0])
        options = set(options_clean.split(' '))
        if 'js' in options and 'css' not in options:
            kind = 'js'
        elif 'css' in options and 'js' not in options:
            kind = 'css'

    parser = get_class(settings.COMPRESS_PARSER)(data)
    js_compressor, css_compressor = Compressor('js'), Compressor('css')
    compressable_elements, expanded_elements, deferred_elements = [], [], []
    if kind == 'js':
        for elem in parser.js_elems():
            attribs = parser.elem_attribs(elem)
            try:
                if 'src' in attribs:
                    js_compressor.get_basename(attribs['src'])
            except UncompressableFileError:
                if 'defer' in attribs:
                    deferred_elements.append(elem)
                else:
                    expanded_elements.append(elem)
            else:
                compressable_elements.append(elem)
    elif kind == 'css':
        for elem in parser.css_elems():
            attribs = parser.elem_attribs(elem)
            try:
                if parser.elem_name(elem) == 'link' and attribs['rel'].lower(
                ) == 'stylesheet':
                    css_compressor.get_basename(attribs['href'])
            except UncompressableFileError:
                expanded_elements.append(elem)
            else:
                compressable_elements.append(elem)

    # reconcatenate them
    results = []
    data = ''.join(parser.elem_str(e) for e in expanded_elements)
    expanded_node = CompressorNode(nodelist=TextNode(data),
                                   kind=kind,
                                   mode='file')
    results.append(expanded_node.get_original_content(context=context))

    if 'file' in options or len(options) == 0:
        data = ''.join(parser.elem_str(e) for e in compressable_elements)
        compressable_node = CompressorNode(nodelist=TextNode(data),
                                           kind=kind,
                                           mode='file')
        tmp_result = compressable_node.render(context=context)
        if 'defer' in options:
            tmp_result = re.sub("></script>$", " defer=\"defer\"></script>",
                                tmp_result)
        results.append(tmp_result)

    if 'preload' in options:
        data = ''.join(parser.elem_str(e) for e in compressable_elements)
        compressable_node = CompressorNode(nodelist=TextNode(data),
                                           kind=kind,
                                           mode='preload')
        results.append(compressable_node.render(context=context))

    if 'inline' in options:
        data = ''.join(parser.elem_str(e) for e in compressable_elements)
        compressable_node = CompressorNode(nodelist=TextNode(data),
                                           kind=kind,
                                           mode='inline')
        results.append(compressable_node.render(context=context))

    data = ''.join(parser.elem_str(e) for e in deferred_elements)
    deferred_node = CompressorNode(nodelist=TextNode(data),
                                   kind=kind,
                                   mode='file')
    results.append(deferred_node.get_original_content(context=context))

    return '\n'.join(results)
コード例 #20
0
 def __init__(self, nodelist, kind=None, mode=OUTPUT_FILE):
     self.nodelist = nodelist
     self.kind = kind
     self.mode = mode
     self.compressor_cls = get_class(COMPRESSORS.get(self.kind),
                                     exception=ImproperlyConfigured)
コード例 #21
0
ファイル: base.py プロジェクト: heynemann/django_compressor
 def _get_parser(self):
     if self._parser:
         return self._parser
     parser_cls = get_class(settings.PARSER)
     self._parser = parser_cls(self.content)
     return self._parser
コード例 #22
0
 def parser(self):
     return get_class(settings.COMPRESS_PARSER)(self.content)
コード例 #23
0
ファイル: base.py プロジェクト: repos-db/mongoadmin
 def cached_filters(self):
     return [get_class(filter_cls) for filter_cls in self.filters]
コード例 #24
0
 def compressor_cls(self, kind, *args, **kwargs):
     if kind not in self.compressors.keys():
         raise template.TemplateSyntaxError(
             "The compress tag's argument must be 'js' or 'css'.")
     return get_class(self.compressors.get(kind),
                      exception=ImproperlyConfigured)(*args, **kwargs)
コード例 #25
0
 def cached_filters(self):
     return [get_class(filter_cls) for filter_cls in self.filters]
コード例 #26
0
def objects_all_model(class_name):
    model = get_class(class_name)
    objects_all_model = model.objects.all()
    return list(objects_all_model)
コード例 #27
0
ファイル: base.py プロジェクト: gitter-badger/rooibos
 def _get_parser(self):
     if self._parser:
         return self._parser
     parser_cls = get_class(settings.PARSER)
     self._parser = parser_cls(self.content)
     return self._parser
コード例 #28
0
ファイル: core_filters.py プロジェクト: LeandroJatai/musicat
def objects_all_model(class_name):
    model = get_class(class_name)
    objects_all_model = model.objects.all()
    return list(objects_all_model)