diff --git a/imagekit/admin.py b/imagekit/admin.py index cc24d29..ebab76c 100644 --- a/imagekit/admin.py +++ b/imagekit/admin.py @@ -21,11 +21,11 @@ class AdminThumbnail(object): self.template = template def __call__(self, obj): - thumbnail = getattr(obj, self.image_field, None) - - if not thumbnail: - raise Exception('The property {0} is not defined on {1}.'.format( - obj, self.image_field)) + try: + thumbnail = getattr(obj, self.image_field) + except AttributeError: + raise Exception('The property %s is not defined on %s.' % \ + (self.image_field, obj.__class__.__name__)) original_image = getattr(thumbnail, 'source_file', None) or thumbnail template = self.template or 'imagekit/admin/thumbnail.html' diff --git a/imagekit/templates/imagekit/admin/thumbnail.html b/imagekit/templates/imagekit/admin/thumbnail.html index 6531391..adaa89f 100644 --- a/imagekit/templates/imagekit/admin/thumbnail.html +++ b/imagekit/templates/imagekit/admin/thumbnail.html @@ -1,3 +1,5 @@ - - - \ No newline at end of file +{% if thumbnail %} + + + +{% endif %} \ No newline at end of file diff --git a/imagekit/utils.py b/imagekit/utils.py index b6ca548..07cd532 100644 --- a/imagekit/utils.py +++ b/imagekit/utils.py @@ -97,9 +97,10 @@ def _extension_to_format(extension): def _format_to_extension(format): - for k, v in Image.EXTENSION.iteritems(): - if v == format.upper(): - return k + if format: + for k, v in Image.EXTENSION.iteritems(): + if v == format.upper(): + return k return None @@ -121,11 +122,13 @@ def format_to_extension(format): """Returns the first extension that matches the provided format. """ - extension = _format_to_extension(format) - if not extension and _preinit_pil(): - extension = _format_to_extension(format) - if not extension and _init_pil(): + extension = None + if format: extension = _format_to_extension(format) + if not extension and _preinit_pil(): + extension = _format_to_extension(format) + if not extension and _init_pil(): + extension = _format_to_extension(format) if not extension: raise UnknownFormatError(format) return extension