mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-17 05:40:25 +00:00
Correct pickling/unpickling of dynamic specs
Previously, __reduce__ was returning a reduction of the class, not the instance.
This commit is contained in:
parent
938e2e178b
commit
0ec6067c8d
1 changed files with 14 additions and 8 deletions
|
|
@ -143,15 +143,22 @@ class ImageSpec(BaseImageSpec):
|
|||
return content
|
||||
|
||||
|
||||
def create_spec_class(class_attrs):
|
||||
cls = type('Spec', (DynamicSpec,), class_attrs)
|
||||
cls._spec_attrs = class_attrs
|
||||
return cls
|
||||
|
||||
|
||||
def create_spec(class_attrs, kwargs):
|
||||
cls = create_spec_class(class_attrs)
|
||||
return cls(**kwargs)
|
||||
|
||||
|
||||
class DynamicSpec(ImageSpec):
|
||||
def __reduce__(self):
|
||||
return (create_spec_class, (self._spec_attrs,))
|
||||
|
||||
|
||||
def create_spec_class(spec_attrs):
|
||||
cls = type('Spec', (DynamicSpec,), spec_attrs)
|
||||
cls._spec_attrs = spec_attrs
|
||||
return cls
|
||||
kwargs = dict(self.kwargs)
|
||||
kwargs['source_file'] = self.source_file
|
||||
return (create_spec, (self._spec_attrs, kwargs))
|
||||
|
||||
|
||||
class SpecHost(object):
|
||||
|
|
@ -169,7 +176,6 @@ class SpecHost(object):
|
|||
raise TypeError('You can provide either an image spec or'
|
||||
' arguments for the ImageSpec constructor, but not both.')
|
||||
else:
|
||||
# spec = type('Spec', (ImageSpec,), spec_attrs) # TODO: Base class name on spec id?
|
||||
spec = create_spec_class(spec_attrs)
|
||||
|
||||
self._original_spec = spec
|
||||
|
|
|
|||
Loading…
Reference in a new issue