diff options
| author | Jacob Kaplan-Moss <jacob@jacobian.org> | 2008-07-07 23:16:00 +0000 |
|---|---|---|
| committer | Jacob Kaplan-Moss <jacob@jacobian.org> | 2008-07-07 23:16:00 +0000 |
| commit | a28b75b0ba9650ae3bd46e38d12d95d48f5c5664 (patch) | |
| tree | 60084232ace3608e32c9f15987263795f0592265 /django/newforms/fields.py | |
| parent | 9dabd1f8ff7760f28bd1dcfa8b83ae6b1c0b79aa (diff) | |
Fixed #7614: the quickening has come, and there now is only one UploadedFile. On top of that, UploadedFile's interface has been improved:
* The API now more closely matches a proper file API. This unfortunately means a few backwards-incompatible renamings; see BackwardsIncompatibleChanges. This refs #7593.
* While we were at it, renamed chunk() to chunks() to clarify that it's an iterator.
* Temporary uploaded files now property use the tempfile library behind the scenes which should ensure better cleanup of tempfiles (refs #7593 again).
Thanks to Mike Axiak for the bulk of this patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7859 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/newforms/fields.py')
| -rw-r--r-- | django/newforms/fields.py | 27 |
1 files changed, 6 insertions, 21 deletions
diff --git a/django/newforms/fields.py b/django/newforms/fields.py index 1feef31ee0..ad46d78859 100644 --- a/django/newforms/fields.py +++ b/django/newforms/fields.py @@ -27,7 +27,7 @@ from django.utils.encoding import StrAndUnicode, smart_unicode, smart_str from util import ErrorList, ValidationError from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, FileInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple, DateTimeInput - +from django.core.files.uploadedfile import SimpleUploadedFile as UploadedFile __all__ = ( 'Field', 'CharField', 'IntegerField', @@ -419,18 +419,6 @@ except ImportError: # It's OK if Django settings aren't configured. URL_VALIDATOR_USER_AGENT = 'Django (http://www.djangoproject.com/)' -class UploadedFile(StrAndUnicode): - "A wrapper for files uploaded in a FileField" - def __init__(self, filename, data): - self.filename = filename - self.data = data - - def __unicode__(self): - """ - The unicode representation is the filename, so that the pre-database-insertion - logic can use UploadedFile objects - """ - return self.filename class FileField(Field): widget = FileInput @@ -460,23 +448,20 @@ class FileField(Field): category = DeprecationWarning, stacklevel = 2 ) + data = UploadedFile(data['filename'], data['content']) try: - file_name = data.file_name - file_size = data.file_size + file_name = data.name + file_size = data.size except AttributeError: - try: - file_name = data.get('filename') - file_size = bool(data['content']) - except (AttributeError, KeyError): - raise ValidationError(self.error_messages['invalid']) + raise ValidationError(self.error_messages['invalid']) if not file_name: raise ValidationError(self.error_messages['invalid']) if not file_size: raise ValidationError(self.error_messages['empty']) - return UploadedFile(file_name, data) + return data class ImageField(FileField): default_error_messages = { |
