mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-17 05:40:25 +00:00
Rename cache_state_backend to image_cache_backend
Related names (like the package and class names) have also been updated.
This commit is contained in:
parent
15b15afe2c
commit
e9e364eedd
3 changed files with 29 additions and 29 deletions
|
|
@ -2,9 +2,9 @@ from django.core.exceptions import ImproperlyConfigured
|
|||
from django.utils.importlib import import_module
|
||||
|
||||
|
||||
class PessimisticCacheStateBackend(object):
|
||||
class PessimisticImageCacheBackend(object):
|
||||
"""
|
||||
A very safe cache state backend. Guarantees that files will always be
|
||||
A very safe image cache backend. Guarantees that files will always be
|
||||
available, but at the cost of hitting the storage backend.
|
||||
|
||||
"""
|
||||
|
|
@ -30,7 +30,7 @@ class PessimisticCacheStateBackend(object):
|
|||
file.delete(save=False)
|
||||
|
||||
|
||||
class NonValidatingCacheStateBackend(object):
|
||||
class NonValidatingImageCacheBackend(object):
|
||||
"""
|
||||
A backend that is super optimistic about the existence of spec files. It
|
||||
will hit your file storage much less frequently than the pessimistic
|
||||
|
|
@ -41,7 +41,7 @@ class NonValidatingCacheStateBackend(object):
|
|||
|
||||
def validate(self, file):
|
||||
"""
|
||||
NonValidatingCacheStateBackend has faith, so validate's a no-op.
|
||||
NonValidatingImageCacheBackend has faith, so validate's a no-op.
|
||||
|
||||
"""
|
||||
pass
|
||||
|
|
@ -57,31 +57,31 @@ class NonValidatingCacheStateBackend(object):
|
|||
file.delete(save=False)
|
||||
|
||||
|
||||
_default_cache_state_backend = None
|
||||
_default_image_cache_backend = None
|
||||
|
||||
|
||||
def get_default_cache_state_backend():
|
||||
def get_default_image_cache_backend():
|
||||
"""
|
||||
Get the default cache state backend. Uses the same method as
|
||||
Get the default image cache backend. Uses the same method as
|
||||
django.core.file.storage.get_storage_class
|
||||
|
||||
"""
|
||||
global _default_cache_state_backend
|
||||
if not _default_cache_state_backend:
|
||||
from ..settings import DEFAULT_CACHE_STATE_BACKEND as import_path
|
||||
global _default_image_cache_backend
|
||||
if not _default_image_cache_backend:
|
||||
from .settings import DEFAULT_IMAGE_CACHE_BACKEND as import_path
|
||||
try:
|
||||
dot = import_path.rindex('.')
|
||||
except ValueError:
|
||||
raise ImproperlyConfigured("%s isn't a cache state backend module." % \
|
||||
raise ImproperlyConfigured("%s isn't an image cache backend module." % \
|
||||
import_path)
|
||||
module, classname = import_path[:dot], import_path[dot+1:]
|
||||
try:
|
||||
mod = import_module(module)
|
||||
except ImportError, e:
|
||||
raise ImproperlyConfigured('Error importing cache state module %s: "%s"' % (module, e))
|
||||
raise ImproperlyConfigured('Error importing image cache backend module %s: "%s"' % (module, e))
|
||||
try:
|
||||
cls = getattr(mod, classname)
|
||||
_default_cache_state_backend = cls()
|
||||
_default_image_cache_backend = cls()
|
||||
except AttributeError:
|
||||
raise ImproperlyConfigured('Cache state backend module "%s" does not define a "%s" class.' % (module, classname))
|
||||
return _default_cache_state_backend
|
||||
raise ImproperlyConfigured('Image cache backend module "%s" does not define a "%s" class.' % (module, classname))
|
||||
return _default_image_cache_backend
|
||||
|
|
@ -12,7 +12,7 @@ from imagekit.utils import img_to_fobj, open_image, \
|
|||
format_to_extension, extension_to_format, UnknownFormatError, \
|
||||
UnknownExtensionError
|
||||
from imagekit.processors import ProcessorPipeline, AutoConvert
|
||||
from .cachestate import get_default_cache_state_backend
|
||||
from .imagecache import get_default_image_cache_backend
|
||||
|
||||
|
||||
class _ImageSpecMixin(object):
|
||||
|
|
@ -64,7 +64,7 @@ class ImageSpec(_ImageSpecMixin):
|
|||
|
||||
def __init__(self, processors=None, format=None, options={},
|
||||
image_field=None, pre_cache=None, storage=None, cache_to=None,
|
||||
autoconvert=True, cache_state_backend=None):
|
||||
autoconvert=True, image_cache_backend=None):
|
||||
"""
|
||||
:param processors: A list of processors to run on the original image.
|
||||
:param format: The format of the output file. If not provided,
|
||||
|
|
@ -96,9 +96,9 @@ class ImageSpec(_ImageSpecMixin):
|
|||
this extension, it's only a recommendation.
|
||||
:param autoconvert: Specifies whether the AutoConvert processor
|
||||
should be run before saving.
|
||||
:param cache_state_backend: An object responsible for managing the state
|
||||
:param image_cache_backend: An object responsible for managing the state
|
||||
of cached files. Defaults to an instance of
|
||||
IMAGEKIT_DEFAULT_CACHE_STATE_BACKEND
|
||||
IMAGEKIT_DEFAULT_IMAGE_CACHE_BACKEND
|
||||
|
||||
"""
|
||||
|
||||
|
|
@ -112,8 +112,8 @@ class ImageSpec(_ImageSpecMixin):
|
|||
self.pre_cache = pre_cache
|
||||
self.storage = storage
|
||||
self.cache_to = cache_to
|
||||
self.cache_state_backend = cache_state_backend or \
|
||||
get_default_cache_state_backend()
|
||||
self.image_cache_backend = image_cache_backend or \
|
||||
get_default_image_cache_backend()
|
||||
|
||||
def contribute_to_class(self, cls, name):
|
||||
setattr(cls, name, _ImageSpecDescriptor(self, name))
|
||||
|
|
@ -133,9 +133,9 @@ class ImageSpec(_ImageSpecMixin):
|
|||
post_delete.connect(ImageSpec._post_delete_receiver, sender=cls,
|
||||
dispatch_uid=uid)
|
||||
|
||||
# Register the field with the cache_state_backend
|
||||
# Register the field with the image_cache_backend
|
||||
try:
|
||||
self.cache_state_backend.register_field(cls, self, name)
|
||||
self.image_cache_backend.register_field(cls, self, name)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
|
|
@ -264,13 +264,13 @@ class ImageSpecFile(_ImageSpecFileMixin, ImageFieldFile):
|
|||
file = property(_get_file, ImageFieldFile._set_file, ImageFieldFile._del_file)
|
||||
|
||||
def clear(self):
|
||||
return self.field.cache_state_backend.clear(self)
|
||||
return self.field.image_cache_backend.clear(self)
|
||||
|
||||
def invalidate(self):
|
||||
return self.field.cache_state_backend.invalidate(self)
|
||||
return self.field.image_cache_backend.invalidate(self)
|
||||
|
||||
def validate(self):
|
||||
return self.field.cache_state_backend.validate(self)
|
||||
return self.field.image_cache_backend.validate(self)
|
||||
|
||||
def generate(self, save=True):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from django.conf import settings
|
||||
|
||||
DEFAULT_CACHE_STATE_BACKEND = getattr(settings,
|
||||
'IMAGEKIT_DEFAULT_CACHE_STATE_BACKEND',
|
||||
'imagekit.cachestate.PessimisticCacheStateBackend')
|
||||
DEFAULT_IMAGE_CACHE_BACKEND = getattr(settings,
|
||||
'IMAGEKIT_DEFAULT_IMAGE_CACHE_BACKEND',
|
||||
'imagekit.imagecache.PessimisticImageCacheBackend')
|
||||
|
|
|
|||
Loading…
Reference in a new issue