示例#1
0
def process_file(src, **attrs):
    # Fail silently if there's no path or extension
    src_no_ext, ext = os.path.splitext(src)
    if not src or not ext:
        return None, None, None

    # Removes the "." from the extension and get the filetype
    ext = ext[1:]
    filetype = get_filetype(ext)

    # Extends default attributes for the filetype
    default_attrs = app_settings.FILETYPES_ATTRIBUTES.get(filetype, {})
    attrs = dict(default_attrs, **attrs)

    # Convert the src to a URL relative to the MEDIA_URL or absolute
    src = get_relative_url(src)

    # Apply processors (image resize or others)
    processors = get_filetype_processors(filetype)
    for proc in processors:
        src, attrs = proc(src, attrs)

    # Add anti-cache query string
    anti_cache = nocache(src)
    if anti_cache:
        src += '?' + anti_cache

    # Return the (possibly) modified src and attributes
    return src, filetype, attrs
示例#2
0
def process_file(src, **attrs):
    # Fail silently if there's no path or extension
    src_no_ext, ext = os.path.splitext(src)
    if not src or not ext:
        return None, None, None

    # Removes the "." from the extension and get the filetype
    ext = ext[1:]
    filetype = get_filetype(ext)

    # Extends default attributes for the filetype
    default_attrs = app_settings.FILETYPES_ATTRIBUTES.get(filetype, {})
    attrs = dict(default_attrs, **attrs)

    # Convert the src to a URL relative to the MEDIA_URL or absolute
    src = get_relative_url(src)

    # Apply processors (image resize or others)
    processors = get_filetype_processors(filetype)
    for proc in processors:
        src, attrs = proc(src, attrs)

    # Add anti-cache query string
    anti_cache = nocache(src)
    if anti_cache:
        src += '?' + anti_cache

    # Return the (possibly) modified src and attributes
    return src, filetype, attrs
示例#3
0
 def test_import(self):
     from webmedia.processors import get_filetype_processors
     from webmedia.processors.image import thumbnail
     image_processors = get_filetype_processors('image')
     self.assertEqual(image_processors, [thumbnail])