summaryrefslogtreecommitdiff
path: root/ishtar_common/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-06-05 23:28:27 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-06-05 23:28:27 +0200
commit6e04566c15b214c15cda717862455248e8662ebf (patch)
tree4bfbe86ca07870bf4062a79dfee49d6f82189872 /ishtar_common/models.py
parentcd512c2f960743eddcddc268d991b931b9daee62 (diff)
downloadIshtar-6e04566c15b214c15cda717862455248e8662ebf.tar.bz2
Ishtar-6e04566c15b214c15cda717862455248e8662ebf.zip
Silent error when the associated image is not on the hard drive
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r--ishtar_common/models.py40
1 files changed, 21 insertions, 19 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 833dfbec9..d8948d3e3 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -552,25 +552,27 @@ class ImageModel(models.Model):
filename = os.path.splitext(os.path.split(self.image.name)[-1])[0]
old_path = self.image.path
filename = "%s.jpg" % filename
- image = Image.open(self.image.file)
-
- # convert to RGB
- if image.mode not in ('L', 'RGB'):
- image = image.convert('RGB')
-
- # resize if necessary
- self.image.save(filename,
- self.create_thumb(image, self.IMAGE_MAX_SIZE),
- save=False)
-
- if old_path != self.image.path:
- os.remove(old_path)
-
- # save the thumbnail
- self.thumbnail.save(
- '_%s' % filename,
- self.create_thumb(image, self.THUMB_MAX_SIZE),
- save=False)
+ try:
+ image = Image.open(self.image.file)
+ # convert to RGB
+ if image.mode not in ('L', 'RGB'):
+ image = image.convert('RGB')
+
+ # resize if necessary
+ self.image.save(filename,
+ self.create_thumb(image, self.IMAGE_MAX_SIZE),
+ save=False)
+
+ if old_path != self.image.path:
+ os.remove(old_path)
+
+ # save the thumbnail
+ self.thumbnail.save(
+ '_%s' % filename,
+ self.create_thumb(image, self.THUMB_MAX_SIZE),
+ save=False)
+ except IOError:
+ pass
super(ImageModel, self).save(*args, **kwargs)