Commit a9879b14 authored by Jacob Kaplan-Moss's avatar Jacob Kaplan-Moss
Browse files

[1.1.X] Fixed #6054: work around PIL's installation brokeness by detecting...

[1.1.X] Fixed #6054: work around PIL's installation brokeness by detecting either of the two ways it can end up being installed.

Backport of [12429] from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12430 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 166405b2
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -30,7 +30,12 @@ class ImageFile(File):

def get_image_dimensions(file_or_path):
    """Returns the (width, height) of an image, given an open file or a path."""
    # Try to import PIL in either of the two ways it can end up installed.
    try:
        from PIL import ImageFile as PILImageFile
    except ImportError:
        import ImageFile as PILImageFile
        
    p = PILImageFile.Parser()
    close = False
    if hasattr(file_or_path, 'read'):
+5 −1
Original line number Diff line number Diff line
@@ -47,8 +47,12 @@ def get_validation_errors(outfile, app=None):
            if isinstance(f, models.FileField) and not f.upload_to:
                e.add(opts, '"%s": FileFields require an "upload_to" attribute.' % f.name)
            if isinstance(f, models.ImageField):
                # Try to import PIL in either of the two ways it can end up installed.
                try:
                    from PIL import Image
                except ImportError:
                    try:
                        import Image
                    except ImportError:
                        e.add(opts, '"%s": To use ImageFields, you need to install the Python Imaging Library. Get it at http://www.pythonware.com/products/pil/ .' % f.name)
            if isinstance(f, models.BooleanField) and getattr(f, 'null', False):
+6 −1
Original line number Diff line number Diff line
@@ -483,7 +483,12 @@ class ImageField(FileField):
            return None
        elif not data and initial:
            return initial
            
        # Try to import PIL in either of the two ways it can end up installed.
        try:
            from PIL import Image
        except ImportError:
            import Image

        # We need to get a file object for PIL. We might have a path or we might
        # have to read the data into memory.
+9 −5
Original line number Diff line number Diff line
@@ -99,11 +99,15 @@ class TextFile(models.Model):
        return self.description

try:
    # If PIL is available, try testing ImageFields.
    # Checking for the existence of Image is enough for CPython, but
    # for PyPy, you need to check for the underlying modules
    # If PIL is not available, ImageField tests are omitted.
    # If PIL is available, try testing ImageFields. Checking for the existence
    # of Image is enough for CPython, but for PyPy, you need to check for the
    # underlying modules If PIL is not available, ImageField tests are omitted.
    # Try to import PIL in either of the two ways it can end up installed.
    try:
        from PIL import Image, _imaging
    except ImportError:
        import Image, _imaging
    
    test_images = True

    class ImageFile(models.Model):
+7 −3
Original line number Diff line number Diff line
@@ -18,10 +18,14 @@ try:
except ImportError:
    import dummy_threading as threading

try:
# Try to import PIL in either of the two ways it can end up installed.
# Checking for the existence of Image is enough for CPython, but
# for PyPy, you need to check for the underlying modules
try:
    from PIL import Image, _imaging
except ImportError:
    try:
        import Image, _imaging
    except ImportError:
        Image = None

Loading