diff --git a/mezzanine/core/templatetags/mezzanine_tags.py b/mezzanine/core/templatetags/mezzanine_tags.py index 51ae257a6e..238a67ddd5 100644 --- a/mezzanine/core/templatetags/mezzanine_tags.py +++ b/mezzanine/core/templatetags/mezzanine_tags.py @@ -119,10 +119,19 @@ def thumbnail(image_url, width, height): thumb_url = "%s/%s/%s" % (os.path.dirname(image_url), settings.THUMBNAILS_DIR_NAME, thumb_name) - # Abort if thumbnail exists or original image doesn't exist. - if os.path.exists(thumb_path): + try: + thumb_exists = os.path.exists(thumb_path) + except UnicodeEncodeError: + # The image that was saved to a filesystem with utf-8 support, + # but somehow the locale has changed and the filesystem does not + # support utf-8. + from mezzanine.core.exceptions import FileSystemEncodingChanged + raise FileSystemEncodingChanged() + if thumb_exists: + # Thumbnail exists, don't generate it. return thumb_url elif not default_storage.exists(image_url): + # Requested image does not exist, just return its URL. return image_url image = Image.open(default_storage.open(image_url)) diff --git a/mezzanine/galleries/models.py b/mezzanine/galleries/models.py index d5da18f617..b754718434 100644 --- a/mezzanine/galleries/models.py +++ b/mezzanine/galleries/models.py @@ -59,9 +59,19 @@ def save(self, delete_zip_import=True, *args, **kwargs): image.verify() except: continue - path = default_storage.save(os.path.join(GALLERIES_UPLOAD_DIR, - self.slug, name.decode("utf-8")), ContentFile(data)) - self.images.add(GalleryImage(file=path)) + path = os.path.join(GALLERIES_UPLOAD_DIR, self.slug, + name.decode("utf-8")) + try: + saved_path = default_storage.save(path, ContentFile(data)) + except UnicodeEncodeError: + from warnings import warn + warn("Your filesystem encoding doesn't seem to support " + "utf-8. You may need to set LC_CTYPE to a correct " + "value via your terminal, eg: en_US.utf8") + path = os.path.join(GALLERIES_UPLOAD_DIR, self.slug, + unicode(name, errors="ignore")) + saved_path = default_storage.save(path, ContentFile(data)) + self.images.add(GalleryImage(file=saved_path)) if delete_zip_import: zip_file.close() self.zip_import.delete(save=True)