Newer
Older
"""
Functions used by several modules.
"""
def remove_mongodb_id_from_result(json_data, result_type) -> list:
"""
When retrieving results from MongoDB, the Mongo ID is included by the DB.
This function removes this ID from the result.
"""
purged_list = []
for obj in json_data:
d = dict(obj)
del d['_id']
if result_type == 'gt':
d = d['gt_workspace']
purged_list.append(d)
return purged_list
def remove_key_from_dict(d: dict, tbr_key: str) -> None:
"""
This function removes keys with the value of null from the result.
"""
for key in list(d.keys()):
if key == tbr_key and d[key] == None:
del d[key]
else:
remove_key_from_dict(d[key], tbr_key)