Skip to content

Commit

Permalink
Update DynamicList.unformat_data and test
Browse files Browse the repository at this point in the history
  • Loading branch information
benvand committed Apr 18, 2017
1 parent 666e986 commit 5823b10
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
23 changes: 11 additions & 12 deletions dmcontent/questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
1 change: 0 additions & 1 deletion tests/test_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5823b10

Please sign in to comment.