Add IKOption.storage to explicitly set cached thumbnail storage.

Original image storage is still the default, and the original image
is always read from its own storage.
This commit is contained in:
Ben Jackson 2009-12-17 22:26:19 -08:00
parent f28683dd0f
commit 26f01721df
3 changed files with 11 additions and 6 deletions

View file

@ -93,6 +93,10 @@ class ImageModel(models.Model):
@property
def _imgfield(self):
return getattr(self, self._ik.image_field)
@property
def _storage(self):
return getattr(self._ik, 'storage', self._imgfield.storage)
def _clear_cache(self):
for spec in self._ik.specs:

View file

@ -16,8 +16,9 @@ class Options(object):
cache_filename_format = "%(filename)s_%(specname)s.%(extension)s"
admin_thumbnail_spec = 'admin_thumbnail'
spec_module = 'imagekit.defaults'
#storage = defaults to image_field.storage
def __init__(self, opts):
for key, value in opts.__dict__.iteritems():
setattr(self, key, value)
self.specs = []
self.specs = []

View file

@ -63,13 +63,13 @@ class Accessor(object):
self._img, self._fmt = self.spec.process(Image.open(fp), self._obj)
# save the new image to the cache
content = ContentFile(self._get_imgfile().read())
self._obj._imgfield.storage.save(self.name, content)
self._obj._storage.save(self.name, content)
def _delete(self):
self._obj._imgfield.storage.delete(self.name)
self._obj._storage.delete(self.name)
def _exists(self):
return self._obj._imgfield.storage.exists(self.name)
return self._obj._storage.exists(self.name)
@property
def name(self):
@ -98,12 +98,12 @@ class Accessor(object):
current_count = getattr(self._obj, fieldname)
setattr(self._obj, fieldname, current_count + 1)
self._obj.save(clear_cache=False)
return self._obj._imgfield.storage.url(self.name)
return self._obj._storage.url(self.name)
@property
def file(self):
self._create()
return self._obj._imgfield.storage.open(self.name)
return self._obj._storage.open(self.name)
@property
def image(self):