Commit d980ce4b authored by Roshan Rabinarayan's avatar Roshan Rabinarayan

add submission to the quiz

parent b2696eb8
No preview for this file type
...@@ -2,5 +2,6 @@ from django.contrib import admin ...@@ -2,5 +2,6 @@ from django.contrib import admin
# Register your models here. # Register your models here.
from .models import Questions from .models import Questions
from .models import submission
admin.site.register(Questions) admin.site.register(Questions)
admin.site.register(submission)
# Generated by Django 2.2.7 on 2020-10-20 07:55
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('quiz', '0004_auto_20201020_0733'),
]
operations = [
migrations.AlterField(
model_name='questions',
name='questionId',
field=models.AutoField(primary_key=True, serialize=False),
),
]
...@@ -16,7 +16,7 @@ class Questions(models.Model): ...@@ -16,7 +16,7 @@ class Questions(models.Model):
explainations=models.TextField(max_length=1000,default='No Explaination Given') explainations=models.TextField(max_length=1000,default='No Explaination Given')
quizId = models.CharField(max_length=100,default=10) quizId = models.CharField(max_length=100,default=10)
questionId=models.AutoField(primary_key=True,) questionId=models.AutoField(primary_key=True,)
class submission(models.Model): class submission(models.Model):
#submission( questionid,selectedoption, quizid, studentid) #submission( questionid,selectedoption, quizid, studentid)
questionId=models.CharField(max_length=100) questionId=models.CharField(max_length=100)
......
window.onload = initall; window.onload = initall;
var save ; var save ;
var quizId;
var questionId;
function initall() { function initall() {
save=document.getElementById('save_ans')//save_ans save=document.getElementById('save_ans')//save_ans
save.onclick = save_ans; save.onclick = save_ans;
} }
function save_ans() { function save_ans() {
var ans = $("input:radio[name=name]:checked").val() var ans = $("input:radio[name=name]:checked").val()
var url = '/save_ans?ans='+ans var url = '/save_ans?ans='+ans+'&quizId='+document.getElementById('quizId').innerHTML+'&questionId='+document.getElementById('questionId').innerHTML
var req = new XMLHttpRequest(); var req = new XMLHttpRequest();
req.onreadystatechange = function() { req.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) { if (this.readyState == 4 && this.status == 200) {
......
...@@ -8,9 +8,12 @@ ...@@ -8,9 +8,12 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head> </head>
<body> <body>
<center><h1>Question {{ questions.end_index }} of {{count}}</h1></center>
<center><h1>
{{questions.quizId}}Question {{ questions.end_index }} of {{count}}</h1></center>
<div > <div >
{% for i in questions%} {% for i in questions%}
<h1 id ='quizId'>{{i.quizId}}<h1><h1 id ='questionId' hidden>{{i.questionId}} </h1>
<h1>{{i.question}}</h1> <h1>{{i.question}}</h1>
<form> <form>
<div > <div >
...@@ -28,7 +31,7 @@ ...@@ -28,7 +31,7 @@
</form> </form>
{%endfor%} {%endfor%}
<div > <div >
<button id="save_ans" clicked>Submit Answer</button> <button id="save_ans" >Submit Answer</button>
</div> </div>
<div > <div >
<div> <div>
......
<html> <html>
<body> <body>
<form name = "form" enctype = "multipart/form-data" <form name = "form" enctype = "multipart/form-data"
action = "{% url "uploaded" %}" method = "POST" >{% csrf_token %} action = "{% url "uploaded" %}" method = "POST" >{% csrf_token %}
......
...@@ -4,6 +4,7 @@ from . models import Questions ...@@ -4,6 +4,7 @@ from . models import Questions
from django.core.paginator import Paginator from django.core.paginator import Paginator
from .forms import UploadFileForm from .forms import UploadFileForm
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from .models import submission
from . newQuiz import readCSV from . newQuiz import readCSV
import csv import csv
lst = [] lst = []
...@@ -19,7 +20,7 @@ for i in answers: ...@@ -19,7 +20,7 @@ for i in answers:
negative.append(i.negative) negative.append(i.negative)
def index(request): def index(request):
obj = Questions.objects.all() obj = Questions.objects.get_queryset().order_by('questionId')
count = Questions.objects.all().count() count = Questions.objects.all().count()
paginator = Paginator(obj,1) paginator = Paginator(obj,1)
try: try:
...@@ -50,6 +51,11 @@ def result(request): ...@@ -50,6 +51,11 @@ def result(request):
def save_ans(request): def save_ans(request):
ans = request.GET['ans'] ans = request.GET['ans']
quizId=request.GET['quizId']
questionId=request.GET['questionId']
studentId=1# initialize here student id
t=submission(questionId=questionId,option=ans,quizId=quizId,studentId=studentId)
t.save()
lst.append(ans) lst.append(ans)
return HttpResponse('') return HttpResponse('')
......
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