added support for getting completed answers with question ids matching a provided list

dj111py38
Jamie Campbell 2016-02-11 01:27:13 -06:00
parent 5ae7ce8c13
commit e65edce4b8
2 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('questionnaire', '0016_subject_given_sur_name_index'),
]
operations = [
migrations.CreateModel(
name='GlobalStyles',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('content', models.TextField()),
],
),
migrations.AddField(
model_name='questionnaire',
name='admin_access_only',
field=models.BooleanField(default=False, verbose_name=b'Only allow access to logged in users? (This allows entering paper surveys without allowing new external submissions)'),
),
migrations.AlterField(
model_name='subject',
name='language',
field=models.CharField(default=b'en-us', max_length=2, verbose_name='Language', choices=[(b'en', b'English')]),
),
]

View File

@ -0,0 +1,20 @@
#!/usr/bin/python
from questionnaire.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:
specific_answers = Answer.objects.filter(runid=run.runid, 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()