Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #11150 -- Removed dependency on cStringIO in ImageField validat…

…ion. Thanks vvd for the report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17825 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 159d1be6567a3696468b77c64169f4f5a5429c14 1 parent 6cbb96e
@claudep claudep authored
Showing with 15 additions and 2 deletions.
  1. +2 −2 django/forms/fields.py
  2. +13 −0 tests/modeltests/model_forms/tests.py
View
4 django/forms/fields.py
@@ -577,8 +577,8 @@ def to_python(self, data):
# Since we're about to use the file again we have to reset the
# file object if possible.
- if hasattr(file, 'reset'):
- file.reset()
+ if hasattr(file, 'seek') and callable(file.seek):
+ file.seek(0)
# verify() is the only method that can spot a corrupt PNG,
# but it must be called immediately after the constructor
View
13 tests/modeltests/model_forms/tests.py
@@ -1370,6 +1370,19 @@ def test_image_field(self):
self.assertEqual(instance.image.name, 'foo/test4.png')
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):
# Similar to a regular Form class you can define custom media to be used on
# the ModelForm.
Please sign in to comment.
Something went wrong with that request. Please try again.