Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Claude Paroz authored March 29, 2012
4  django/forms/fields.py
@@ -577,8 +577,8 @@ def to_python(self, data):
577 577
 
578 578
             # Since we're about to use the file again we have to reset the
579 579
             # file object if possible.
580  
-            if hasattr(file, 'reset'):
581  
-                file.reset()
  580
+            if hasattr(file, 'seek') and callable(file.seek):
  581
+                file.seek(0)
582 582
 
583 583
             # verify() is the only method that can spot a corrupt PNG,
584 584
             #  but it must be called immediately after the constructor
13  tests/modeltests/model_forms/tests.py
@@ -1370,6 +1370,19 @@ def test_image_field(self):
1370 1370
         self.assertEqual(instance.image.name, 'foo/test4.png')
1371 1371
         instance.delete()
1372 1372
 
  1373
+        # Test image field when cStringIO is not available
  1374
+        from django.forms import fields
  1375
+        from StringIO import StringIO
  1376
+        old_StringIO = fields.StringIO
  1377
+        fields.StringIO = StringIO
  1378
+        try:
  1379
+            f = ImageFileForm(
  1380
+                data={'description': u'An image'},
  1381
+                files={'image': SimpleUploadedFile('test.png', image_data)})
  1382
+            self.assertEqual(f.is_valid(), True)
  1383
+        finally:
  1384
+            fields.StringIO = old_StringIO
  1385
+
1373 1386
     def test_media_on_modelform(self):
1374 1387
         # Similar to a regular Form class you can define custom media to be used on
1375 1388
         # the ModelForm.

0 notes on commit 159d1be

Please sign in to comment.
Something went wrong with that request. Please try again.