mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-17 05:40:25 +00:00
Simplify dynamic spec definitions
Use a closure instead of an attribute to store the class attrs.
This commit is contained in:
parent
c45876f95c
commit
042bdcefb6
1 changed files with 8 additions and 10 deletions
|
|
@ -144,9 +144,14 @@ class ImageSpec(BaseImageSpec):
|
|||
|
||||
|
||||
def create_spec_class(class_attrs):
|
||||
cls = type('Spec', (DynamicSpec,), class_attrs)
|
||||
cls._spec_attrs = class_attrs
|
||||
return cls
|
||||
|
||||
class DynamicSpecBase(ImageSpec):
|
||||
def __reduce__(self):
|
||||
kwargs = dict(self.kwargs)
|
||||
kwargs['source_file'] = self.source_file
|
||||
return (create_spec, (class_attrs, kwargs))
|
||||
|
||||
return type('DynamicSpec', (DynamicSpecBase,), class_attrs)
|
||||
|
||||
|
||||
def create_spec(class_attrs, kwargs):
|
||||
|
|
@ -154,13 +159,6 @@ def create_spec(class_attrs, kwargs):
|
|||
return cls(**kwargs)
|
||||
|
||||
|
||||
class DynamicSpec(ImageSpec):
|
||||
def __reduce__(self):
|
||||
kwargs = dict(self.kwargs)
|
||||
kwargs['source_file'] = self.source_file
|
||||
return (create_spec, (self._spec_attrs, kwargs))
|
||||
|
||||
|
||||
class SpecHost(object):
|
||||
"""
|
||||
An object that ostensibly has a spec attribute but really delegates to the
|
||||
|
|
|
|||
Loading…
Reference in a new issue