From 2387cc4be2274aa841672c2eccb9c7fc5d077354 Mon Sep 17 00:00:00 2001 From: Matthew Tretter Date: Fri, 2 Sep 2011 23:24:35 -0400 Subject: [PATCH] Added ability to specify specs in IKOptions directly. --- imagekit/models.py | 21 +++++++++++---------- imagekit/options.py | 3 ++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/imagekit/models.py b/imagekit/models.py index 6a8a0a1..3241d09 100644 --- a/imagekit/models.py +++ b/imagekit/models.py @@ -44,17 +44,18 @@ class ImageModelBase(ModelBase): return user_opts = getattr(cls, 'IKOptions', None) opts = Options(user_opts) - try: - module = __import__(opts.spec_module, {}, {}, ['']) - except ImportError: - raise ImportError('Unable to load imagekit config module: %s' % \ - opts.spec_module) - for spec in [spec for spec in module.__dict__.values() \ - if isinstance(spec, type) \ - and issubclass(spec, specs.ImageSpec) \ - and spec != specs.ImageSpec]: + if not opts.specs: + try: + module = __import__(opts.spec_module, {}, {}, ['']) + except ImportError: + raise ImportError('Unable to load imagekit config module: %s' \ + % opts.spec_module) + opts.specs.extend([spec for spec in module.__dict__.values() \ + if isinstance(spec, type) \ + and issubclass(spec, specs.ImageSpec) \ + and spec != specs.ImageSpec]) + for spec in opts.specs: setattr(cls, spec.name(), specs.Descriptor(spec)) - opts.specs.append(spec) setattr(cls, '_ik', opts) diff --git a/imagekit/options.py b/imagekit/options.py index cd3fc85..7170799 100644 --- a/imagekit/options.py +++ b/imagekit/options.py @@ -17,9 +17,10 @@ class Options(object): cache_filename_format = "%(filename)s_%(specname)s.%(extension)s" admin_thumbnail_spec = 'admin_thumbnail' spec_module = 'imagekit.defaults' + specs = None #storage = defaults to image_field.storage def __init__(self, opts): for key, value in opts.__dict__.iteritems(): setattr(self, key, value) - self.specs = [] + self.specs = list(self.specs or [])