diff options
author | Prabhu Ramachandran | 2011-11-15 01:23:48 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2011-11-15 01:23:48 +0530 |
commit | eb98b1b563fd664050fae8e663760a7573b12fb3 (patch) | |
tree | df6af4f7871fbef85290dfa2b3722a943686a1b1 | |
parent | 019ad81a980aabb30d5f5ff205f696bab6d1a79a (diff) | |
download | online_test-eb98b1b563fd664050fae8e663760a7573b12fb3.tar.gz online_test-eb98b1b563fd664050fae8e663760a7573b12fb3.tar.bz2 online_test-eb98b1b563fd664050fae8e663760a7573b12fb3.zip |
ENH: Saving the answer before evaluation.
This is useful for debugging if we have a runaway loop or some stupid
error with the code server. Also fixed a small issue with rendering the
monitor when there are users with no profile but with a quiz in the
system (like the admin).
-rw-r--r-- | exam/views.py | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/exam/views.py b/exam/views.py index 7330197..c9d8b7a 100644 --- a/exam/views.py +++ b/exam/views.py @@ -145,18 +145,22 @@ def check(request, q_id): if skip is not None: next_q = quiz.skip() return show_question(request, next_q) + + # Add the answer submitted, regardless of it being correct or not. + new_answer = Answer(question=question, answer=answer, correct=False) + new_answer.save() + quiz.answers.add(new_answer) # Otherwise we were asked to check. We obtain the results via XML-RPC # with the code executed safely in a separate process (the python_server.py) # running as nobody. user_dir = get_user_dir(user) success, err_msg = python_server.run_code(answer, question.test, user_dir) - - # Add the answer submitted. - new_answer = Answer(question=question, answer=answer.strip()) - new_answer.correct = success - new_answer.save() - quiz.answers.add(new_answer) + + if success: + # Note the success and save it. + new_answer.correct = success + new_answer.save() ci = RequestContext(request) if not success: @@ -196,8 +200,13 @@ def monitor(request): for quiz in quizzes: paper = {} user = quiz.user + try: + profile = Profile.objects.get(user=user) + except Profile.DoesNotExist: + # Admin user may have a quiz by accident but no profile. + continue paper['username'] = str(user.first_name) + ' ' + str(user.last_name) - paper['rollno'] = str(Profile.objects.get(user=user).roll_number) + paper['rollno'] = str(profile.roll_number) qa = quiz.questions_answered.split('|') answered = ', '.join(sorted(qa)) paper['answered'] = answered if answered else 'None' |