diff options
-rw-r--r-- | yaksh/templates/yaksh/monitor.html | 4 | ||||
-rw-r--r-- | yaksh/views.py | 42 |
2 files changed, 28 insertions, 18 deletions
diff --git a/yaksh/templates/yaksh/monitor.html b/yaksh/templates/yaksh/monitor.html index 52695cb..dae07e3 100644 --- a/yaksh/templates/yaksh/monitor.html +++ b/yaksh/templates/yaksh/monitor.html @@ -54,8 +54,8 @@ <tr> <td> <a href="{{URL_ROOT}}/exam/manage/user_data/{{paper.user.username}}">{{ paper.user.get_full_name.title }}</a> </td> <td> <a href="{{URL_ROOT}}/exam/manage/user_data/{{paper.user.username}}">{{ paper.user.username }}</a> </td> - <td> {{ paper.profile.roll_number }} </td> - <td> {{ paper.profile.institute }} </td> + <td> {{ paper.user.profile.roll_number }} </td> + <td> {{ paper.user.profile.institute }} </td> <td> {{ paper.get_answered_str }} </td> <td> {{ paper.marks_obtained }} </td> <td> {{ paper.answers.count }} </td> diff --git a/yaksh/views.py b/yaksh/views.py index 78f33f6..82a813c 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -876,13 +876,13 @@ def question(request, q_id, attempt_num, questionpaper_id, success_msg=None): return my_redirect('/exam/start/') if not paper.question_paper.quiz.active: reason = 'The quiz has been deactivated!' - return complete(request, reason, questionpaper_id) + return complete(request, reason, attempt_num, questionpaper_id) elif paper.end_time < datetime.datetime.now(): reason = 'You have already attempted the quiz' - return complete(request, reason, questionpaper_id) + return complete(request, reason, attempt_num, questionpaper_id) time_left = paper.time_left() if time_left == 0: - return complete(request, reason='Your time is up!') + return complete(request, attempt_num, questionpaper_id, reason='Your time is up!') quiz_name = paper.question_paper.quiz.description questions, to_attempt, submitted = get_questions(paper) if success_msg is None: @@ -933,22 +933,30 @@ def _save_skipped_answer(old_skipped, user_answer, paper, question): correct=False, skipped=True) skipped_answer.save() paper.answers.add(skipped_answer) - +def _time_check(paper): + if paper.time_left() <= 0: + return False + else: + return True def check(request, q_id, attempt_num=None, questionpaper_id=None): """Checks the answers of the user for particular question""" - user = request.user q_paper = QuestionPaper.objects.get(id=questionpaper_id) paper = AnswerPaper.objects.get(user=request.user, attempt_number=attempt_num, question_paper=q_paper) + is_time_left = _time_check(paper) + if not is_time_left: + reason = 'Your time is up!' + return complete(request, reason, attempt_num, questionpaper_id) + if q_id in paper.questions_answered: next_q = paper.skip(q_id) return show_question(request, next_q, attempt_num, questionpaper_id) if not user.is_authenticated() or paper.end_time < datetime.datetime.now(): return my_redirect('/exam/login/') - + question = get_object_or_404(Question, pk=q_id) test_cases = TestCase.objects.filter(question=question) @@ -1004,9 +1012,9 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None): new_answer.error = result.get('error') new_answer.save() - time_left = paper.time_left() + is_time_left = _time_check(paper) if not result.get('success'): # Should only happen for non-mcq questions. - if time_left == 0: + if is_time_left == 0: reason = 'Your time is up!' return complete(request, reason, attempt_num, questionpaper_id) if not paper.question_paper.quiz.active: @@ -1027,7 +1035,7 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None): return my_render_to_response('yaksh/question.html', context, context_instance=ci) else: - if time_left <= 0: + if is_time_left <= 0: reason = 'Your time is up!' return complete(request, reason, attempt_num, questionpaper_id) @@ -1114,10 +1122,17 @@ def quit(request, attempt_num=None, questionpaper_id=None): context_instance=RequestContext(request)) +def _update_marks(answer_paper): + answer_paper.update_marks_obtained() + answer_paper.update_percent() + answer_paper.update_passed() + answer_paper.update_status() + answer_paper.end_time = datetime.datetime.now() + answer_paper.save() + @login_required def complete(request, reason=None, attempt_num=None, questionpaper_id=None): """Show a page to inform user that the quiz has been compeleted.""" - user = request.user if questionpaper_id is None: logout(request) @@ -1130,12 +1145,7 @@ def complete(request, reason=None, attempt_num=None, questionpaper_id=None): q_paper = QuestionPaper.objects.get(id=questionpaper_id) paper = AnswerPaper.objects.get(user=user, question_paper=q_paper, attempt_number=attempt_num) - paper.update_marks_obtained() - paper.update_percent() - paper.update_passed() - paper.end_time = datetime.datetime.now() - paper.update_status() - paper.save() + _update_marks(paper) obt_marks = paper.marks_obtained tot_marks = paper.question_paper.total_marks if obt_marks == paper.question_paper.total_marks: |