diff --git a/dmcontent/questions.py b/dmcontent/questions.py index b66a836..08753ba 100644 --- a/dmcontent/questions.py +++ b/dmcontent/questions.py @@ -394,20 +394,19 @@ def unformat_data(self, data): { "yesno-0": True, "yesno-1": False, - "evidence-0": "Yes, I did." - "nonDynamicListKey": 'other data' - } + "evidence-0": "Yes, I did." } """ result = {} - for key in data: - if key == self.id: - for question in self.questions: - # For each question e.g. evidence-0, find if data exists for it and insert it into our result - root, index = question.id.split('-') - if root in data[self.id][int(index)]: - result[question.id] = data[self.id][int(index)].get(root) - else: - result[key] = data[key] + data = data.get(self.id, None) + if not data: + return result + for question in self.questions: + # For each question e.g. evidence-0, find if data exists for it and insert it into our result + root, index = question.id.split('-') + question_data = data[self.id][int(index)] + if root in question_data: + result.update({question.id: question_data.get(root)}) + return result def get_error_messages(self, errors, question_descriptor_from="label"): diff --git a/tests/test_questions.py b/tests/test_questions.py index bf76743..a918e7b 100644 --- a/tests/test_questions.py +++ b/tests/test_questions.py @@ -561,7 +561,6 @@ def test_unformat_data(self): "yesno-0": True, "evidence-0": 'my evidence', "yesno-2": False, - "nonDynamicKey": 'data' } assert question.unformat_data(data) == expected