From 6838f17325c2149e432e4a40b945695b765f35a2 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Fri, 30 Jan 2015 16:40:54 +0000 Subject: Add built-in translations. --- rest_framework/views.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'rest_framework/views.py') diff --git a/rest_framework/views.py b/rest_framework/views.py index 12bb78bd..995ddd0f 100644 --- a/rest_framework/views.py +++ b/rest_framework/views.py @@ -2,12 +2,10 @@ Provides an APIView class that is the base of all views in REST framework. """ from __future__ import unicode_literals -import inspect -import warnings - from django.core.exceptions import PermissionDenied from django.http import Http404 from django.utils.encoding import smart_text +from django.utils.translation import ugettext_lazy as _ from django.views.decorators.csrf import csrf_exempt from rest_framework import status, exceptions from rest_framework.compat import HttpResponseBase, View @@ -15,6 +13,8 @@ from rest_framework.request import Request from rest_framework.response import Response from rest_framework.settings import api_settings from rest_framework.utils import formatting +import inspect +import warnings def get_view_name(view_cls, suffix=None): @@ -74,11 +74,11 @@ def exception_handler(exc, context): return Response(data, status=exc.status_code, headers=headers) elif isinstance(exc, Http404): - data = {'detail': 'Not found'} + data = {'detail': _('Not found.')} return Response(data, status=status.HTTP_404_NOT_FOUND) elif isinstance(exc, PermissionDenied): - data = {'detail': 'Permission denied'} + data = {'detail': _('Permission denied.')} return Response(data, status=status.HTTP_403_FORBIDDEN) # Note: Unhandled exceptions will raise a 500 error. -- cgit v1.2.3 From 2cc4cb24652366c6622af08370a0c04b429aa4b8 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Sat, 31 Jan 2015 08:53:40 +0000 Subject: Fix error text in test. --- rest_framework/views.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'rest_framework/views.py') diff --git a/rest_framework/views.py b/rest_framework/views.py index 995ddd0f..9445c840 100644 --- a/rest_framework/views.py +++ b/rest_framework/views.py @@ -4,6 +4,7 @@ Provides an APIView class that is the base of all views in REST framework. from __future__ import unicode_literals from django.core.exceptions import PermissionDenied from django.http import Http404 +from django.utils import six from django.utils.encoding import smart_text from django.utils.translation import ugettext_lazy as _ from django.views.decorators.csrf import csrf_exempt @@ -74,11 +75,13 @@ def exception_handler(exc, context): return Response(data, status=exc.status_code, headers=headers) elif isinstance(exc, Http404): - data = {'detail': _('Not found.')} + msg = _('Not found.') + data = {'detail': six.text_type(msg)} return Response(data, status=status.HTTP_404_NOT_FOUND) elif isinstance(exc, PermissionDenied): - data = {'detail': _('Permission denied.')} + msg = _('Permission denied.') + data = {'detail': six.text_type(msg)} return Response(data, status=status.HTTP_403_FORBIDDEN) # Note: Unhandled exceptions will raise a 500 error. -- cgit v1.2.3 From 1f996128458570a909d13f15c3d739fb12111984 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Fri, 6 Feb 2015 13:21:35 +0000 Subject: Upgrade pending deprecations to deprecations --- rest_framework/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rest_framework/views.py') diff --git a/rest_framework/views.py b/rest_framework/views.py index 9445c840..b4abc4d9 100644 --- a/rest_framework/views.py +++ b/rest_framework/views.py @@ -409,7 +409,7 @@ class APIView(View): warnings.warn( 'The `exception_handler(exc)` call signature is deprecated. ' 'Use `exception_handler(exc, context) instead.', - PendingDeprecationWarning + DeprecationWarning ) response = exception_handler(exc) else: -- cgit v1.2.3