Django

Code

Changeset 3048

Show
Ignore:
Timestamp:
06/01/06 15:47:34 (3 years ago)
Author:
lukeplant
Message:

Fixed #2045 - TypeError? thrown if a form does not have the correct enctype for uploading
files. It throws a ValidationError? now, as it should.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/validators.py

    r3026 r3048  
    147147    from cStringIO import StringIO 
    148148    try: 
    149         Image.open(StringIO(field_data['content'])) 
     149        content = field_data['content'] 
     150    except TypeError: 
     151        raise ValidationError, gettext("No file was submitted. Check the encoding type on the form.") 
     152    try: 
     153        Image.open(StringIO(content)) 
    150154    except IOError: # Python Imaging Library doesn't recognize it as an image 
    151155        raise ValidationError, gettext("Upload a valid image. The file you uploaded was either not an image or a corrupted image.") 
     
    367371 
    368372    def __call__(self, field_data, all_data): 
    369         if self.min_size is not None and len(field_data['content']) < self.min_size: 
     373        try: 
     374            content = field_data['content'] 
     375        except TypeError: 
     376            raise ValidationError, gettext_lazy("No file was submitted. Check the encoding type on the form.") 
     377        if self.min_size is not None and len(content) < self.min_size: 
    370378            raise ValidationError, self.min_error_message 
    371         if self.max_size is not None and len(field_data['content']) > self.max_size: 
     379        if self.max_size is not None and len(content) > self.max_size: 
    372380            raise ValidationError, self.max_error_message 
    373381 
  • django/trunk/django/forms/__init__.py

    r3021 r3048  
    642642 
    643643    def isNonEmptyFile(self, field_data, all_data): 
    644         if not field_data['content']: 
     644        try: 
     645            content = field_data['content'] 
     646        except TypeError: 
     647            raise validators.CriticalValidationError, gettext("No file was submitted. Check the encoding type on the form.") 
     648        if not content: 
    645649            raise validators.CriticalValidationError, gettext("The submitted file is empty.") 
    646650