diff options
Diffstat (limited to 'testapp/exam/views.py')
-rw-r--r-- | testapp/exam/views.py | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/testapp/exam/views.py b/testapp/exam/views.py index 2545d8b..f21357e 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -151,6 +151,14 @@ def quizlist_user(request): context = {'quizzes': avail_quiz, 'user': user} return my_render_to_response("exam/quizzes_user.html", context) +def intro(request, questionpaper_id): + """Show introduction page before quiz starts""" + user = request.user + context = {'user': user, 'paper_id': questionpaper_id } + ci = RequestContext(request) + return my_render_to_response('exam/intro.html', context, + context_instance=ci) + def results_user(request): """Show list of Results of Quizzes that is taken by logged-in user.""" @@ -158,7 +166,11 @@ def results_user(request): papers = AnswerPaper.objects.filter(user=user) quiz_marks = [] for paper in papers: - temp = paper.question_paper.quiz.description, paper.get_total_marks() + marks_obtained = paper.get_total_marks() + max_marks = paper.question_paper.total_marks + percentage = round((marks_obtained/max_marks)*100,2) + temp = paper.question_paper.quiz.description, marks_obtained,\ + max_marks, percentage quiz_marks.append(temp) context = {'papers': quiz_marks} return my_render_to_response("exam/results_user.html", context) @@ -653,16 +665,9 @@ def start(request, questionpaper_id=None): questions = [str(_.id) for _ in questionpaper.questions.all()] random.shuffle(questions) - #questions = questionpaper.questions - #random.shuffle(questions) new_paper.questions = "|".join(questions) new_paper.save() - # Show the user the intro page. - context = {'user': user, 'paper_id': questionpaper_id} - ci = RequestContext(request) - return my_render_to_response('exam/intro.html', context, - context_instance=ci) - + return start(request, questionpaper_id) def question(request, q_id, questionpaper_id,success_msg=None): """Check the credentials of the user and start the exam.""" @@ -680,7 +685,9 @@ def question(request, q_id, questionpaper_id,success_msg=None): if not paper.question_paper.quiz.active: reason='The quiz has been deactivated!' return complete(request, reason, questionpaper_id) - + #if new: + # paper.start_time = datetime.datetime.now() + # paper.end_time = datetime.datetime.now() time_left = paper.time_left() if time_left == 0: return complete(request, reason='Your time is up!') @@ -731,7 +738,6 @@ def check(request, q_id, questionpaper_id=None): if question.type == 'mcq': # Add the answer submitted, regardless of it being correct or not. if user_answer is not None : - print "EEERRRROOOORRRRRRR :P" new_answer = Answer(question=question, answer=user_answer, correct=False) new_answer.save() @@ -790,13 +796,9 @@ def check(request, q_id, questionpaper_id=None): context_instance=ci) else: if time_left <= 0: - print "success" - print str(time_left) reason='Your time is up!' return complete(request, reason, questionpaper_id) else: - print "fail" - print time_left next_q = paper.completed_question(question.id) return show_question(request, next_q, questionpaper_id,success_msg) @@ -850,14 +852,14 @@ def complete(request, reason=None, questionpaper_id=None): return my_redirect('/exam/') -def monitor(request, quiz_id=None): +def monitor(request, questionpaper_id=None): """Monitor the progress of the papers taken so far.""" user = request.user if not user.is_authenticated() or not is_moderator(user): raise Http404('You are not allowed to view this page!') - if quiz_id is None: + if questionpaper_id is None: q_paper = QuestionPaper.objects.all() context = {'papers': [], 'quiz': None, @@ -866,15 +868,15 @@ def monitor(request, quiz_id=None): context_instance=RequestContext(request)) # quiz_id is not None. try: - quiz = QuestionPaper.objects.get(id=quiz_id) + q_paper = QuestionPaper.objects.get(id=questionpaper_id) except QuestionPaper.DoesNotExist: papers = [] - quiz = None + q_paper = None else: - papers = AnswerPaper.objects.all().annotate( + papers = AnswerPaper.objects.filter(question_paper=q_paper).annotate( total=Sum('answers__marks')).order_by('-total') - context = {'papers': papers, 'quiz': quiz, 'quizzes': None} + context = {'papers': papers, 'quiz': q_paper, 'quizzes': None} return my_render_to_response('exam/monitor.html', context, context_instance=RequestContext(request)) |