Mercurial > p > roundup > code
diff roundup/rest.py @ 5577:11e75fbb9edc REST-rebased
Added pretty print
committer: Ralf Schlatterbeck <rsc@runtux.com>
| author | Chau Nguyen <dangchau1991@yahoo.com> |
|---|---|
| date | Wed, 30 Jan 2019 10:26:34 +0100 |
| parents | 77d11a24f718 |
| children | c2214d0c9df8 |
line wrap: on
line diff
--- a/roundup/rest.py Wed Jan 30 10:26:34 2019 +0100 +++ b/roundup/rest.py Wed Jan 30 10:26:34 2019 +0100 @@ -255,6 +255,12 @@ format_header = self.client.request.headers.getheader('Accept')[12:] format_output = format_ext or format_header or "json" + # check for pretty print + try: + pretty_output = input['pretty'].value.lower() == "true" + except KeyError: + pretty_output = False + self.client.setHeader("Access-Control-Allow-Origin", "*") self.client.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, " @@ -312,7 +318,11 @@ finally: if format_output.lower() == "json": self.client.setHeader("Content-Type", "application/json") - output = RoundupJSONEncoder().encode(output) + if pretty_output: + indent = 4 + else: + indent = None + output = RoundupJSONEncoder(indent=indent).encode(output) else: self.client.response_code = 406 output = ""
