From 56c66f48833e5a36a6f65209d5b56a2391682882 Mon Sep 17 00:00:00 2001 From: Matthew Tretter Date: Thu, 4 Oct 2012 23:15:16 -0400 Subject: [PATCH] Back ProcessedImageField with spec registry --- imagekit/models/fields/__init__.py | 12 +++++++----- imagekit/specs.py | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/imagekit/models/fields/__init__.py b/imagekit/models/fields/__init__.py index 73969dc..f0e10af 100644 --- a/imagekit/models/fields/__init__.py +++ b/imagekit/models/fields/__init__.py @@ -30,7 +30,8 @@ class ImageSpecField(SpecHost): SpecHost.__init__(self, processors=p, format=format, options=options, storage=storage, autoconvert=autoconvert, image_cache_backend=image_cache_backend, - image_cache_strategy=image_cache_strategy, spec=spec, id=id) + image_cache_strategy=image_cache_strategy, spec=spec, + spec_id=id) self.image_field = image_field @@ -71,7 +72,7 @@ class ImageSpecField(SpecHost): pass -class ProcessedImageField(models.ImageField): +class ProcessedImageField(models.ImageField, SpecHost): """ ProcessedImageField is an ImageField that runs processors on the uploaded image *before* saving it to storage. This is in contrast to specs, which @@ -83,7 +84,7 @@ class ProcessedImageField(models.ImageField): def __init__(self, processors=None, format=None, options=None, verbose_name=None, name=None, width_field=None, height_field=None, - autoconvert=True, **kwargs): + autoconvert=True, spec=None, spec_id=None, **kwargs): """ The ProcessedImageField constructor accepts all of the arguments that the :class:`django.db.models.ImageField` constructor accepts, as well @@ -91,10 +92,11 @@ class ProcessedImageField(models.ImageField): :class:`imagekit.models.ImageSpecField`. """ + SpecHost.__init__(self, processors=processors, format=format, + options=options, autoconvert=autoconvert, spec=spec, + spec_id=spec_id) models.ImageField.__init__(self, verbose_name, name, width_field, height_field, **kwargs) - self.spec = ImageSpec(processors, format=format, options=options, - autoconvert=autoconvert) def get_filename(self, filename): filename = os.path.normpath(self.storage.get_valid_name( diff --git a/imagekit/specs.py b/imagekit/specs.py index d2e0cba..b4ea37b 100644 --- a/imagekit/specs.py +++ b/imagekit/specs.py @@ -174,7 +174,7 @@ class SpecHost(object): """ def __init__(self, processors=None, format=None, options=None, storage=None, autoconvert=None, image_cache_backend=None, - image_cache_strategy=None, spec=None, id=None): + image_cache_strategy=None, spec=None, spec_id=None): if spec: if any([processors, format, options, storage, autoconvert, @@ -195,9 +195,9 @@ class SpecHost(object): self._original_spec = spec self.spec_id = None - if id: + if spec_id: # If an id is given, register the spec immediately. - self.register_spec(id) + self.register_spec(spec_id) def register_spec(self, id): """