Skip to content

Commit d819a1f

Browse files
committed
Corrected inflection setting management
1 parent a9dac87 commit d819a1f

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ requests and responses from the python/rest_framework's preferred underscore to
155155
a format of your choice. To hook this up include the following in your project
156156
settings::
157157

158-
JSON_API_FORMAT_KEYS = True
158+
JSON_API_FORMAT_KEYS = 'dasherize'
159159

160160
Note: due to the way the inflector works address_1 can camelize to address1
161161
on output but it cannot convert address1 back to address_1 on POST or PUT. Keep

example/tests/test_format_keys.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ def setUp(self):
1818
self.detail_url = reverse('user-detail', kwargs={'pk': self.miles.pk})
1919

2020
# Set the format keys settings.
21-
setattr(settings, 'JSON_API_FORMAT_KEYS', True)
21+
setattr(settings, 'JSON_API_FORMAT_KEYS', 'camelization')
2222

2323
def tearDown(self):
2424
# Remove the format keys settings.
25-
delattr(settings, 'JSON_API_FORMAT_KEYS')
25+
setattr(settings, 'JSON_API_FORMAT_KEYS', 'dasherize')
2626

2727

2828
def test_camelization(self):

rest_framework_json_api/utils.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,12 @@ def format_keys(obj, format_type=None):
115115
def format_value(value, format_type=None):
116116
format_type = getattr(settings, 'JSON_API_FORMAT_KEYS', False)
117117
if format_type == 'dasherize':
118-
return inflection.dasherize(value)
119-
if format_type == 'camelize':
120-
return inflection.camelize(value)
121-
if format_type == 'underscore':
122-
return inflection.underscore(value)
118+
value = inflection.dasherize(value)
119+
elif format_type == 'camelize':
120+
value = inflection.camelize(value)
121+
elif format_type == 'underscore':
122+
value = inflection.underscore(value)
123+
return value
123124

124125

125126
def build_json_resource_obj(fields, resource, resource_name):

0 commit comments

Comments
 (0)