Commit 961f4f25 authored by Roshan Rabinarayan's avatar Roshan Rabinarayan

saved submissions

parent 5a5bc06f
No preview for this file type
......@@ -34,11 +34,11 @@ function goto_question(x) {
}
}
function set_option( question_id, option_id ) {
function set_option( question_id, option_id ,value) {
if(typeof question_id == "number" && typeof option_id == "number") {
if(question_id>=0 && question_id<questions_len && option_id>=0 && option_id<4) {
var ans = document.getElementById('q'+question_id);
ans.value = option_id;
ans.value = value;
var cbox = document.getElementById("lbl_"+question_id+"_"+option_id);
console.log("lbl_"+question_id+"_"+option_id);
cbox.style.backgroundColor = '#f4fa9c';
......
......@@ -8,7 +8,7 @@
</head>
<body>
<form method="POST" action="result">
<form method="POST" action="/result/">{% csrf_token %}
<!-- <h1>{{questions.quizId}} Question {{ questions.end_index }} of {{count}}</h1> -->
<aside id="question_palette">
<ul class="questions_list">
......@@ -35,14 +35,19 @@
<!-- <h1 id ='quizId'>{{i.quizId}}<h1> -->
<h1 id ='questionId' hidden>{{i.questionId}} </h1>
<h1>{{i.question}}</h1>
<label class="op_box" onclick="set_option({{forloop.counter0}}, 0)"><span id="lbl_{{forloop.counter0}}_0"><strong>A</strong><span>{{i.option1}}</span></span></label>
<label class="op_box" onclick="set_option({{forloop.counter0}}, 1)"><span id="lbl_{{forloop.counter0}}_1"><strong>B</strong><span>{{i.option2}}</span></span></label>
<label class="op_box" onclick="set_option({{forloop.counter0}}, 2)"><span id="lbl_{{forloop.counter0}}_2"><strong>C</strong><span>{{i.option3}}</span></span></label>
<label class="op_box" onclick="set_option({{forloop.counter0}}, 3)"><span id="lbl_{{forloop.counter0}}_3"><strong>D</strong><span>{{i.option4}}</span></span></label>
<input type="hidden" id="q{{forloop.counter0}}" name="q{{forloop.counter0}}" value="NA">
<input type="hidden" id="qq{{forloop.counter0}}" name="qq{{forloop.counter0}}" value="{{i.questionId}}">
<label class="op_box" onclick="set_option({{forloop.counter0}},0, ' {{i.option1}}')"><span id="lbl_{{forloop.counter0}}_0"><strong>A</strong><span>{{i.option1}}</span></span></label>
<label class="op_box" onclick="set_option({{forloop.counter0}},1, '{{i.option2}}')"><span id="lbl_{{forloop.counter0}}_1"><strong>B</strong><span>{{i.option2}}</span></span></label>
<label class="op_box" onclick="set_option({{forloop.counter0}},2, '{{i.option3}}')"><span id="lbl_{{forloop.counter0}}_2"><strong>C</strong><span>{{i.option3}}</span></span></label>
<label class="op_box" onclick="set_option({{forloop.counter0}}, 3,'{{i.option4}}')"><span id="lbl_{{forloop.counter0}}_3"><strong>D</strong><span>{{i.option4}}</span></span></label>
<input type="hidden" id="q{{forloop.counter0}}" name="{{i.questionId}}" value="NA">
<!-- <label ><input type="textarea" name="fame" id="cribs" value="">Cribs...</label> -->
</div>
{%endfor%}
<input type="hidden" id="quizId" name="quizId" value="{{questions.0.quizId}}">
</div>
</section>
</form>
......
......@@ -10,15 +10,11 @@ from . newQuiz import readCSV
import csv
lst = []
answers = Questions.objects.all()
answers = []
anslist = []
marksList=[]
negative=[]
for i in answers:
print(str(i.answer)+" "+str(i.negative)+" "+str(i.marks))
anslist.append(i.answer)
marksList.append(i.marks)
negative.append(i.negative)
def index(request):
obj = Questions.objects.get_queryset().order_by('questionId')
......@@ -37,14 +33,27 @@ def index(request):
def result(request):
score =0
#print("lstlstlst"+str(len(anslist)))
for i in range(len(lst)):
if lst[i]==anslist[i]:
score +=marksList[i]
else:
score-=negative[i]
return render(request,'result.html',{'score':score,'lst':lst,'anslist':anslist})
st=str()
answer=list() #contains user responses
questionNumber=list()
ans=list()
for req in request.POST:
ans.append(req)
if(request.method =="POST"):
quizId=request.POST['quizId']
i=len(request.POST)
j=2
while j<i-1:
#last value contains quiz id
questionNumber.append(request.POST[ans[j-1]])
answer.append(request.POST[ans[j]])
t=submission(questionId=request.POST[ans[j-1]],option=request.POST[ans[j]],studentId=6969,quizId=quizId)#studentid hardcoded
t.save()
j+=2 #questionid option pair
return HttpResponse(str(ans))
def save_ans(request):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment