implemented multiple choice question functionality
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
*.pyc
|
*.pyc
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
reports/
|
||||||
|
|||||||
@@ -1,8 +1,23 @@
|
|||||||
from django.utils import simplejson
|
from django.utils import simplejson
|
||||||
from dajaxice.decorators import dajaxice_register
|
from dajaxice.decorators import dajaxice_register
|
||||||
|
|
||||||
@dajaxice_register
|
from three_d_viewer.models import Question
|
||||||
|
|
||||||
|
@dajaxice_register
|
||||||
def dajaxice_example(request):
|
def dajaxice_example(request):
|
||||||
|
test = check_answer(request, 3, 1)
|
||||||
|
print test
|
||||||
return simplejson.dumps({'message':'Hello from Python!'})
|
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>
|
<html>
|
||||||
{{ sample.description }}
|
{{ sample.description }}
|
||||||
|
<br>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>js-openctm - Demo</title>
|
<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/lzma.js" %}"></script>
|
||||||
<script type="text/javascript" src="{% static "three_d_viewer/ctm.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/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 %}
|
{% dajaxice_js_import %}
|
||||||
|
|
||||||
<script id="shader-vs" type="x-shader/x-vertex">
|
<script id="shader-vs" type="x-shader/x-vertex">
|
||||||
@@ -359,10 +362,15 @@ function handleMouseMove(event){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function my_callback(data){
|
function my_callback(data){
|
||||||
alert(data.message);
|
var message = "Incorrect";
|
||||||
|
if (data.result){
|
||||||
|
message = 'Correct';
|
||||||
|
}
|
||||||
|
alert(message);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body onload="load();">
|
<body onload="load();">
|
||||||
@@ -372,7 +380,13 @@ function my_callback(data){
|
|||||||
</div>
|
</div>
|
||||||
</center>
|
</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>
|
<body>
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,7 @@ class IndexView(generic.ListView):
|
|||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
"""
|
"""
|
||||||
Return the last five published polls (not including those set to be
|
Return the active samples
|
||||||
published in the future).
|
|
||||||
"""
|
"""
|
||||||
return Sample.objects.filter(active=True)
|
return Sample.objects.filter(active=True)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user