mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-05-28 22:08:17 +00:00
Merge pull request #267 from bmispelon/issue-266
Fixed #266 -- Simplified (and renamed) StrategyWrapper.
This commit is contained in:
commit
d3aabb0db3
2 changed files with 10 additions and 23 deletions
|
|
@ -36,24 +36,11 @@ class DictStrategy(object):
|
||||||
setattr(self, k, v)
|
setattr(self, k, v)
|
||||||
|
|
||||||
|
|
||||||
class StrategyWrapper(LazyObject):
|
def load_strategy(strategy):
|
||||||
def __init__(self, strategy):
|
if isinstance(strategy, six.string_types):
|
||||||
if isinstance(strategy, six.string_types):
|
strategy = get_singleton(strategy, 'cache file strategy')
|
||||||
strategy = get_singleton(strategy, 'cache file strategy')
|
elif isinstance(strategy, dict):
|
||||||
elif isinstance(strategy, dict):
|
strategy = DictStrategy(strategy)
|
||||||
strategy = DictStrategy(strategy)
|
elif callable(strategy):
|
||||||
elif callable(strategy):
|
strategy = strategy()
|
||||||
strategy = strategy()
|
return strategy
|
||||||
self._wrapped = strategy
|
|
||||||
|
|
||||||
def __getstate__(self):
|
|
||||||
return {'_wrapped': self._wrapped}
|
|
||||||
|
|
||||||
def __setstate__(self, state):
|
|
||||||
self._wrapped = state['_wrapped']
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return force_text(self._wrapped)
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return str(self._wrapped)
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ from copy import copy
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db.models.fields.files import ImageFieldFile
|
from django.db.models.fields.files import ImageFieldFile
|
||||||
from ..cachefiles.backends import get_default_cachefile_backend
|
from ..cachefiles.backends import get_default_cachefile_backend
|
||||||
from ..cachefiles.strategies import StrategyWrapper
|
from ..cachefiles.strategies import load_strategy
|
||||||
from .. import hashers
|
from .. import hashers
|
||||||
from ..exceptions import AlreadyRegistered, MissingSource
|
from ..exceptions import AlreadyRegistered, MissingSource
|
||||||
from ..utils import open_image, get_by_qname, process_image
|
from ..utils import open_image, get_by_qname, process_image
|
||||||
|
|
@ -36,7 +36,7 @@ class BaseImageSpec(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.cachefile_backend = self.cachefile_backend or get_default_cachefile_backend()
|
self.cachefile_backend = self.cachefile_backend or get_default_cachefile_backend()
|
||||||
self.cachefile_strategy = StrategyWrapper(self.cachefile_strategy)
|
self.cachefile_strategy = load_strategy(self.cachefile_strategy)
|
||||||
|
|
||||||
def generate(self):
|
def generate(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue