From ca89d42126f999e5907090338690eaad8e84458c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Mali=C5=84ski?= Date: Sun, 2 Nov 2014 17:32:55 +0100 Subject: [PATCH] [close #141] Fix checking if thumbnail exists in management command. --- .../commands/generateckeditorthumbnails.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ckeditor/management/commands/generateckeditorthumbnails.py b/ckeditor/management/commands/generateckeditorthumbnails.py index ff83242..ebc7a20 100644 --- a/ckeditor/management/commands/generateckeditorthumbnails.py +++ b/ckeditor/management/commands/generateckeditorthumbnails.py @@ -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)