summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorHonza Král <honza.kral@gmail.com>2009-06-03 02:38:23 +0000
committerHonza Král <honza.kral@gmail.com>2009-06-03 02:38:23 +0000
commita9efb44c0159e0ea7a6f0040e2185d335c25f799 (patch)
tree352596e067a749e7aa866e06e9515187bc1743a8 /django
parent92934650f6cf428e7b7bf796db138c5a46370578 (diff)
[soc2009/model-validation] FileFields migrated
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@10908 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/forms/fields.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py
index 625c74235b..cf1daa0003 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -472,12 +472,9 @@ class FileField(Field):
self.max_length = kwargs.pop('max_length', None)
super(FileField, self).__init__(*args, **kwargs)
- def clean(self, data, initial=None):
- super(FileField, self).clean(initial or data)
- if not self.required and data in EMPTY_VALUES:
+ def to_python(self, data):
+ if data in EMPTY_VALUES:
return None
- elif not data and initial:
- return initial
# UploadedFile objects should have name and size attributes.
try:
@@ -496,21 +493,25 @@ class FileField(Field):
return data
+ def clean(self, data, initial=None):
+ if not data and initial:
+ return initial
+ return super(FileField, self).clean(data)
+
+
class ImageField(FileField):
default_error_messages = {
'invalid_image': _(u"Upload a valid image. The file you uploaded was either not an image or a corrupted image."),
}
- def clean(self, data, initial=None):
+ def to_python(self, data):
"""
Checks that the file-upload field data contains a valid image (GIF, JPG,
PNG, possibly others -- whatever the Python Imaging Library supports).
"""
- f = super(ImageField, self).clean(data, initial)
+ f = super(ImageField, self).to_python(data)
if f is None:
return None
- elif not data and initial:
- return initial
from PIL import Image
# We need to get a file object for PIL. We might have a path or we might