diff options
author | Prabhu Ramachandran | 2011-11-08 15:29:48 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2011-11-08 15:29:48 +0530 |
commit | bed96635b1b0aac8548b6df85e96ee256e5e5bcb (patch) | |
tree | 682d25a0a5a0c7b8c923a1fa2433b2b35c969114 /exam | |
parent | 0b842b5e1e0eb7aadb5c87a3993cdcac94b34323 (diff) | |
download | online_test-bed96635b1b0aac8548b6df85e96ee256e5e5bcb.tar.gz online_test-bed96635b1b0aac8548b6df85e96ee256e5e5bcb.tar.bz2 online_test-bed96635b1b0aac8548b6df85e96ee256e5e5bcb.zip |
BUG: Fixing various issues
- Modified the question model to use description instead of question.
- Once a user completes the exam it would not allow another one to
start.
- Improved the error messages displayed on errors.
- If there is a mistake, it doesn't wipe out the old attempt so student
can modify what they submitted last.
Diffstat (limited to 'exam')
-rw-r--r-- | exam/models.py | 2 | ||||
-rw-r--r-- | exam/views.py | 32 |
2 files changed, 19 insertions, 15 deletions
diff --git a/exam/models.py b/exam/models.py index 247b362..3a8121b 100644 --- a/exam/models.py +++ b/exam/models.py @@ -13,7 +13,7 @@ class Question(models.Model): # An optional one-line summary of the question. summary = models.CharField(max_length=256) # The question text. - question = models.TextField() + description = models.TextField() # Number of points for the question. points = models.IntegerField() diff --git a/exam/views.py b/exam/views.py index 8cc239d..69d7838 100644 --- a/exam/views.py +++ b/exam/views.py @@ -29,13 +29,6 @@ def index(request): user = request.user if user.is_authenticated(): return redirect("/exam/start/") - else: - try: - ip = request.META['REMOTE_ADDR'] - Quiz.objects.get(user_ip=ip) - return redirect("/exam/complete") - except Quiz.DoesNotExist: - pass if request.method == "POST": form = UserRegisterForm(request.POST) @@ -81,7 +74,7 @@ def start(request): try: old_quiz = Quiz.objects.get(user=user) q = old_quiz.current_question() - return show_question(request, q) + return redirect('/exam/%s'%q) except Quiz.DoesNotExist: ip = request.META['REMOTE_ADDR'] key = gen_key(10) @@ -109,8 +102,11 @@ def question(request, q_id): context_instance=ci) def test_answer(func_code, test_code): - exec func_code - exec test_code + obj = compile(func_code, '<string>', mode='exec') + g = {} + exec obj in g + t = compile(test_code, '<string>', mode='exec') + exec t in g def check(request, q_id): user = request.user @@ -125,20 +121,28 @@ def check(request, q_id): # Otherwise we were asked to check. retry = True + tb = None try: test_answer(answer, question.test) - except: + except AssertionError: type, value, tb = sys.exc_info() info = traceback.extract_tb(tb) fname, lineno, func, text = info[-1] - err = "{0}: {1} In code: {2}".format(type.__name__, str(value), text) + text = str(question.test).splitlines()[lineno-1] + err = "{0} {1} in: {2}".format(type.__name__, str(value), text) + except: + type, value = sys.exc_info()[:2] + err = "Error: {0}".format(repr(value)) else: retry = False err = 'Correct answer' - + finally: + del tb + ci = RequestContext(request) if retry: - context = {'question': question, 'error_message': err} + context = {'question': question, 'error_message': err, + 'last_attempt': answer} return render_to_response('exam/question.html', context, context_instance=ci) else: |