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 19, 2017
1 parent 666e986 commit bd77101
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dmcontent/content_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from werkzeug.datastructures import ImmutableMultiDict

from .errors import ContentNotFoundError, QuestionNotFoundError
from .questions import Question, ContentQuestion, Date
from .questions import Question, ContentQuestion
from .messages import ContentMessage
from .utils import TemplateField, template_all, drop_followups

Expand Down
20 changes: 10 additions & 10 deletions dmcontent/questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,19 +395,19 @@ def unformat_data(self, data):
"yesno-0": True,
"yesno-1": False,
"evidence-0": "Yes, I did."
"nonDynamicListKey": 'other data'
}
"""
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]
dynamic_list_data = data.get(self.id, None)
if not dynamic_list_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 = dynamic_list_data[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 bd77101

Please sign in to comment.