implemented multiple choice question functionality
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
*.pyc
|
||||
.DS_Store
|
||||
reports/
|
||||
|
||||
@@ -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})
|
||||
|
||||
@@ -5,12 +5,15 @@
|
||||
|
||||
<html>
|
||||
{{ sample.description }}
|
||||
<br>
|
||||
|
||||
<head>
|
||||
<title>js-openctm - Demo</title>
|
||||
|
||||
<script type="text/javascript" src="{% static "three_d_viewer/lzma.js" %}"></script>
|
||||
<script type="text/javascript" src="{% static "three_d_viewer/ctm.js" %}"></script>
|
||||
<script type="text/javascript" src="{% static "three_d_viewer/glMatrix-0.9.5.min.js" %}"></script>
|
||||
<script type="text/javascript" src="{% static "three_d_viewer/jquery-2.0.3.js" %}"></script>
|
||||
{% dajaxice_js_import %}
|
||||
|
||||
<script id="shader-vs" type="x-shader/x-vertex">
|
||||
@@ -359,10 +362,15 @@ function handleMouseMove(event){
|
||||
}
|
||||
|
||||
function my_callback(data){
|
||||
alert(data.message);
|
||||
var message = "Incorrect";
|
||||
if (data.result){
|
||||
message = 'Correct';
|
||||
}
|
||||
alert(message);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<body onload="load();">
|
||||
@@ -372,7 +380,13 @@ function my_callback(data){
|
||||
</div>
|
||||
</center>
|
||||
|
||||
<input type="button" onclick="Dajaxice.three_d_viewer.dajaxice_example(my_callback)" value="Get message from server!">
|
||||
{% if sample.questions %}
|
||||
{{ sample.questions.all.0 }}<br>
|
||||
{% for answer in sample.questions.all.0.answers.all %}
|
||||
<input type="radio" name="answer" value={{answer.id}}>{{ answer}}</input><br>
|
||||
{% endfor %}
|
||||
<input type="button" onclick="Dajaxice.three_d_viewer.check_answer(my_callback, {'answerid':$('input:radio[name=answer]:checked').val(), 'questionid':{{ sample.questions.all.0.id }}})" value="Get message from server!" />
|
||||
{% endif %}
|
||||
|
||||
<body>
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user