@@ -70,10 +70,10 @@ def get_resource_name(context):
70
70
if not isinstance (resource_name , six .string_types ):
71
71
return resource_name
72
72
73
- resource_name = inflection .pluralize (resource_name .lower ())
74
-
75
73
resource_name = format_value (resource_name )
76
74
75
+ resource_name = inflection .pluralize (resource_name )
76
+
77
77
return resource_name
78
78
79
79
@@ -94,17 +94,22 @@ def format_keys(obj, format_type=None):
94
94
if format_type is None :
95
95
format_type = getattr (settings , 'JSON_API_FORMAT_KEYS' , False )
96
96
97
- if format_type in ('dasherize' , 'camelize' , 'underscore' ):
97
+ if format_type in ('dasherize' , 'camelize' , 'underscore' , 'capitalize' ):
98
98
99
99
if isinstance (obj , dict ):
100
100
formatted = OrderedDict ()
101
101
for key , value in obj .items ():
102
102
if format_type == 'dasherize' :
103
+ # inflection can't dasherize camelCase
104
+ key = inflection .underscore (key )
103
105
formatted [inflection .dasherize (key )] \
104
106
= format_keys (value , format_type )
105
107
elif format_type == 'camelize' :
106
108
formatted [inflection .camelize (key , False )] \
107
109
= format_keys (value , format_type )
110
+ elif format_type == 'capitalize' :
111
+ formatted [inflection .camelize (key )] \
112
+ = format_keys (value , format_type )
108
113
elif format_type == 'underscore' :
109
114
formatted [inflection .underscore (key )] \
110
115
= format_keys (value , format_type )
@@ -121,8 +126,12 @@ def format_value(value, format_type=None):
121
126
if format_type is None :
122
127
format_type = getattr (settings , 'JSON_API_FORMAT_KEYS' , False )
123
128
if format_type == 'dasherize' :
129
+ # inflection can't dasherize camelCase
130
+ value = inflection .underscore (value )
124
131
value = inflection .dasherize (value )
125
132
elif format_type == 'camelize' :
133
+ value = inflection .camelize (value , False )
134
+ elif format_type == 'capitalize' :
126
135
value = inflection .camelize (value )
127
136
elif format_type == 'underscore' :
128
137
value = inflection .underscore (value )
@@ -132,15 +141,10 @@ def format_value(value, format_type=None):
132
141
def format_relation_name (value , format_type = None ):
133
142
if format_type is None :
134
143
format_type = getattr (settings , 'JSON_API_FORMAT_RELATION_KEYS' , False )
135
-
144
+
136
145
if not format_type :
137
- # let's keep it the way it was
138
146
return value
139
147
140
- # in case the value is going to be changed, make it underscored first
141
- # because dasherize does not work with a camel cased string
142
- value = inflection .underscore (value )
143
-
144
148
# format_type will never be None here so we can use format_value
145
149
value = format_value (value , format_type )
146
150
0 commit comments