Ticket #11150: 11150-2.diff

File 11150-2.diff, 1.6 KB (added by Claude Paroz, 13 years ago)

Patch including test

  • django/forms/fields.py

    diff --git a/django/forms/fields.py b/django/forms/fields.py
    index 96ecabf..1fa8d57 100644
    a b class ImageField(FileField):  
    577577
    578578            # Since we're about to use the file again we have to reset the
    579579            # 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)
    582582
    583583            # verify() is the only method that can spot a corrupt PNG,
    584584            #  but it must be called immediately after the constructor
  • tests/modeltests/model_forms/tests.py

    diff --git a/tests/modeltests/model_forms/tests.py b/tests/modeltests/model_forms/tests.py
    index a2ad024..ff5048e 100644
    a b class OldFormForXTests(TestCase):  
    13701370        self.assertEqual(instance.image.name, 'foo/test4.png')
    13711371        instance.delete()
    13721372
     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
    13731386    def test_media_on_modelform(self):
    13741387        # Similar to a regular Form class you can define custom media to be used on
    13751388        # the ModelForm.
Back to Top