Django

Code

Show
Ignore:
Timestamp:
07/01/08 10:10:51 (2 months ago)
Author:
jacob
Message:

Fixed #2070: refactored Django's file upload capabilities.

A description of the new features can be found in the new upload handling documentation; the executive summary is that Django will now happily handle uploads of large files without issues.

This changes the representation of uploaded files from dictionaries to bona fide objects; see BackwardsIncompatibleChanges for details.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/tests/regressiontests/forms/error_messages.py

    r7776 r7814  
    22tests = r""" 
    33>>> from django.newforms import * 
     4>>> from django.core.files.uploadedfile import SimpleUploadedFile 
    45 
    56# CharField ################################################################### 
     
    215216... 
    216217ValidationError: [u'INVALID'] 
    217 >>> f.clean({}
    218 Traceback (most recent call last): 
    219 ... 
    220 ValidationError: [u'MISSING'] 
    221 >>> f.clean({'filename': 'name', 'content':''}
     218>>> f.clean(SimpleUploadedFile('name', None)
     219Traceback (most recent call last): 
     220... 
     221ValidationError: [u'EMPTY FILE'] 
     222>>> f.clean(SimpleUploadedFile('name', '')
    222223Traceback (most recent call last): 
    223224... 
  • django/trunk/tests/regressiontests/forms/fields.py

    r7799 r7814  
    33>>> from django.newforms import * 
    44>>> from django.newforms.widgets import RadioFieldRenderer 
     5>>> from django.core.files.uploadedfile import SimpleUploadedFile 
    56>>> import datetime 
    67>>> import time 
     
    772773'files/test2.pdf' 
    773774 
    774 >>> f.clean({}
    775 Traceback (most recent call last): 
    776 ... 
    777 ValidationError: [u'No file was submitted.'] 
    778  
    779 >>> f.clean({}, '') 
    780 Traceback (most recent call last): 
    781 ... 
    782 ValidationError: [u'No file was submitted.'] 
    783  
    784 >>> f.clean({}, 'files/test3.pdf') 
     775>>> f.clean(SimpleUploadedFile('', '')
     776Traceback (most recent call last): 
     777... 
     778ValidationError: [u'No file was submitted. Check the encoding type on the form.'] 
     779 
     780>>> f.clean(SimpleUploadedFile('', ''), '') 
     781Traceback (most recent call last): 
     782... 
     783ValidationError: [u'No file was submitted. Check the encoding type on the form.'] 
     784 
     785>>> f.clean(None, 'files/test3.pdf') 
    785786'files/test3.pdf' 
    786787 
     
    790791ValidationError: [u'No file was submitted. Check the encoding type on the form.'] 
    791792 
    792 >>> f.clean({'filename': 'name', 'content': None}
     793>>> f.clean(SimpleUploadedFile('name', None)
    793794Traceback (most recent call last): 
    794795... 
    795796ValidationError: [u'The submitted file is empty.'] 
    796797 
    797 >>> f.clean({'filename': 'name', 'content': ''}
     798>>> f.clean(SimpleUploadedFile('name', '')
    798799Traceback (most recent call last): 
    799800... 
    800801ValidationError: [u'The submitted file is empty.'] 
    801802 
    802 >>> type(f.clean({'filename': 'name', 'content': 'Some File Content'})) 
     803>>> type(f.clean(SimpleUploadedFile('name', 'Some File Content'))) 
    803804<class 'django.newforms.fields.UploadedFile'> 
    804805 
    805 >>> type(f.clean({'filename': 'name', 'content': 'Some File Content'}, 'files/test4.pdf')) 
     806>>> type(f.clean(SimpleUploadedFile('name', 'Some File Content'), 'files/test4.pdf')) 
    806807<class 'django.newforms.fields.UploadedFile'> 
    807808 
  • django/trunk/tests/regressiontests/forms/forms.py

    r7693 r7814  
    22tests = r""" 
    33>>> from django.newforms import * 
     4>>> from django.core.files.uploadedfile import SimpleUploadedFile 
    45>>> import datetime 
    56>>> import time 
     
    14661467<tr><th>File1:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="file" name="file1" /></td></tr> 
    14671468 
    1468 >>> f = FileForm(data={}, files={'file1': {'filename': 'name', 'content':''}}, auto_id=False) 
     1469>>> f = FileForm(data={}, files={'file1': SimpleUploadedFile('name', '')}, auto_id=False) 
    14691470>>> print f 
    14701471<tr><th>File1:</th><td><ul class="errorlist"><li>The submitted file is empty.</li></ul><input type="file" name="file1" /></td></tr> 
     
    14741475<tr><th>File1:</th><td><ul class="errorlist"><li>No file was submitted. Check the encoding type on the form.</li></ul><input type="file" name="file1" /></td></tr> 
    14751476 
    1476 >>> f = FileForm(data={}, files={'file1': {'filename': 'name', 'content':'some content'}}, auto_id=False) 
     1477>>> f = FileForm(data={}, files={'file1': SimpleUploadedFile('name', 'some content')}, auto_id=False) 
    14771478>>> print f 
    14781479<tr><th>File1:</th><td><input type="file" name="file1" /></td></tr>