1818from rest_framework .exceptions import APIException
1919from rest_framework .serializers import ManyRelatedField # noqa: F401
2020
21+ from .settings import json_api_settings
22+
2123try :
2224 from rest_framework_nested .relations import HyperlinkedRouterField
2325except ImportError :
@@ -104,7 +106,7 @@ def format_keys(obj, format_type=None):
104106 :format_type: Either 'dasherize', 'camelize' or 'underscore'
105107 """
106108 if format_type is None :
107- format_type = getattr ( settings , 'JSON_API_FORMAT_KEYS' , False )
109+ format_type = json_api_settings . FORMAT_KEYS
108110
109111 if format_type in ('dasherize' , 'camelize' , 'underscore' , 'capitalize' ):
110112
@@ -136,7 +138,7 @@ def format_keys(obj, format_type=None):
136138
137139def format_value (value , format_type = None ):
138140 if format_type is None :
139- format_type = getattr ( settings , 'JSON_API_FORMAT_KEYS' , False )
141+ format_type = json_api_settings . FORMAT_KEYS
140142 if format_type == 'dasherize' :
141143 # inflection can't dasherize camelCase
142144 value = inflection .underscore (value )
@@ -156,17 +158,17 @@ def format_relation_name(value, format_type=None):
156158 "settings are now 'JSON_API_FORMAT_TYPES' and 'JSON_API_PLURALIZE_TYPES'"
157159 )
158160 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
161163 return format_resource_type (value , format_type , pluralize )
162164
163165
164166def format_resource_type (value , format_type = None , pluralize = None ):
165167 if format_type is None :
166- format_type = getattr ( settings , 'JSON_API_FORMAT_TYPES' , False )
168+ format_type = json_api_settings . FORMAT_TYPES
167169
168170 if pluralize is None :
169- pluralize = getattr ( settings , 'JSON_API_PLURALIZE_TYPES' , False )
171+ pluralize = json_api_settings . PLURALIZE_TYPES
170172
171173 if format_type :
172174 # format_type will never be None here so we can use format_value
0 commit comments