diff --git a/rest_framework/authtoken/serializers.py b/rest_framework/authtoken/serializers.py index 7c49f3305..42d67c2d3 100644 --- a/rest_framework/authtoken/serializers.py +++ b/rest_framework/authtoken/serializers.py @@ -18,20 +18,17 @@ class AuthTokenSerializer(serializers.Serializer): if user: if not user.is_active: msg = _('User account is disabled.') - raise serializers.ValidationError( - msg, - code='authorization') + code = 'authorization' + raise serializers.ValidationError(msg, code=code) else: msg = _('Unable to log in with provided credentials.') - raise serializers.ValidationError( - msg, - code='authorization') + code = 'authorization' + raise serializers.ValidationError(msg, code=code) else: msg = _('Must include "username" and "password".') - raise serializers.ValidationError( - msg, - code='authorization') + code = 'authorization' + raise serializers.ValidationError(msg, code=code) attrs['user'] = user return attrs diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 469c573f7..27e064040 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -31,9 +31,7 @@ from rest_framework.compat import ( MinValueValidator, duration_string, parse_duration, unicode_repr, unicode_to_repr ) -from rest_framework.exceptions import ( - ValidationError -) +from rest_framework.exceptions import ValidationError from rest_framework.settings import api_settings from rest_framework.utils import html, humanize_datetime, representation diff --git a/rest_framework/validators.py b/rest_framework/validators.py index 53d5479ce..d96421542 100644 --- a/rest_framework/validators.py +++ b/rest_framework/validators.py @@ -147,9 +147,9 @@ class UniqueTogetherValidator(object): ] if None not in checked_values and queryset.exists(): field_names = ', '.join(self.fields) - raise ValidationError( - self.message.format(field_names=field_names), - code='unique') + message = self.message.format(field_names=field_names) + code = 'unique' + raise ValidationError(message, code=code) def __repr__(self): return unicode_to_repr('<%s(queryset=%s, fields=%s)>' % (