def clean_file(self): data = self.cleaned_data.get('file') max_upload_size = get_max_file_upload_size(file_module=True) if data.size > max_upload_size: raise forms.ValidationError(_('Please keep filesize under %s. Current filesize %s') % (filesizeformat(max_upload_size), filesizeformat(data.size))) return data
def clean_photo_upload(self): photo_upload = self.cleaned_data['photo_upload'] if photo_upload: extension = splitext(photo_upload.name)[1] # check the extension if extension.lower() not in ALLOWED_LOGO_EXT: raise forms.ValidationError( _('The photo must be of jpg, gif, or png image type.')) # check the image header image_type = '.%s' % imghdr.what('', photo_upload.read()) if image_type not in ALLOWED_LOGO_EXT: raise forms.ValidationError( _('The photo is an invalid image. Try uploading another photo.' )) max_upload_size = get_max_file_upload_size() if photo_upload.size > max_upload_size: raise forms.ValidationError( _('Please keep filesize under %(max_upload_size)s. Current filesize %(upload_size)s' ) % { 'max_upload_size': filesizeformat(max_upload_size), 'upload_size': filesizeformat(photo_upload.size) }) return photo_upload
def clean_logo(self): logo = self.cleaned_data['logo'] if logo: extension = splitext(logo.name)[1] # check the extension if extension.lower() not in ALLOWED_LOGO_EXT: raise forms.ValidationError( 'The logo must be of jpg, gif, or png image type.') # check the image header image_type = '.%s' % imghdr.what('', logo.read()) if image_type not in ALLOWED_LOGO_EXT: raise forms.ValidationError( 'The logo is an invalid image. Try uploading another logo.' ) max_upload_size = get_max_file_upload_size() if logo.size > max_upload_size: raise forms.ValidationError( _('Please keep filesize under %s. Current filesize %s') % (filesizeformat(max_upload_size), filesizeformat( logo.size))) return logo
def clean_file(self): data = self.cleaned_data['file'] max_upload_size = get_max_file_upload_size(file_module=True) if data.size > max_upload_size: raise forms.ValidationError(_('Please keep filesize under %s. Current filesize %s') % (filesizeformat(max_upload_size), filesizeformat(data.size))) return data
def clean_header_image(self): header_image = self.cleaned_data['header_image'] if header_image: extension = splitext(header_image.name)[1] # check the extension if extension.lower() not in ALLOWED_IMG_EXT: raise forms.ValidationError( _('The header image must be of jpg, gif, or png image type.' )) # check the image header_image image_type = '.%s' % imghdr.what('', header_image.read()) if image_type not in ALLOWED_IMG_EXT: raise forms.ValidationError( _('The header image is an invalid image. Try uploading another image.' )) max_upload_size = get_max_file_upload_size() if header_image.size > max_upload_size: raise forms.ValidationError( _('Please keep filesize under %(max_upload_size)s. Current filesize %(header_image)s' ) % { 'max_upload_size': filesizeformat(max_upload_size), 'header_image': filesizeformat(header_image.size) }) return header_image
def clean_files(self): files = self.cleaned_data.get('files') max_upload_size = get_max_file_upload_size(file_module=True) for data in files: if data.size > max_upload_size: raise forms.ValidationError(_('Please keep filesize under %(max_upload_size)s. Current filesize %(data_size)s') % { 'max_upload_size': filesizeformat(max_upload_size), 'data_size': filesizeformat(data.size)}) return files
def clean_files(self): files = self.cleaned_data.get('files') max_upload_size = get_max_file_upload_size(file_module=True) for data in files: if data.size > max_upload_size: raise forms.ValidationError( _('Please keep filesize under %s. Current filesize %s') % (filesizeformat(max_upload_size), filesizeformat( data.size))) return files
def clean_header_image(self): header_image = self.cleaned_data['header_image'] if header_image: extension = splitext(header_image.name)[1] # check the extension if extension.lower() not in ALLOWED_IMG_EXT: raise forms.ValidationError('The header image must be of jpg, gif, or png image type.') # check the image header_image image_type = '.%s' % imghdr.what('', header_image.read()) if image_type not in ALLOWED_IMG_EXT: raise forms.ValidationError('The header image is an invalid image. Try uploading another image.') max_upload_size = get_max_file_upload_size() if header_image.size > max_upload_size: raise forms.ValidationError(_('Please keep filesize under %s. Current filesize %s') % (filesizeformat(max_upload_size), filesizeformat(header_image.size))) return header_image
def clean_photo_upload(self): photo_upload = self.cleaned_data['photo_upload'] if photo_upload: extension = splitext(photo_upload.name)[1] # check the extension if extension.lower() not in ALLOWED_LOGO_EXT: raise forms.ValidationError('The logo must be of jpg, gif, or png image type.') # check the image header image_type = '.%s' % imghdr.what('', photo_upload.read()) if image_type not in ALLOWED_LOGO_EXT: raise forms.ValidationError('The logo is an invalid image. Try uploading another logo.') max_upload_size = get_max_file_upload_size() if photo_upload.size > max_upload_size: raise forms.ValidationError(_('Please keep filesize under %s. Current filesize %s') % (filesizeformat(max_upload_size), filesizeformat(photo_upload.size))) return photo_upload
def clean_logo(self): logo = self.cleaned_data['logo'] if logo: try: extension = splitext(logo.name)[1] # check the extension if extension.lower() not in ALLOWED_LOGO_EXT: raise forms.ValidationError('The logo must be of jpg, gif, or png image type.') # check the image header image_type = '.%s' % imghdr.what('', logo.read()) if image_type not in ALLOWED_LOGO_EXT: raise forms.ValidationError('The logo is an invalid image. Try uploading another logo.') max_upload_size = get_max_file_upload_size() if logo.size > max_upload_size: raise forms.ValidationError(_('Please keep filesize under %(max_upload_size)s. Current filesize %(logo_size)s') % { 'max_upload_size': filesizeformat(max_upload_size), 'logo_size': filesizeformat(logo.size)}) except IOError: logo = None return logo