rockviewer/three_d_viewer/ajax.py

27 lines
621 B
Python
Raw Normal View History

2013-08-25 20:16:20 +10:00
"""
Handle asynchronous calls from the web pages
"""
from django.utils import simplejson
from dajaxice.decorators import dajaxice_register
2013-08-25 20:16:20 +10:00
from models import Question
2013-08-25 19:43:19 +10:00
2013-08-25 19:43:19 +10:00
@dajaxice_register
def check_answer(request, answerid, questionid):
2013-08-25 20:16:20 +10:00
"""
Check whether answerid is the correct answer for questionid.
Returns a boolean in 'result'
"""
question = Question.objects.get(id=int(questionid))
2013-08-25 19:43:19 +10:00
result = False
for answer in question.correct_answers():
print type(answer.id)
if answer.id == int(answerid):
result = True
2013-08-25 20:16:20 +10:00
return simplejson.dumps({'result': result})