added support for getting completed answers with question ids matching a provided list
parent
5ae7ce8c13
commit
e65edce4b8
|
@ -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')]),
|
||||
),
|
||||
]
|
|
@ -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()
|
Loading…
Reference in New Issue