Skip to content

Commit 6e49949

Browse files
committed
Added pretty print
committer: Ralf Schlatterbeck <[email protected]>
1 parent ceeaaa7 commit 6e49949

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

roundup/rest.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ def dispatch(self, method, uri, input):
255255
format_header = self.client.request.headers.getheader('Accept')[12:]
256256
format_output = format_ext or format_header or "json"
257257

258+
# check for pretty print
259+
try:
260+
pretty_output = input['pretty'].value.lower() == "true"
261+
except KeyError:
262+
pretty_output = False
263+
258264
self.client.setHeader("Access-Control-Allow-Origin", "*")
259265
self.client.setHeader("Access-Control-Allow-Headers",
260266
"Content-Type, Authorization, "
@@ -312,7 +318,11 @@ def dispatch(self, method, uri, input):
312318
finally:
313319
if format_output.lower() == "json":
314320
self.client.setHeader("Content-Type", "application/json")
315-
output = RoundupJSONEncoder().encode(output)
321+
if pretty_output:
322+
indent = 4
323+
else:
324+
indent = None
325+
output = RoundupJSONEncoder(indent=indent).encode(output)
316326
else:
317327
self.client.response_code = 406
318328
output = ""

0 commit comments

Comments
 (0)