diff --git a/questionnaire/migrations/0017_auto_20160209_0228.py b/questionnaire/migrations/0017_auto_20160209_0228.py new file mode 100644 index 0000000..be2c2b2 --- /dev/null +++ b/questionnaire/migrations/0017_auto_20160209_0228.py @@ -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')]), + ), + ] diff --git a/questionnaire/utils_noncircular.py b/questionnaire/utils_noncircular.py new file mode 100644 index 0000000..ce8db22 --- /dev/null +++ b/questionnaire/utils_noncircular.py @@ -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()