18
18
from rest_framework .exceptions import APIException
19
19
from rest_framework .serializers import ManyRelatedField # noqa: F401
20
20
21
+ from .settings import json_api_settings
22
+
21
23
try :
22
24
from rest_framework_nested .relations import HyperlinkedRouterField
23
25
except ImportError :
@@ -104,7 +106,7 @@ def format_keys(obj, format_type=None):
104
106
:format_type: Either 'dasherize', 'camelize' or 'underscore'
105
107
"""
106
108
if format_type is None :
107
- format_type = getattr ( settings , 'JSON_API_FORMAT_KEYS' , False )
109
+ format_type = json_api_settings . FORMAT_KEYS
108
110
109
111
if format_type in ('dasherize' , 'camelize' , 'underscore' , 'capitalize' ):
110
112
@@ -136,7 +138,7 @@ def format_keys(obj, format_type=None):
136
138
137
139
def format_value (value , format_type = None ):
138
140
if format_type is None :
139
- format_type = getattr ( settings , 'JSON_API_FORMAT_KEYS' , False )
141
+ format_type = json_api_settings . FORMAT_KEYS
140
142
if format_type == 'dasherize' :
141
143
# inflection can't dasherize camelCase
142
144
value = inflection .underscore (value )
@@ -156,17 +158,17 @@ def format_relation_name(value, format_type=None):
156
158
"settings are now 'JSON_API_FORMAT_TYPES' and 'JSON_API_PLURALIZE_TYPES'"
157
159
)
158
160
if format_type is None :
159
- format_type = getattr ( settings , 'JSON_API_FORMAT_RELATION_KEYS' , None )
160
- pluralize = getattr ( settings , 'JSON_API_PLURALIZE_RELATION_TYPE' , None )
161
+ format_type = json_api_settings . FORMAT_RELATION_KEYS
162
+ pluralize = json_api_settings . PLURALIZE_RELATION_TYPE
161
163
return format_resource_type (value , format_type , pluralize )
162
164
163
165
164
166
def format_resource_type (value , format_type = None , pluralize = None ):
165
167
if format_type is None :
166
- format_type = getattr ( settings , 'JSON_API_FORMAT_TYPES' , False )
168
+ format_type = json_api_settings . FORMAT_TYPES
167
169
168
170
if pluralize is None :
169
- pluralize = getattr ( settings , 'JSON_API_PLURALIZE_TYPES' , False )
171
+ pluralize = json_api_settings . PLURALIZE_TYPES
170
172
171
173
if format_type :
172
174
# format_type will never be None here so we can use format_value
0 commit comments