kopia lustrzana https://github.com/wagtail/wagtail
				
				
				
			Remove pre-Django 1.8 code from check_image_file_format
							rodzic
							
								
									98f600c514
								
							
						
					
					
						commit
						6882a1fb42
					
				| 
						 | 
				
			
			@ -7,7 +7,6 @@ from django.core.exceptions import ValidationError
 | 
			
		|||
from django.forms.fields import ImageField
 | 
			
		||||
from django.template.defaultfilters import filesizeformat
 | 
			
		||||
from django.utils.translation import ugettext_lazy as _
 | 
			
		||||
from PIL import Image
 | 
			
		||||
 | 
			
		||||
ALLOWED_EXTENSIONS = ['gif', 'jpg', 'jpeg', 'png']
 | 
			
		||||
SUPPORTED_FORMATS_TEXT = _("GIF, JPEG, PNG")
 | 
			
		||||
| 
						 | 
				
			
			@ -60,31 +59,11 @@ class WagtailImageField(ImageField):
 | 
			
		|||
        if extension not in ALLOWED_EXTENSIONS:
 | 
			
		||||
            raise ValidationError(self.error_messages['invalid_image'], code='invalid_image')
 | 
			
		||||
 | 
			
		||||
        if hasattr(f, 'image'):
 | 
			
		||||
            # Django 1.8 annotates the file object with the PIL image
 | 
			
		||||
            image = f.image
 | 
			
		||||
        elif not f.closed:
 | 
			
		||||
            # Open image file
 | 
			
		||||
            file_position = f.tell()
 | 
			
		||||
            f.seek(0)
 | 
			
		||||
 | 
			
		||||
            try:
 | 
			
		||||
                image = Image.open(f)
 | 
			
		||||
            except IOError:
 | 
			
		||||
                # Uploaded file is not even an image file (or corrupted)
 | 
			
		||||
                raise ValidationError(self.error_messages['invalid_image_known_format'],
 | 
			
		||||
                                      code='invalid_image_known_format')
 | 
			
		||||
 | 
			
		||||
            f.seek(file_position)
 | 
			
		||||
        else:
 | 
			
		||||
            # Couldn't get the PIL image, skip checking the internal file format
 | 
			
		||||
            return
 | 
			
		||||
 | 
			
		||||
        image_format = extension.upper()
 | 
			
		||||
        if image_format == 'JPG':
 | 
			
		||||
            image_format = 'JPEG'
 | 
			
		||||
 | 
			
		||||
        internal_image_format = image.format.upper()
 | 
			
		||||
        internal_image_format = f.image.format.upper()
 | 
			
		||||
        if internal_image_format == 'MPO':
 | 
			
		||||
            internal_image_format = 'JPEG'
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue