mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-17 05:40:25 +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)
|
||||
|
||||
|
||||
class StrategyWrapper(LazyObject):
|
||||
def __init__(self, strategy):
|
||||
if isinstance(strategy, six.string_types):
|
||||
strategy = get_singleton(strategy, 'cache file strategy')
|
||||
elif isinstance(strategy, dict):
|
||||
strategy = DictStrategy(strategy)
|
||||
elif callable(strategy):
|
||||
strategy = 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)
|
||||
def load_strategy(strategy):
|
||||
if isinstance(strategy, six.string_types):
|
||||
strategy = get_singleton(strategy, 'cache file strategy')
|
||||
elif isinstance(strategy, dict):
|
||||
strategy = DictStrategy(strategy)
|
||||
elif callable(strategy):
|
||||
strategy = strategy()
|
||||
return strategy
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from copy import copy
|
|||
from django.conf import settings
|
||||
from django.db.models.fields.files import ImageFieldFile
|
||||
from ..cachefiles.backends import get_default_cachefile_backend
|
||||
from ..cachefiles.strategies import StrategyWrapper
|
||||
from ..cachefiles.strategies import load_strategy
|
||||
from .. import hashers
|
||||
from ..exceptions import AlreadyRegistered, MissingSource
|
||||
from ..utils import open_image, get_by_qname, process_image
|
||||
|
|
@ -36,7 +36,7 @@ class BaseImageSpec(object):
|
|||
|
||||
def __init__(self):
|
||||
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):
|
||||
raise NotImplementedError
|
||||
|
|
|
|||
Loading…
Reference in a new issue