2012-09-06 02:19:46 +00:00
|
|
|
from ...utils import get_singleton
|
2012-03-05 16:47:19 +00:00
|
|
|
from django.core.exceptions import ImproperlyConfigured
|
|
|
|
|
|
|
|
|
|
|
2012-09-06 02:19:46 +00:00
|
|
|
def get_default_image_cache_backend():
|
|
|
|
|
"""
|
|
|
|
|
Get the default image cache backend.
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
from django.conf import settings
|
|
|
|
|
return get_singleton(settings.IMAGEKIT_DEFAULT_IMAGE_CACHE_BACKEND,
|
|
|
|
|
'image cache backend')
|
|
|
|
|
|
|
|
|
|
|
2012-03-05 16:47:19 +00:00
|
|
|
class InvalidImageCacheBackendError(ImproperlyConfigured):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2012-09-06 02:19:46 +00:00
|
|
|
class Simple(object):
|
2012-02-11 05:15:58 +00:00
|
|
|
"""
|
2012-09-06 02:19:46 +00:00
|
|
|
The most basic image cache backend. Files are considered valid if they
|
|
|
|
|
exist. To invalidate a file, it's deleted; to validate one, it's generated
|
|
|
|
|
immediately.
|
2012-02-11 05:15:58 +00:00
|
|
|
|
|
|
|
|
"""
|
2012-02-02 03:37:58 +00:00
|
|
|
|
|
|
|
|
def is_invalid(self, file):
|
|
|
|
|
if not getattr(file, '_file', None):
|
|
|
|
|
# No file on object. Have to check storage.
|
|
|
|
|
return not file.storage.exists(file.name)
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def validate(self, file):
|
|
|
|
|
"""
|
|
|
|
|
Generates a new image by running the processors on the source file.
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
if self.is_invalid(file):
|
2012-02-03 14:16:50 +00:00
|
|
|
file.generate(save=True)
|
2012-02-02 03:37:58 +00:00
|
|
|
|
|
|
|
|
def invalidate(self, file):
|
|
|
|
|
file.delete(save=False)
|
|
|
|
|
|
2012-02-03 04:20:09 +00:00
|
|
|
def clear(self, file):
|
|
|
|
|
file.delete(save=False)
|