ImageFields now include PIL error messages if invalid error (#353)
This commit is contained in:
parent
a246154961
commit
e5648a4af9
@ -5,6 +5,7 @@ Changelog
|
||||
|
||||
Changes in 0.8.2
|
||||
================
|
||||
- ImageFields now include PIL error messages if invalid error (#353)
|
||||
- Fixed hashing of EmbeddedDocuments (#348)
|
||||
- Added lock when calling doc.Delete() for when signals have no sender (#350)
|
||||
- Reload forces read preference to be PRIMARY (#355)
|
||||
|
@ -1259,8 +1259,8 @@ class ImageGridFsProxy(GridFSProxy):
|
||||
try:
|
||||
img = Image.open(file_obj)
|
||||
img_format = img.format
|
||||
except:
|
||||
raise ValidationError('Invalid image')
|
||||
except Exception, e:
|
||||
raise ValidationError('Invalid image: %s' % e)
|
||||
|
||||
if (field.size and (img.size[0] > field.size['width'] or
|
||||
img.size[1] > field.size['height'])):
|
||||
|
@ -269,6 +269,17 @@ class FileTest(unittest.TestCase):
|
||||
|
||||
TestImage.drop_collection()
|
||||
|
||||
with tempfile.TemporaryFile() as f:
|
||||
f.write(b("Hello World!"))
|
||||
f.flush()
|
||||
|
||||
t = TestImage()
|
||||
try:
|
||||
t.image.put(f)
|
||||
self.fail("Should have raised an invalidation error")
|
||||
except ValidationError, e:
|
||||
self.assertEquals("%s" % e, "Invalid image: cannot identify image file")
|
||||
|
||||
t = TestImage()
|
||||
t.image.put(open(TEST_IMAGE_PATH, 'rb'))
|
||||
t.save()
|
||||
|
Loading…
x
Reference in New Issue
Block a user