diff --git a/server/app/models/entry.py b/server/app/models/entry.py index ea8e6af..64cca89 100644 --- a/server/app/models/entry.py +++ b/server/app/models/entry.py @@ -1,4 +1,5 @@ from ..extensions import db +from ..tools.data import declutter_results from ..tools.models import JsonString from sqlalchemy_json import MutableJson @@ -18,8 +19,8 @@ class Entry(db.Model): def __init__(self, answers:list, results:dict): self.id = uuid4().hex self.timestamp = datetime.utcnow() - self.answers = answers - self.results = results + self.answers = answers.copy() + self.results = declutter_results(results) def add(self): db.session.add(self) diff --git a/server/app/tools/data.py b/server/app/tools/data.py index 6d44f26..dd07262 100644 --- a/server/app/tools/data.py +++ b/server/app/tools/data.py @@ -4,6 +4,8 @@ import json from os.path import isfile from pathlib import Path +from copy import deepcopy + def check_file(filename:str) -> bool: data_dir = Path(app.config.get('DATA')) if isfile(f'./{data_dir}/{filename}'): return True @@ -11,4 +13,12 @@ def check_file(filename:str) -> bool: def load(filename:str) -> dict: data_dir = Path(app.config.get('DATA')) - with open(f'./{data_dir}/{filename}') as file: return json.load(file) \ No newline at end of file + with open(f'./{data_dir}/{filename}') as file: return json.load(file) + +def declutter_results(raw_results:dict) -> dict: + data = deepcopy(raw_results) + playbook_lists = [] + for item in data['playbooks']: + playbook_lists.append(list(item.keys())[0]) + data['playbooks'] = playbook_lists + return data \ No newline at end of file