Fix key ordering in json. (sort if it's a sorted dictc representation, or not otherwise)

This commit is contained in:
Tom Christie 2012-10-10 12:32:23 +01:00
parent 648d2be29b
commit db6b5a990b

View File

@ -54,7 +54,6 @@ class JSONRenderer(BaseRenderer):
# E.g. If we're being called by the BrowseableAPIRenderer. # E.g. If we're being called by the BrowseableAPIRenderer.
renderer_context = renderer_context or {} renderer_context = renderer_context or {}
indent = renderer_context.get('indent', None) indent = renderer_context.get('indent', None)
sort_keys = indent and True or False
if accepted_media_type: if accepted_media_type:
# If the media type looks like 'application/json; indent=4', # If the media type looks like 'application/json; indent=4',
@ -63,12 +62,10 @@ class JSONRenderer(BaseRenderer):
indent = params.get('indent', indent) indent = params.get('indent', indent)
try: try:
indent = max(min(int(indent), 8), 0) indent = max(min(int(indent), 8), 0)
sort_keys = True
except (ValueError, TypeError): except (ValueError, TypeError):
indent = None indent = None
return json.dumps(data, cls=self.encoder_class, return json.dumps(data, cls=self.encoder_class, indent=indent)
indent=indent, sort_keys=sort_keys)
class JSONPRenderer(JSONRenderer): class JSONPRenderer(JSONRenderer):