diff --git a/imagekit/management/commands/warmimagecache.py b/imagekit/management/commands/warmimagecache.py index 42a005d..dfe5d46 100644 --- a/imagekit/management/commands/warmimagecache.py +++ b/imagekit/management/commands/warmimagecache.py @@ -19,17 +19,16 @@ class Command(BaseCommand): for generator_id in generators: self.stdout.write('Validating generator: %s\n' % generator_id) - for cacheables in cacheable_registry.get(generator_id): - for cacheable in cacheables.files(): - if cacheable: - generator = generator_registry.get(generator_id, cacheable=cacheable) # TODO: HINTS! (Probably based on cacheable, so this will need to be moved into loop below.) - self.stdout.write(' %s\n' % cacheable) - try: - # TODO: Allow other validation actions through command option - GeneratedImageCacheFile(generator).validate() - except Exception, err: - # TODO: How should we handle failures? Don't want to error, but should call it out more than this. - self.stdout.write(' FAILED: %s\n' % err) + for kwargs in cacheable_registry.get(generator_id): + if kwargs: + generator = generator_registry.get(generator_id, **kwargs) # TODO: HINTS! (Probably based on cacheable, so this will need to be moved into loop below.) + self.stdout.write(' %s\n' % generator) + try: + # TODO: Allow other validation actions through command option + GeneratedImageCacheFile(generator).validate() + except Exception, err: + # TODO: How should we handle failures? Don't want to error, but should call it out more than this. + self.stdout.write(' FAILED: %s\n' % err) def compile_patterns(self, generator_ids): return [re.compile('%s$' % '.*'.join(re.escape(part) for part in id.split('*'))) for id in generator_ids] diff --git a/imagekit/registry.py b/imagekit/registry.py index 93e491f..258f252 100644 --- a/imagekit/registry.py +++ b/imagekit/registry.py @@ -70,25 +70,25 @@ class CacheableRegistry(object): Associates cacheables with a generator id """ - for cacheable in cacheables: - if cacheable not in self._cacheables: - self._cacheables[cacheable] = set() - self._cacheables[cacheable].add(generator_id) + if cacheables not in self._cacheables: + self._cacheables[cacheables] = set() + self._cacheables[cacheables].add(generator_id) def unregister(self, generator_id, cacheables): """ Disassociates cacheables with a generator id """ - for cacheable in cacheables: - try: - self._cacheables[cacheable].remove(generator_id) - except KeyError: - continue + try: + self._cacheables[cacheables].remove(generator_id) + except KeyError: + pass def get(self, generator_id): - return [cacheable for cacheable in self._cacheables - if generator_id in self._cacheables[cacheable]] + for k, v in self._cacheables.items(): + if generator_id in v: + for cacheable in k(): + yield cacheable def before_access_receiver(self, sender, generator, cacheable, **kwargs): generator.image_cache_strategy.invoke_callback('before_access', cacheable) @@ -130,8 +130,6 @@ class Register(object): # iterable that returns kwargs or callable that returns iterable of kwargs def cacheables(self, generator_id, cacheables): - if callable(cacheables): - cacheables = cacheables() cacheable_registry.register(generator_id, cacheables) @@ -144,8 +142,6 @@ class Unregister(object): generator_registry.unregister(id, generator) def cacheables(self, generator_id, cacheables): - if callable(cacheables): - cacheables = cacheables() cacheable_registry.unregister(generator_id, cacheables) diff --git a/imagekit/specs/sourcegroups.py b/imagekit/specs/sourcegroups.py index 6bd1eed..04c30c3 100644 --- a/imagekit/specs/sourcegroups.py +++ b/imagekit/specs/sourcegroups.py @@ -117,11 +117,8 @@ class ImageFieldSourceGroup(object): self.image_field = image_field signal_router.add(self) - def files(self): - for instance in self.model_class.objects.all(): - yield getattr(instance, self.image_field) - def __call__(self): - return self.files() + for instance in self.model_class.objects.all(): + yield {'source': getattr(instance, self.image_field)} signal_router = ModelSignalRouter()