def isValidImage(field_data, all_data):
 from PIL import Image
 from cStringIO import StringIO
 try:
  content = field_data['content']
 except TypeError:
  raise ValidationError, gettext('No file was submitted. Check the encoding type on the form.')
 try:
  Image.open(StringIO(content))
 except IOError:
  raise ValidationError, gettext('Upload a valid image. The file you uploaded was either not an image or a corrupted image.')

def isValidImage ( field_data , all_data ) : from PIL import Image from cStringIO import StringIO try : content = field_data [ 'content' ] except TypeError : raise ValidationError , gettext ( 'No file was submitted. Check the encoding type on the form.' ) try : Image . open ( StringIO ( content ) ) except IOError : raise ValidationError , gettext ( 'Upload a valid image. The file you uploaded was either not an image or a corrupted image.' )
checks that the file-upload field data contains a valid image .