Merge pull request #267 from bmispelon/issue-266

Fixed #266 -- Simplified (and renamed) StrategyWrapper.
This commit is contained in:
Matthew Dapena-Tretter 2014-01-21 08:53:56 -08:00
commit d3aabb0db3
2 changed files with 10 additions and 23 deletions

View file

@ -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

View file

@ -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