summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2010-02-14 18:33:01 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2010-02-14 18:33:01 +0000
commita9879b14387f4ee8439b4fc53ef55602b6a48db2 (patch)
treed9dcfc91375b2a96b31c61583b3fd7faa2955270 /django
parent166405b2e4197fba7d5638ee732f2170f8647f62 (diff)
[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
Diffstat (limited to 'django')
-rw-r--r--django/core/files/images.py7
-rw-r--r--django/core/management/validation.py6
-rw-r--r--django/forms/fields.py7
3 files changed, 17 insertions, 3 deletions
diff --git a/django/core/files/images.py b/django/core/files/images.py
index 24c1151e8d..55008b548a 100644
--- a/django/core/files/images.py
+++ b/django/core/files/images.py
@@ -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."""
- from PIL import ImageFile as PILImageFile
+ # 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'):
diff --git a/django/core/management/validation.py b/django/core/management/validation.py
index b971558ac7..bbea35b5ce 100644
--- a/django/core/management/validation.py
+++ b/django/core/management/validation.py
@@ -47,10 +47,14 @@ 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:
- 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)
+ 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):
e.add(opts, '"%s": BooleanFields do not accept null values. Use a NullBooleanField instead.' % f.name)
if f.choices:
diff --git a/django/forms/fields.py b/django/forms/fields.py
index c0ee2f0955..12316a1ab1 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -483,7 +483,12 @@ class ImageField(FileField):
return None
elif not data and initial:
return initial
- from PIL import Image
+
+ # 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.