Prevent thumbnails clones

To prevent the creation of multiple thumbnails clones "fileName.hash.ext"
This commit is contained in:
Igor Mella 2015-01-11 17:49:10 -03:00
parent 206682ce0a
commit d7db61b275

View file

@ -111,7 +111,11 @@ class Avatar(models.Model):
thumb_file = ContentFile(thumb.getvalue())
else:
thumb_file = File(orig)
thumb = self.avatar.storage.save(self.avatar_name(size), thumb_file)
storage = self.avatar.storage
thum_name = self.avatar_name(size)
if storage.exists(thum_name):
storage.delete(thum_name)
storage.save(thum_name, thumb_file)
except IOError:
return # What should we do here? Render a "sorry, didn't work" img?