From 3022eb037d7bb18b0f1b44a0bd38dc8e0dd21382 Mon Sep 17 00:00:00 2001 From: Matthew Tretter Date: Thu, 3 Nov 2011 12:31:04 -0400 Subject: [PATCH] Proper handling of empty images and missing fields Fixes #42 --- imagekit/admin.py | 6 +++--- imagekit/templates/imagekit/admin/thumbnail.html | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/imagekit/admin.py b/imagekit/admin.py index 94d9cf5..ebab76c 100644 --- a/imagekit/admin.py +++ b/imagekit/admin.py @@ -21,9 +21,9 @@ class AdminThumbnail(object): self.template = template def __call__(self, obj): - thumbnail = getattr(obj, self.image_field, None) - - if not thumbnail: + 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__)) 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