api: truncate output in html preview
This commit is contained in:
parent
5c91e99ab7
commit
23da7e3605
1 changed files with 11 additions and 1 deletions
|
@ -11,7 +11,17 @@ orig_render = JSONRenderer.render
|
||||||
def nicer_renderer(self, data, accepted_media_type=None, renderer_context=None):
|
def nicer_renderer(self, data, accepted_media_type=None, renderer_context=None):
|
||||||
if self.get_indent(accepted_media_type, renderer_context) is None:
|
if self.get_indent(accepted_media_type, renderer_context) is None:
|
||||||
return orig_render(self, data, accepted_media_type, renderer_context)
|
return orig_render(self, data, accepted_media_type, renderer_context)
|
||||||
return json_encoder_reindent(lambda d: orig_render(self, d, accepted_media_type, renderer_context), data)
|
shorten = isinstance(data, (list, tuple)) and len(data) > 2
|
||||||
|
orig_len = None
|
||||||
|
if shorten:
|
||||||
|
orig_len = len(data)-2
|
||||||
|
data = data[:2]
|
||||||
|
result = json_encoder_reindent(lambda d: orig_render(self, d, accepted_media_type, renderer_context), data)
|
||||||
|
if shorten:
|
||||||
|
result = (result[:-2] +
|
||||||
|
('\n ...%d more elements (truncated for HTML preview)...' % orig_len).encode() +
|
||||||
|
result[-2:])
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
# Monkey patch for nicer indentation in the django rest framework
|
# Monkey patch for nicer indentation in the django rest framework
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue