diff options
author | hardythe1 | 2013-07-01 11:56:32 +0530 |
---|---|---|
committer | hardythe1 | 2013-07-01 11:56:32 +0530 |
commit | f5ef323d03dd80e1ae00f306ac44f5ee3efb3e7c (patch) | |
tree | e957b93691515c5ab50db5ed0365658263809460 /testapp | |
parent | 5ce91d1f2b2f2434bc51ddeeaf4f9f27305d1145 (diff) | |
download | online_test-f5ef323d03dd80e1ae00f306ac44f5ee3efb3e7c.tar.gz online_test-f5ef323d03dd80e1ae00f306ac44f5ee3efb3e7c.tar.bz2 online_test-f5ef323d03dd80e1ae00f306ac44f5ee3efb3e7c.zip |
edited JS to give a msg when the answer is correct
Diffstat (limited to 'testapp')
-rw-r--r-- | testapp/exam/views.py | 31 | ||||
-rw-r--r-- | testapp/static/exam/js/add_question.js | 4 | ||||
-rw-r--r-- | testapp/static/exam/js/add_quiz.js | 1 | ||||
-rw-r--r-- | testapp/static/exam/js/edit_question.js | 4 | ||||
-rw-r--r-- | testapp/templates/exam/question.html | 9 |
5 files changed, 28 insertions, 21 deletions
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() <font size=3 face=arial> {{ question.description|safe }} </font> {% if error_message %}<h5>ERROR:</h5><div class="alert alert-error">{{ error_message }}</div>{% endif %} + {% if success_msg %} + <script type="text/javascript"> + alert("Congratulations, that's correct. Let's go to next question"); + </script> + {% endif %} <p id="status"></p> <form id="code" action="{{URL_ROOT}}/exam/{{ question.id }}/check/{{ paper.question_paper.id }}/" method="post"> {% csrf_token %} @@ -87,9 +92,9 @@ function update_time() {% endfor %} {% else %} - <textarea tabindex=1 rows="3" style="width:750px;margin-bottom:15px;height:auto;" readonly=yes name="snippet" id="snippet" wrap="off">{% if last_attempt %}{% else %}{% if question.type == "bash" %} #!/bin/bash{% else %} #To avoid errors use tabs for indentation for Python questions {{ question.snippet }}{% endif %}{% endif %}</textarea> + <textarea tabindex=1 rows="3" style="width:750px;margin-bottom:15px;height:auto;" readonly=yes name="snippet" id="snippet" wrap="off">{% if last_attempt %}{{question.snippet}}{% else %}{% if question.type == "bash" %} #!/bin/bash{% else %} #To avoid errors use tabs for indentation for Python questions {{ question.snippet }}{% endif %}{% endif %}</textarea> - <textarea tabindex=1 rows="10" style="width:750px;margin-bottom:10px;" name="answer" id="answer" wrap="off" onkeydown="return catchTab(this,event)">{% if last_attempt %}{{last_attempt.strip}}{% else %}{% if question.type == "bash" %}{% else %}{% endif %}{% endif %}</textarea> + <textarea tabindex=1 rows="10" style="width:750px;margin-bottom:10px;" name="answer" id="answer" wrap="off" onkeydown="return catchTab(this,event)">{% if last_attempt %}{{last_attempt}}{% else %}{% if question.type == "bash" %}{% else %}{% endif %}{% endif %}</textarea> <br> <script type="text/javascript"> |