From 2f7bfe5dc7ebf01310812d8a8638926e12f957d7 Mon Sep 17 00:00:00 2001 From: Colin Wood Date: Fri, 11 Jul 2014 10:07:43 -0400 Subject: [PATCH] Make sure image files has a name associated. The generate image command will run into issues if the ImageSpecField does not have any image file source associated wit hti. Like a Optional image field. So we can not generate the images for that. So this should check to make sure that it has one. --- imagekit/management/commands/generateimages.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/imagekit/management/commands/generateimages.py b/imagekit/management/commands/generateimages.py index 444440a..0d9cae5 100644 --- a/imagekit/management/commands/generateimages.py +++ b/imagekit/management/commands/generateimages.py @@ -1,6 +1,7 @@ from django.core.management.base import BaseCommand import re from ...registry import generator_registry, cachefile_registry +from ...exceptions import MissingSource class Command(BaseCommand): @@ -22,14 +23,15 @@ well as "a:b" and "a:b:c".""") for generator_id in generators: self.stdout.write('Validating generator: %s\n' % generator_id) - for file in cachefile_registry.get(generator_id): - self.stdout.write(' %s\n' % file) - try: - # TODO: Allow other validation actions through command option - file.generate() - except Exception as 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 image_file in cachefile_registry.get(generator_id): + if image_file.name: + self.stdout.write(' %s\n' % image_file.name) + try: + image_file.generate() + except MissingSource as err: + self.stdout.write('\t No source associated with\n') + except Exception as err: + self.stdout.write('\tFailed %s\n' % (err)) def compile_patterns(self, generator_ids): return [self.compile_pattern(id) for id in generator_ids]