mirror of
https://github.com/django/django.git
synced 2025-10-25 06:36:07 +00:00
Fixed #18013 -- Use the new 'as' syntax for exceptions.
Thanks Clueless for the initial patch. Note that unittest has been purposely left out (external package only used by Python 2.6).
This commit is contained in:
@@ -132,7 +132,7 @@ class Field(object):
|
||||
for v in self.validators:
|
||||
try:
|
||||
v(value)
|
||||
except ValidationError, e:
|
||||
except ValidationError as e:
|
||||
if hasattr(e, 'code') and e.code in self.error_messages:
|
||||
message = self.error_messages[e.code]
|
||||
if e.params:
|
||||
@@ -884,7 +884,7 @@ class MultiValueField(Field):
|
||||
raise ValidationError(self.error_messages['required'])
|
||||
try:
|
||||
clean_data.append(field.clean(field_value))
|
||||
except ValidationError, e:
|
||||
except ValidationError as e:
|
||||
# Collect all validation errors in a single list, which we'll
|
||||
# raise at the end of clean(), rather than raising a single
|
||||
# exception for the first error we encounter.
|
||||
|
||||
@@ -289,7 +289,7 @@ class BaseForm(StrAndUnicode):
|
||||
if hasattr(self, 'clean_%s' % name):
|
||||
value = getattr(self, 'clean_%s' % name)()
|
||||
self.cleaned_data[name] = value
|
||||
except ValidationError, e:
|
||||
except ValidationError as e:
|
||||
self._errors[name] = self.error_class(e.messages)
|
||||
if name in self.cleaned_data:
|
||||
del self.cleaned_data[name]
|
||||
@@ -297,7 +297,7 @@ class BaseForm(StrAndUnicode):
|
||||
def _clean_form(self):
|
||||
try:
|
||||
self.cleaned_data = self.clean()
|
||||
except ValidationError, e:
|
||||
except ValidationError as e:
|
||||
self._errors[NON_FIELD_ERRORS] = self.error_class(e.messages)
|
||||
|
||||
def _post_clean(self):
|
||||
|
||||
@@ -291,7 +291,7 @@ class BaseFormSet(StrAndUnicode):
|
||||
# Give self.clean() a chance to do cross-form validation.
|
||||
try:
|
||||
self.clean()
|
||||
except ValidationError, e:
|
||||
except ValidationError as e:
|
||||
self._non_form_errors = self.error_class(e.messages)
|
||||
|
||||
def clean(self):
|
||||
|
||||
@@ -324,13 +324,13 @@ class BaseModelForm(BaseForm):
|
||||
# Clean the model instance's fields.
|
||||
try:
|
||||
self.instance.clean_fields(exclude=exclude)
|
||||
except ValidationError, e:
|
||||
except ValidationError as e:
|
||||
self._update_errors(e.message_dict)
|
||||
|
||||
# Call the model instance's clean method.
|
||||
try:
|
||||
self.instance.clean()
|
||||
except ValidationError, e:
|
||||
except ValidationError as e:
|
||||
self._update_errors({NON_FIELD_ERRORS: e.messages})
|
||||
|
||||
# Validate uniqueness if needed.
|
||||
@@ -345,7 +345,7 @@ class BaseModelForm(BaseForm):
|
||||
exclude = self._get_validation_exclusions()
|
||||
try:
|
||||
self.instance.validate_unique(exclude=exclude)
|
||||
except ValidationError, e:
|
||||
except ValidationError as e:
|
||||
self._update_errors(e.message_dict)
|
||||
|
||||
def save(self, commit=True):
|
||||
|
||||
@@ -66,7 +66,7 @@ def from_current_timezone(value):
|
||||
current_timezone = timezone.get_current_timezone()
|
||||
try:
|
||||
return timezone.make_aware(value, current_timezone)
|
||||
except Exception, e:
|
||||
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.')
|
||||
|
||||
Reference in New Issue
Block a user