[close #141] Fix checking if thumbnail exists in management command.

This commit is contained in:
Piotr Maliński 2014-11-02 17:32:55 +01:00
parent 8fe3c51662
commit ca89d42126
1 changed files with 11 additions and 1 deletions

View File

@ -17,7 +17,7 @@ class Command(NoArgsCommand):
if getattr(settings, 'CKEDITOR_IMAGE_BACKEND', None):
backend = get_backend()
for image in get_image_files():
if not os.path.isfile(get_thumb_filename(image)):
if not self._thumbnail_exists(image):
self.stdout.write("Creating thumbnail for %s" % image)
try:
backend.create_thumbnail(image)
@ -26,3 +26,13 @@ class Command(NoArgsCommand):
self.stdout.write("Finished")
else:
self.stdout.write("No thumbnail backend is enabled")
def _thumbnail_exists(self, image_path):
thumb_path = self._to_absolute_path(
get_thumb_filename(image_path)
)
return os.path.isfile(thumb_path)
@staticmethod
def _to_absolute_path(image_path):
return os.path.join(settings.MEDIA_ROOT, image_path)