From aa239e3e5405933af6a29dac3cf587b59a099927 Mon Sep 17 00:00:00 2001 From: Justin Bronn Date: Tue, 5 Aug 2008 17:15:33 +0000 Subject: gis: Merged revisions 7981-8001,8003-8011,8013-8033,8035-8036,8038-8039,8041-8063,8065-8076,8078-8139,8141-8154,8156-8214 via svnmerge from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@8215 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/forms/fields.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'django/forms/fields.py') diff --git a/django/forms/fields.py b/django/forms/fields.py index 9df8955392..47ae5e11b2 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -7,6 +7,7 @@ import datetime import os import re import time +import urlparse try: from cStringIO import StringIO except ImportError: @@ -23,7 +24,7 @@ except NameError: from sets import Set as set from django.utils.translation import ugettext_lazy as _ -from django.utils.encoding import StrAndUnicode, smart_unicode, smart_str +from django.utils.encoding import smart_unicode, smart_str from util import ErrorList, ValidationError from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, FileInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple, DateTimeInput @@ -73,7 +74,10 @@ class Field(object): if label is not None: label = smart_unicode(label) self.required, self.label, self.initial = required, label, initial - self.help_text = smart_unicode(help_text or '') + if help_text is None: + self.help_text = u'' + else: + self.help_text = smart_unicode(help_text) widget = widget or self.widget if isinstance(widget, type): widget = widget() @@ -503,6 +507,11 @@ class ImageField(FileField): # but it must be called immediately after the constructor trial_image = Image.open(file) trial_image.verify() + except ImportError: + # Under PyPy, it is possible to import PIL. However, the underlying + # _imaging C module isn't available, so an ImportError will be + # raised. Catch and re-raise. + raise except Exception: # Python Imaging Library doesn't recognize it as an image raise ValidationError(self.error_messages['invalid_image']) if hasattr(f, 'seek') and callable(f.seek): @@ -534,6 +543,9 @@ class URLField(RegexField): # If no URL scheme given, assume http:// if value and '://' not in value: value = u'http://%s' % value + # If no URL path given, assume / + if value and not urlparse.urlsplit(value)[2]: + value += '/' value = super(URLField, self).clean(value) if value == u'': return value -- cgit v1.2.1