Fixed #11150 -- Removed dependency on cStringIO in ImageField validation. Thanks vvd for the report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17825 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Claude Paroz 2012-03-29 16:49:59 +00:00
parent 6cbb96ef5c
commit 159d1be656
2 changed files with 15 additions and 2 deletions

View File

@ -577,8 +577,8 @@ class ImageField(FileField):
# Since we're about to use the file again we have to reset the # Since we're about to use the file again we have to reset the
# file object if possible. # file object if possible.
if hasattr(file, 'reset'): if hasattr(file, 'seek') and callable(file.seek):
file.reset() file.seek(0)
# verify() is the only method that can spot a corrupt PNG, # verify() is the only method that can spot a corrupt PNG,
# but it must be called immediately after the constructor # but it must be called immediately after the constructor

View File

@ -1370,6 +1370,19 @@ class OldFormForXTests(TestCase):
self.assertEqual(instance.image.name, 'foo/test4.png') self.assertEqual(instance.image.name, 'foo/test4.png')
instance.delete() instance.delete()
# Test image field when cStringIO is not available
from django.forms import fields
from StringIO import StringIO
old_StringIO = fields.StringIO
fields.StringIO = StringIO
try:
f = ImageFileForm(
data={'description': u'An image'},
files={'image': SimpleUploadedFile('test.png', image_data)})
self.assertEqual(f.is_valid(), True)
finally:
fields.StringIO = old_StringIO
def test_media_on_modelform(self): def test_media_on_modelform(self):
# Similar to a regular Form class you can define custom media to be used on # Similar to a regular Form class you can define custom media to be used on
# the ModelForm. # the ModelForm.