From 1ca8bc168cecd00f7ec25936ace1e893ee50f897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Thu, 23 Jul 2020 16:09:49 +0200 Subject: [PATCH] chg: pretty print json when possible. --- website/web/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/website/web/__init__.py b/website/web/__init__.py index 97e0631f..23b59418 100644 --- a/website/web/__init__.py +++ b/website/web/__init__.py @@ -255,8 +255,15 @@ def urlnode_details(tree_uuid: str, node_uuid: str): body_content = urlnode.body.getvalue() if body_content: got_content = True + if hasattr(urlnode, 'json') and urlnode.json: + try: + loaded = json.loads(body_content) + body_content = json.dumps(loaded, indent=2).encode() + except Exception: + # Not json, but junk + pass with ZipFile(to_return, 'w', ZIP_DEFLATED) as zfile: - zfile.writestr(urlnode.filename, urlnode.body.getvalue()) + zfile.writestr(urlnode.filename, body_content) if not got_content: with ZipFile(to_return, 'w', ZIP_DEFLATED) as zfile: zfile.writestr('file.txt', b'Response body empty')