From f5ef323d03dd80e1ae00f306ac44f5ee3efb3e7c Mon Sep 17 00:00:00 2001 From: hardythe1 Date: Mon, 1 Jul 2013 11:56:32 +0530 Subject: edited JS to give a msg when the answer is correct --- testapp/exam/views.py | 31 ++++++++++++++++++++----------- testapp/static/exam/js/add_question.js | 4 +--- testapp/static/exam/js/add_quiz.js | 1 - testapp/static/exam/js/edit_question.js | 4 ---- testapp/templates/exam/question.html | 9 +++++++-- 5 files changed, 28 insertions(+), 21 deletions(-) (limited to 'testapp') diff --git a/testapp/exam/views.py b/testapp/exam/views.py index 6c977ee..4b9d438 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -218,10 +218,10 @@ def edit_question(request): question.points = points[j] question.test = test[j] question.options = options[j] - question.type = type[j] - edit_tags = tags[j] question.active = active[j] question.snippet = snippet[j] + question.type = type[j] + edit_tags = tags[j] question.save() for tag in question.tags.all(): question.tags.remove(tag) @@ -264,7 +264,7 @@ def add_question(request, question_id=None): question = Question.objects.get(id=question_id) for tag in question.tags.all(): question.tags.remove(tag) - tags = form['tags'].data.split(', ') + tags = form['tags'].data.split(',') for i in range(0, len(tags)-1): tag = tags[i].strip() question.tags.add(tag) @@ -303,7 +303,7 @@ def add_question(request, question_id=None): def add_quiz(request, quiz_id=None): """To add a new quiz in the database. - Create a new question and store it.""" + Create a new quiz and store it.""" user = request.user if not user.is_authenticated() or not is_moderator(user): @@ -638,7 +638,7 @@ def start(request, questionpaper_id=None): context_instance=ci) -def question(request, q_id, questionpaper_id): +def question(request, q_id, questionpaper_id,success_msg=None): """Check the credentials of the user and start the exam.""" user = request.user @@ -658,21 +658,29 @@ def question(request, q_id, questionpaper_id): if time_left == 0: return complete(request, reason='Your time is up!') quiz_name = paper.question_paper.quiz.description - context = {'question': q, 'paper': paper, 'user': user, - 'quiz_name': quiz_name, - 'time_left': time_left} + if success_msg is None: + context = {'question': q, 'paper': paper, 'user': user, + 'quiz_name': quiz_name, + 'time_left': time_left,} + + else: + context = {'question': q, 'paper': paper, 'user': user, + 'quiz_name': quiz_name, + 'time_left': time_left, + 'success_msg':success_msg} + ci = RequestContext(request) return my_render_to_response('exam/question.html', context, context_instance=ci) -def show_question(request, q_id, questionpaper_id): +def show_question(request, q_id, questionpaper_id,success_msg=None): """Show a question if possible.""" if len(q_id) == 0: msg = 'Congratulations! You have successfully completed the quiz.' return complete(request, msg) else: - return question(request, q_id, questionpaper_id) + return question(request, q_id, questionpaper_id,success_msg) def check(request, q_id, questionpaper_id=None): @@ -745,7 +753,8 @@ def check(request, q_id, questionpaper_id=None): context_instance=ci) else: next_q = paper.completed_question(question.id) - return show_question(request, next_q, questionpaper_id) + success_msg = True + return show_question(request, next_q, questionpaper_id,success_msg) def quit(request, answerpaper_id=None): diff --git a/testapp/static/exam/js/add_question.js b/testapp/static/exam/js/add_question.js index ab27dc0..a77e392 100644 --- a/testapp/static/exam/js/add_question.js +++ b/testapp/static/exam/js/add_question.js @@ -139,9 +139,7 @@ function textareaformat() $('#id_snippet').bind('blur', function( event ){ document.getElementById("id_snippet").rows=1; document.getElementById("id_snippet").cols=40; - $('#id_snippet').val("#To avoid indentation errors use tabs for indentation for Python questions"); - }); - + }); $('#id_type').bind('change',function(event){ var value = document.getElementById('id_type').value; if(value == 'mcq') diff --git a/testapp/static/exam/js/add_quiz.js b/testapp/static/exam/js/add_quiz.js index 56b0e95..d5688a8 100644 --- a/testapp/static/exam/js/add_quiz.js +++ b/testapp/static/exam/js/add_quiz.js @@ -2,7 +2,6 @@ function test() { if (document.getElementById("id_description").value != "") { - alert("reached condition"); document.getElementById("submit").innerHTML = "Save"; } } diff --git a/testapp/static/exam/js/edit_question.js b/testapp/static/exam/js/edit_question.js index 023b654..2cf304c 100644 --- a/testapp/static/exam/js/edit_question.js +++ b/testapp/static/exam/js/edit_question.js @@ -154,10 +154,6 @@ function textareaformat() this.rows = 5; $(snippet_id).val(""); }); - $(snippet_id).bind('blur',function(event){ - this.rows = 1; - $(snippet_id).val("#To avoid indentation errors use tab for indentation for Python questions"); - }); $(snippet_id).bind('keydown', function (event){ catchTab(snippet_id,event); }); diff --git a/testapp/templates/exam/question.html b/testapp/templates/exam/question.html index 1d801b0..1282130 100644 --- a/testapp/templates/exam/question.html +++ b/testapp/templates/exam/question.html @@ -78,6 +78,11 @@ function update_time() {{ question.description|safe }} {% if error_message %}