From a4da2240d7c39b523b55949437b9783e455b2dd5 Mon Sep 17 00:00:00 2001 From: Shane Frischkorn Date: Sat, 24 Aug 2013 22:12:41 +1000 Subject: [PATCH] implemented multiple choice question functionality --- .gitignore | 1 + three_d_viewer/ajax.py | 17 ++++++++++++++++- .../templates/three_d_viewer/detail.html | 18 ++++++++++++++++-- three_d_viewer/views.py | 3 +-- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 0205d62..a74ceb7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.pyc .DS_Store +reports/ diff --git a/three_d_viewer/ajax.py b/three_d_viewer/ajax.py index 6cb2677..f5e2a93 100644 --- a/three_d_viewer/ajax.py +++ b/three_d_viewer/ajax.py @@ -1,8 +1,23 @@ from django.utils import simplejson from dajaxice.decorators import dajaxice_register -@dajaxice_register +from three_d_viewer.models import Question +@dajaxice_register def dajaxice_example(request): + test = check_answer(request, 3, 1) + print test return simplejson.dumps({'message':'Hello from Python!'}) + +@dajaxice_register +def check_answer(request, answerid, questionid): + question = Question.objects.get(id=int(questionid)) + + result = False + for answer in question.correct_answers(): + print type(answer.id) + if answer.id == int(answerid): + result = True + print simplejson.dumps({'result': result}) + return simplejson.dumps({'result': result}) \ No newline at end of file diff --git a/three_d_viewer/templates/three_d_viewer/detail.html b/three_d_viewer/templates/three_d_viewer/detail.html index 06f7129..786e71c 100644 --- a/three_d_viewer/templates/three_d_viewer/detail.html +++ b/three_d_viewer/templates/three_d_viewer/detail.html @@ -5,12 +5,15 @@ {{ sample.description }} +
+ js-openctm - Demo + {% dajaxice_js_import %} + @@ -372,7 +380,13 @@ function my_callback(data){ - +{% if sample.questions %} + {{ sample.questions.all.0 }}
+ {% for answer in sample.questions.all.0.answers.all %} + {{ answer}}
+ {% endfor %} + +{% endif %} diff --git a/three_d_viewer/views.py b/three_d_viewer/views.py index 4b7b287..666d11d 100644 --- a/three_d_viewer/views.py +++ b/three_d_viewer/views.py @@ -20,8 +20,7 @@ class IndexView(generic.ListView): def get_queryset(self): """ - Return the last five published polls (not including those set to be - published in the future). + Return the active samples """ return Sample.objects.filter(active=True)