mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-05-09 13:54:43 +00:00
Add __getstate__ method to ImageCacheFile
This commit is contained in:
parent
857b1e160e
commit
1c26a2ea5c
2 changed files with 22 additions and 1 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
from copy import copy
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.files import File
|
from django.core.files import File
|
||||||
from django.core.files.images import ImageFile
|
from django.core.files.images import ImageFile
|
||||||
|
|
@ -129,6 +130,14 @@ class ImageCacheFile(BaseIKFile, ImageFile):
|
||||||
existence_required.send(sender=self, file=self)
|
existence_required.send(sender=self, file=self)
|
||||||
return self.cachefile_backend.exists(self)
|
return self.cachefile_backend.exists(self)
|
||||||
|
|
||||||
|
def __getstate__(self):
|
||||||
|
state = copy(self.__dict__)
|
||||||
|
|
||||||
|
# file is hidden link to "file" attribute
|
||||||
|
state.pop('_file', None)
|
||||||
|
|
||||||
|
return state
|
||||||
|
|
||||||
|
|
||||||
class LazyImageCacheFile(SimpleLazyObject):
|
class LazyImageCacheFile(SimpleLazyObject):
|
||||||
def __init__(self, generator_id, *args, **kwargs):
|
def __init__(self, generator_id, *args, **kwargs):
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,9 @@ deserialized. This is important when using IK with Celery.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from .utils import create_photo, pickleback
|
from imagekit.cachefiles import ImageCacheFile
|
||||||
|
from .imagegenerators import TestSpec
|
||||||
|
from .utils import create_photo, pickleback, get_unique_image_file
|
||||||
|
|
||||||
|
|
||||||
def test_imagespecfield():
|
def test_imagespecfield():
|
||||||
|
|
@ -23,3 +25,13 @@ def test_circular_ref():
|
||||||
instance = create_photo('pickletest3.jpg')
|
instance = create_photo('pickletest3.jpg')
|
||||||
instance.thumbnail # Cause thumbnail to be added to instance's __dict__
|
instance.thumbnail # Cause thumbnail to be added to instance's __dict__
|
||||||
pickleback(instance)
|
pickleback(instance)
|
||||||
|
|
||||||
|
|
||||||
|
def test_cachefiles():
|
||||||
|
spec = TestSpec(source=get_unique_image_file())
|
||||||
|
file = ImageCacheFile(spec)
|
||||||
|
file.url
|
||||||
|
# remove link to file from spec source generator
|
||||||
|
# test __getstate__ of ImageCacheFile
|
||||||
|
file.generator.source = None
|
||||||
|
pickleback(file)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue