diff options
Diffstat (limited to 'django/forms')
| -rw-r--r-- | django/forms/fields.py | 3 | ||||
| -rw-r--r-- | django/forms/util.py | 13 |
2 files changed, 10 insertions, 6 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py index 11b7f44029..e708ef846e 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -8,6 +8,7 @@ import copy import datetime import os import re +import sys try: from urllib.parse import urlsplit, urlunsplit except ImportError: # Python 2 @@ -619,7 +620,7 @@ class ImageField(FileField): # 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']) + six.reraise(ValidationError, ValidationError(self.error_messages['invalid_image']), sys.exc_info()[2]) if hasattr(f, 'seek') and callable(f.seek): f.seek(0) return f diff --git a/django/forms/util.py b/django/forms/util.py index 724f256e40..f1b864e6b3 100644 --- a/django/forms/util.py +++ b/django/forms/util.py @@ -6,6 +6,8 @@ from django.utils.encoding import force_text, python_2_unicode_compatible from django.utils.safestring import mark_safe from django.utils import timezone from django.utils.translation import ugettext_lazy as _ +from django.utils import six +import sys # Import ValidationError so that it can be imported from this # module to maintain backwards compatibility. @@ -78,11 +80,12 @@ def from_current_timezone(value): try: return timezone.make_aware(value, current_timezone) except Exception: - raise ValidationError(_('%(datetime)s couldn\'t be interpreted ' - 'in time zone %(current_timezone)s; it ' - 'may be ambiguous or it may not exist.') - % {'datetime': value, - 'current_timezone': current_timezone}) + msg = _( + '%(datetime)s couldn\'t be interpreted ' + 'in time zone %(current_timezone)s; it ' + 'may be ambiguous or it may not exist.') % {'datetime': value, 'current_timezone': + current_timezone} + six.reraise(ValidationError, ValidationError(msg), sys.exc_info()[2]) return value def to_current_timezone(value): |
