You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.4 KiB
46 lines
1.4 KiB
""" |
|
Functions responsible for returning filenames for the given image generator. |
|
Users are free to define their own functions; these are just some some sensible |
|
choices. |
|
|
|
""" |
|
|
|
from django.conf import settings |
|
import os |
|
from ..utils import suggest_extension |
|
|
|
|
|
def spec_slug_as_path(generator): |
|
""" |
|
A namer that, given the following source file name:: |
|
|
|
<asset_uuid>/original/bulldog.jpg |
|
|
|
will generate a relative name like this:: |
|
|
|
<spec_slug>/5ff3233527c5ac3e4b596343b440ff67.jpg |
|
|
|
which is meant to be added to both |
|
|
|
<asset_uuid>/cache/ |
|
<asset_uuid>/manual/ |
|
. |
|
|
|
""" |
|
source_filename = getattr(generator.source, 'name', None) |
|
spec_slug = getattr(generator, 'slug', None) |
|
|
|
ext = suggest_extension(source_filename or '', generator.format) |
|
|
|
|
|
if source_filename is None or os.path.isabs(source_filename): |
|
# Generally, we put the file right in the cache file directory. |
|
dir = settings.IMAGEKIT_CACHEFILE_DIR |
|
else: |
|
# For source files with relative names (like Django media files), |
|
# use the source's name to create the new filename. |
|
dir = os.path.join(settings.IMAGEKIT_CACHEFILE_DIR, |
|
os.path.splitext(source_filename)[0]) |
|
|
|
return os.path.normpath(os.path.join(dir, |
|
'%s%s' % (generator.get_hash(), ext)))
|
|
|