Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
7d417fc6
Commit
7d417fc6
authored
Nov 20, 2014
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make _force_text_recursive private.
parent
37312eed
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
14 deletions
+18
-14
rest_framework/exceptions.py
+18
-14
No files found.
rest_framework/exceptions.py
View file @
7d417fc6
...
...
@@ -13,6 +13,23 @@ from rest_framework.compat import force_text
import
math
def
_force_text_recursive
(
data
):
"""
Descend into a nested data structure, forcing any
lazy translation strings into plain text.
"""
if
isinstance
(
data
,
list
):
return
[
_force_text_recursive
(
item
)
for
item
in
data
]
elif
isinstance
(
data
,
dict
):
return
dict
([
(
key
,
_force_text_recursive
(
value
))
for
key
,
value
in
data
.
items
()
])
return
force_text
(
data
)
class
APIException
(
Exception
):
"""
Base class for REST framework exceptions.
...
...
@@ -38,19 +55,6 @@ class APIException(Exception):
# from rest_framework import serializers
# raise serializers.ValidationError('Value was invalid')
def
force_text_recursive
(
data
):
if
isinstance
(
data
,
list
):
return
[
force_text_recursive
(
item
)
for
item
in
data
]
elif
isinstance
(
data
,
dict
):
return
dict
([
(
key
,
force_text_recursive
(
value
))
for
key
,
value
in
data
.
items
()
])
return
force_text
(
data
)
class
ValidationError
(
APIException
):
status_code
=
status
.
HTTP_400_BAD_REQUEST
...
...
@@ -59,7 +63,7 @@ class ValidationError(APIException):
# The details should always be coerced to a list if not already.
if
not
isinstance
(
detail
,
dict
)
and
not
isinstance
(
detail
,
list
):
detail
=
[
detail
]
self
.
detail
=
force_text_recursive
(
detail
)
self
.
detail
=
_
force_text_recursive
(
detail
)
def
__str__
(
self
):
return
str
(
self
.
detail
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment