fef-questionnaire/questionnaire/utils_noncircular.py

21 lines
760 B
Python
Raw Permalink Normal View History

#!/usr/bin/python
2016-07-26 21:08:23 +00:00
from .models import RunInfoHistory, Answer
def get_completed_answers_for_questions(questionnaire_id, question_list):
completed_questionnaire_runs = RunInfoHistory.objects.filter(questionnaire__id=questionnaire_id)
completed_answers = []
for run in completed_questionnaire_runs:
2016-11-03 15:43:08 +00:00
specific_answers = Answer.objects.filter(run=run.run, question_id__in=question_list)
answer_set = []
for answer in specific_answers:
if answer.answer != '[]':
answer_set.append([int(answer.question_id), answer.answer])
if len(answer_set) > 0:
completed_answers.append(answer_set)
return completed_answers
if __name__ == "__main__":
import doctest
doctest.testmod()