diff options
| author | Justin Bronn <jbronn@gmail.com> | 2008-01-28 15:35:46 +0000 |
|---|---|---|
| committer | Justin Bronn <jbronn@gmail.com> | 2008-01-28 15:35:46 +0000 |
| commit | 00292ad02ebf9ff1cb09d586c2452b3a716fd601 (patch) | |
| tree | 2ffd3546659f49b2eed2626ab5cfdf508ba69fbf /django/newforms/fields.py | |
| parent | 398eca3fb2ac84304b179fabd2f0960228c59b09 (diff) | |
gis: Merged revisions 6990-7043 via svnmerge from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@7044 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/newforms/fields.py')
| -rw-r--r-- | django/newforms/fields.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/django/newforms/fields.py b/django/newforms/fields.py index 3b8f4195b0..bc3e543037 100644 --- a/django/newforms/fields.py +++ b/django/newforms/fields.py @@ -437,10 +437,12 @@ class FileField(Field): def __init__(self, *args, **kwargs): super(FileField, self).__init__(*args, **kwargs) - def clean(self, data): - super(FileField, self).clean(data) + def clean(self, data, initial=None): + super(FileField, self).clean(initial or data) if not self.required and data in EMPTY_VALUES: return None + elif not data and initial: + return initial try: f = UploadedFile(data['filename'], data['content']) except TypeError: @@ -456,14 +458,16 @@ class ImageField(FileField): 'invalid_image': _(u"Upload a valid image. The file you uploaded was either not an image or a corrupted image."), } - def clean(self, data): + def clean(self, data, initial=None): """ 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) + f = super(ImageField, self).clean(data, initial) if f is None: return None + elif not data and initial: + return initial from PIL import Image from cStringIO import StringIO try: |
