diff options
author | Prabhu Ramachandran | 2016-02-16 18:09:49 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2016-02-16 18:09:49 +0530 |
commit | 7e10b82ed3bceb0a2327309f634f8e4d4f8ca27b (patch) | |
tree | 65ed4ec5202176e977ef9028cc33d1726c92be79 | |
parent | 53949a87278136a9faa705bcef0bb0a474551b31 (diff) | |
parent | 712f0cc181efc2ae3d52f5ee3d180bc099f4b793 (diff) | |
download | online_test-7e10b82ed3bceb0a2327309f634f8e4d4f8ca27b.tar.gz online_test-7e10b82ed3bceb0a2327309f634f8e4d4f8ca27b.tar.bz2 online_test-7e10b82ed3bceb0a2327309f634f8e4d4f8ca27b.zip |
Merge pull request #73 from prathamesh920/marks_update_issue
Marks update issue
-rw-r--r-- | yaksh/models.py | 6 | ||||
-rw-r--r-- | yaksh/templates/yaksh/monitor.html | 6 | ||||
-rw-r--r-- | yaksh/tests.py | 8 | ||||
-rw-r--r-- | yaksh/views.py | 41 |
4 files changed, 34 insertions, 27 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index e7852d5..712c455 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -430,9 +430,9 @@ class AnswerPaper(models.Model): else: self.passed = False - def update_status(self): - """ Sets status to completed """ - self.status = 'completed' + def update_status(self, state): + """ Sets status as inprogress or completed """ + self.status = state def get_question_answers(self): """ diff --git a/yaksh/templates/yaksh/monitor.html b/yaksh/templates/yaksh/monitor.html index 52695cb..7df0569 100644 --- a/yaksh/templates/yaksh/monitor.html +++ b/yaksh/templates/yaksh/monitor.html @@ -49,16 +49,18 @@ <th> Questions answered </th> <th> Marks obtained </th> <th> Attempts </th> + <th> Status </th> </tr> {% for paper in papers %} <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> + <td> {{ paper.status }} </td> </tr> {% endfor %} </table> diff --git a/yaksh/tests.py b/yaksh/tests.py index ce1e0e2..9c67c02 100644 --- a/yaksh/tests.py +++ b/yaksh/tests.py @@ -293,6 +293,7 @@ class AnswerPaperTestCases(unittest.TestCase): '2014-06-13 12:20:19.791297') self.assertEqual(self.answerpaper.end_time, '2014-06-13 12:50:19.791297') + self.assertEqual(self.answerpaper.status, 'inprogress') def test_current_question(self): """ Test current_question() method of Answer Paper""" @@ -342,3 +343,10 @@ class AnswerPaperTestCases(unittest.TestCase): self.assertEqual(first_answer.answer, 'Demo answer') self.assertTrue(first_answer.correct) self.assertEqual(len(answered), 2) + + def test_update_status(self): + """ Test update_status method of Answer Paper""" + self.answerpaper.update_status('inprogress') + self.assertEqual(self.answerpaper.status, 'inprogress') + self.answerpaper.update_status('completed') + self.assertEqual(self.answerpaper.status, 'completed') diff --git a/yaksh/views.py b/yaksh/views.py index 78f33f6..5c81eb8 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -99,6 +99,15 @@ def fetch_questions(request): return set2 +def _update_marks(answer_paper, state='completed'): + answer_paper.update_marks_obtained() + answer_paper.update_percent() + answer_paper.update_passed() + answer_paper.update_status(state) + answer_paper.end_time = datetime.datetime.now() + answer_paper.save() + + def index(request): """The start page. """ @@ -243,12 +252,8 @@ def _check_previous_attempt(attempted_papers, already_attempted, attempt_number) return False, None, next_attempt else: previous_attempt = attempted_papers[already_attempted-1] - previous_attempt_day = previous_attempt.start_time - today = datetime.datetime.today() if previous_attempt.status == 'inprogress': - end_time = previous_attempt.end_time - quiz_time = previous_attempt.question_paper.quiz.duration*60 - if quiz_time > (today-previous_attempt_day).seconds: + if previous_attempt.time_left() > 0: return True, previous_attempt, next_attempt else: return False, previous_attempt, next_attempt @@ -876,13 +881,10 @@ 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) - 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: @@ -910,7 +912,7 @@ def show_question(request, q_id, attempt_num, questionpaper_id, success_msg=None q_paper = QuestionPaper.objects.get(id=questionpaper_id) paper = AnswerPaper.objects.get(user=request.user, attempt_number=attempt_num, question_paper=q_paper) - if not user.is_authenticated() or paper.end_time < datetime.datetime.now(): + if not user.is_authenticated(): return my_redirect('/exam/login/') if len(q_id) == 0: msg = 'Congratulations! You have successfully completed the quiz.' @@ -937,18 +939,18 @@ def _save_skipped_answer(old_skipped, user_answer, paper, question): 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) + 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(): + if not user.is_authenticated(): return my_redirect('/exam/login/') - + question = get_object_or_404(Question, pk=q_id) test_cases = TestCase.objects.filter(question=question) @@ -1004,9 +1006,10 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None): new_answer.error = result.get('error') new_answer.save() + _update_marks(paper, 'inprogress') time_left = paper.time_left() if not result.get('success'): # Should only happen for non-mcq questions. - if time_left == 0: + if time_left <= 0: reason = 'Your time is up!' return complete(request, reason, attempt_num, questionpaper_id) if not paper.question_paper.quiz.active: @@ -1117,7 +1120,6 @@ def quit(request, attempt_num=None, questionpaper_id=None): @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 +1132,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: |