You need to sign in or sign up before continuing.
Commit 15dade56 authored by Samarth Joshi's avatar Samarth Joshi

Adding score functionality again someone plz add score to result db

parent 411b69e8
No preview for this file type
......@@ -33,9 +33,9 @@
{% for i in questions%}
<div class="question">
<div class="question_header">
<p><!--placeholder element left--></p>
<p>{{ i.negative }}</p>
<p>Question {{ forloop.counter }} of {{ count }}</p>
<p><!--placeholder element right--></p>
<p>{{ i.marks }}</p>
</div>
<!-- <h1 id ='quizId'>{{i.quizId}}<h1> -->
<h1 id ='questionId' hidden>{{i.questionId}} </h1>
......
......@@ -49,14 +49,20 @@ def result(request):
quizId=int(request.POST['quizId'])
quizInstance = quiz.objects.get(pk=quizId)
prev_subm = submission.objects.all().filter(quizId=quizInstance, studentId=request.user)
score = 0
if len(prev_subm)==0:
for questionno in request.POST:
if questionno.startswith('question_'):
questionId = int(questionno[9:])
questionInstance = Questions.objects.get(pk=questionId)
q=Questions.objects.all().filter(quizId=quizInstance,questionId=questionId).values()
if(request.POST[questionno]==q[0]['answer']):
score+=q[0]['marks']
else:
score-=q[0]['negative']
t=submission(questionId=questionInstance, option=request.POST[questionno], studentId=request.user, quizId=quizInstance)
t.save()
return HttpResponse("Successfully Submitted")
return HttpResponse(f"Successfully Submitted. Score:{score}")
else:
return HttpResponse("You have already submitted this quiz")
......
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