summaryrefslogtreecommitdiff
path: root/postgresqleu/util/widgets.py
diff options
context:
space:
mode:
authorMagnus Hagander2020-02-20 14:54:42 +0000
committerMagnus Hagander2020-02-20 14:54:42 +0000
commite96fbcff738bdda87da41cd8762828c35acda205 (patch)
tree9822e473a51965b6a09e097a7ed8d214e15e0f1b /postgresqleu/util/widgets.py
parent8d2321d025de8f89dc6f42cb610209ce1ee4a053 (diff)
Make json widget handle null values and nested dicts
Diffstat (limited to 'postgresqleu/util/widgets.py')
-rw-r--r--postgresqleu/util/widgets.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/postgresqleu/util/widgets.py b/postgresqleu/util/widgets.py
index 02d2fb30..8994453c 100644
--- a/postgresqleu/util/widgets.py
+++ b/postgresqleu/util/widgets.py
@@ -44,7 +44,12 @@ class PrettyPrintJsonWidget(forms.Textarea):
# This is mighty ugly -- we parse the json and then turn it back into json.
# Luckily this isn't called often :)
try:
- value = json.dumps(json.loads(value), indent=2)
+ if value is not None:
+ if isinstance(value, dict):
+ # Already a dict, so just turn it into json
+ value = json.dumps(value, indent=2)
+ else:
+ value = json.dumps(json.loads(value), indent=2)
except ValueError:
# Don't try to do anything if it's not valid json
pass