Convert dict to json and then dump + fix checking None on FileField

This commit is contained in:
PCoder 2019-11-04 12:15:52 +05:30
parent 6faa8b82e8
commit 7aec4dd938

View file

@ -1,3 +1,4 @@
import json
import logging import logging
import sys import sys
from pprint import pprint from pprint import pprint
@ -115,7 +116,7 @@ class Command(BaseCommand):
"Name": uhk.name, "Name": uhk.name,
"Created on": str(uhk.created_at) "Created on": str(uhk.created_at)
} }
if uhk.private_key is not None: if uhk.private_key:
key["Private key"] = uhk.private_key key["Private key"] = uhk.private_key
keys[uhk.name] = key keys[uhk.name] = key
output_dict = { output_dict = {
@ -129,6 +130,6 @@ class Command(BaseCommand):
"Payment cards": cards, "Payment cards": cards,
"SSH Keys": keys "SSH Keys": keys
} }
pprint(output_dict) pprint(json.dumps(output_dict))
except Exception as e: except Exception as e:
print(" *** Error occurred. Details {}".format(str(e))) print(" *** Error occurred. Details {}".format(str(e)))