Commit c77170e7 authored by Samarth Joshi's avatar Samarth Joshi

Adding Status of quiz in table

parent 35f1f129
......@@ -27,12 +27,31 @@ class quiz(models.Model):
quizInstructor=models.ForeignKey(to=User, on_delete=models.CASCADE)
"""The instructor who created the quiz"""
@property
def start_datetime( self ):
starttime = datetime.datetime.combine( self.date, self.startTime if self.startTime is not None else datetime.time.min )
return starttime
@property
def end_datetime( self ):
starttime = datetime.datetime.combine( self.date, self.startTime if self.startTime is not None else datetime.time.min )
endtime = starttime + datetime.timedelta(minutes=self.length)
return endtime
@property
def status( self ):
stt = self.start_datetime
end = self.end_datetime
cur = datetime.datetime.now()
if stt<=cur and cur<=end:
return "Ongoing"
elif cur>end:
return "Ended"
elif cur<stt:
return "Scheduled"
else:
return "NA"
def __str__(self):
return str(self.quizId)
......
......@@ -61,12 +61,12 @@
<h1 class="heading">ALL Quizzes</h1>
<section class="table_wrapper">
<table cellspacing="0" id="myTable">
<thead><th>Code</th><th>Quiz Name</th><th>Organized By</th><th>Date</th><th>Time</th><th>Duration</th><th>Attempt quiz</th></thead>
<thead><th>Code</th><th>Quiz Name</th><th>Organized By</th><th>Date</th><th>Time</th><th>Duration</th><th>Status</th><th>Attempt quiz</th></thead>
<tbody>
{%for quiz in quizId%}
<tr>
<td>{{quiz.quizCode}}</td><td>{{quiz.quizInfo}}</td><td>{{quiz.quizInstructor}}</td><td>{{quiz.date}}</td><td>{{quiz.startTime}}</td><td>{{quiz.length}} minutes</td><td> <button onclick="start_quiz({{quiz.quizId}})" class="action_btn" type="button">Start</button></td>
<td>{{quiz.quizCode}}</td><td>{{quiz.quizInfo}}</td><td>{{quiz.quizInstructor}}</td><td>{{quiz.date}}</td><td>{{quiz.startTime}}</td><td>{{quiz.length}} minutes</td><td>{{quiz.status}}</td><td>{%if quiz.status == "Ended" %} - {%else%}<button onclick="start_quiz({{quiz.quizId}})" class="action_btn" type="button">Start Quiz</button>{%endif%}</td>
</tr>
{%endfor%}
</tbody>
......@@ -84,7 +84,10 @@
}
$(document).ready( function () {
$('#myTable').DataTable();
$('#myTable').DataTable({
/* Disable initial sort */
"aaSorting": []
});
} );
</script>
</body>
......
......@@ -82,7 +82,10 @@
}
$(document).ready( function () {
$('#myTable').DataTable();
$('#myTable').DataTable({
/* Disable initial sort */
"aaSorting": []
});
} );
</script>
</body>
......
......@@ -46,8 +46,15 @@ def index(request):
"""
quiz_id = int(request.GET['q'])
quizInstance = quiz.objects.get(pk=quiz_id)
obj = Questions.objects.filter(quizId=quizInstance).all().order_by('questionId')
endtime = quizInstance.end_datetime
curtime = datetime.now()
if curtime >= endtime:
return HttpResponse("Quiz has already ended")
prev_subm = submission.objects.all().filter(quizId=quizInstance, studentId=request.user)
if len(prev_subm) != 0:
return HttpResponse("You have already submitted this quiz")
endtime = json.dumps(endtime.isoformat())
count = len(obj)
return render(request,'index.html',{'questions':obj,'count':count, 'endtime': endtime, 'quizId': quiz_id})
......
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