diff options
author | prathamesh | 2018-01-02 16:46:52 +0530 |
---|---|---|
committer | prathamesh | 2018-01-02 16:46:52 +0530 |
commit | e14514e01052fb36cd9f14675cbe7ca940945a34 (patch) | |
tree | 994f3d5dd6d8c4f3614d3b1a655c91caa7426dcf | |
parent | 7fe8e17438b8e67e7290f11ddcd29cda3953921b (diff) | |
download | online_test-e14514e01052fb36cd9f14675cbe7ca940945a34.tar.gz online_test-e14514e01052fb36cd9f14675cbe7ca940945a34.tar.bz2 online_test-e14514e01052fb36cd9f14675cbe7ca940945a34.zip |
Allowed user to skip and view solution if the answer is correct.
Added solution attribute to the Question model.
-rw-r--r-- | yaksh/models.py | 2 | ||||
-rw-r--r-- | yaksh/static/yaksh/js/add_question.js | 4 | ||||
-rw-r--r-- | yaksh/static/yaksh/js/requesthandler.js | 5 | ||||
-rw-r--r-- | yaksh/templates/yaksh/add_question.html | 2 | ||||
-rw-r--r-- | yaksh/templates/yaksh/courses.html | 9 | ||||
-rw-r--r-- | yaksh/templates/yaksh/question.html | 17 | ||||
-rw-r--r-- | yaksh/test_views.py | 2 | ||||
-rw-r--r-- | yaksh/urls.py | 4 | ||||
-rw-r--r-- | yaksh/views.py | 9 |
9 files changed, 43 insertions, 11 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index 839043f..aa65ad9 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -751,6 +751,8 @@ class Question(models.Model): min_time = models.IntegerField("time in minutes", default=0) + solution = models.TextField(blank=True) + def consolidate_answer_data(self, user_answer, user=None): question_data = {} metadata = {} diff --git a/yaksh/static/yaksh/js/add_question.js b/yaksh/static/yaksh/js/add_question.js index 5bec8c6..346991a 100644 --- a/yaksh/static/yaksh/js/add_question.js +++ b/yaksh/static/yaksh/js/add_question.js @@ -110,6 +110,9 @@ function textareaformat() document.getElementById('my').innerHTML = document.getElementById('id_description').value ; }); + $('#id_solution').bind('keypress', function (event){ + document.getElementById('rend_solution').innerHTML = document.getElementById('id_solution').value ; + }); $('#id_type').bind('focus', function(event){ var type = document.getElementById('id_type'); @@ -121,6 +124,7 @@ function textareaformat() language.style.border = '1px solid #ccc'; }); document.getElementById('my').innerHTML = document.getElementById('id_description').value ; + document.getElementById('rend_solution').innerHTML = document.getElementById('id_solution').value ; if (document.getElementById('id_grade_assignment_upload').checked || document.getElementById('id_type').value == 'upload'){ diff --git a/yaksh/static/yaksh/js/requesthandler.js b/yaksh/static/yaksh/js/requesthandler.js index f50570b..a24c1f1 100644 --- a/yaksh/static/yaksh/js/requesthandler.js +++ b/yaksh/static/yaksh/js/requesthandler.js @@ -36,7 +36,8 @@ function unlock_screen() { document.getElementById("ontop").style.display = "none"; } -function show_skip() { +function show_solution() { + document.getElementById("solution").style.display = "block"; document.getElementById("skip_ex").style.visibility = "visible"; } @@ -109,7 +110,7 @@ var global_editor = {}; $(document).ready(function(){ if(is_exercise == "True" && can_skip == "False"){ - setTimeout(function() {show_skip();}, delay_time*1000); + setTimeout(function() {show_solution();}, delay_time*1000); } // Codemirror object, language modes and initial content // Get the textarea node diff --git a/yaksh/templates/yaksh/add_question.html b/yaksh/templates/yaksh/add_question.html index c294d9a..4ec9bee 100644 --- a/yaksh/templates/yaksh/add_question.html +++ b/yaksh/templates/yaksh/add_question.html @@ -24,6 +24,8 @@ <tr><td><strong>Rendered: </strong><td><p id='my'></p> <tr><td>Description: <td>{{ qform.description}} {{qform.description.errors}} <tr><td>Tags: <td>{{ qform.tags }} + <tr><td><strong>Rendered Solution: </strong><td><p id='rend_solution'></p> + <tr><td>Solution: <td>{{ qform.solution }} <tr><td>Snippet: <td>{{ qform.snippet }} <tr><td>Minimum Time(in minutes):<td> {{ qform.min_time }} <tr><td>Partial Grading: <td>{{ qform.partial_grading }} diff --git a/yaksh/templates/yaksh/courses.html b/yaksh/templates/yaksh/courses.html index a06ee7e..a41c8c3 100644 --- a/yaksh/templates/yaksh/courses.html +++ b/yaksh/templates/yaksh/courses.html @@ -151,8 +151,13 @@ <ul class="inputs-list"> <li> {% if unit.learning_type == "quiz" %} - <a href="{{URL_ROOT}}/exam/manage/addquiz/{{unit.quiz.id}}/{{course.id}}"> - {{unit.quiz.description}}</a> + {% if unit.quiz.is_exercise %} + <a href="{{URL_ROOT}}/exam/manage/add_exercise/{{unit.quiz.id}}/{{course.id}}"> + {{unit.quiz.description}}</a> + {% else %} + <a href="{{URL_ROOT}}/exam/manage/addquiz/{{unit.quiz.id}}/{{course.id}}"> + {{unit.quiz.description}}</a> + {% endif %} {% else %} <a href="{{URL_ROOT}}/exam/manage/courses/edit_lesson/{{unit.lesson.id}}/{{course.id}}"> {{unit.lesson.name}}</a> diff --git a/yaksh/templates/yaksh/question.html b/yaksh/templates/yaksh/question.html index 978d226..c9a5211 100644 --- a/yaksh/templates/yaksh/question.html +++ b/yaksh/templates/yaksh/question.html @@ -192,6 +192,23 @@ function call_skip(url) <h5><a href="{{f_name.file.url}}">{{f_name.file.name}}</a></h5> {% endfor %} {% endif %} + + {% if quiz.is_exercise %} + {% if question.solution %} + <h4><u> Solution by teacher</u></h4> + {% else %} + <h4><u> No solution provided by teacher </u></h4> + {% endif%} + {% if can_skip %} + <div id="solution"> + <font size=3 face=arial> {{ question.solution|safe }} </font> + </div> + {% else %} + <div id="solution" style="display:none"> + <font size=3 face=arial> {{ question.solution|safe }} </font> + </div> + {% endif %} + {% endif %} </div> <div class="panel-body"> {% if question.type == "mcq" %} diff --git a/yaksh/test_views.py b/yaksh/test_views.py index 38564a1..129378f 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -1226,7 +1226,7 @@ class TestAddQuiz(TestCase): password=self.user_plaintext_pass ) tzone = pytz.timezone('UTC') - response = self.client.post(reverse('yaksh:add_exercise', + response = self.client.post(reverse('yaksh:edit_exercise', kwargs={'quiz_id': self.exercise.id}), data={ 'description': 'updated demo exercise', diff --git a/yaksh/urls.py b/yaksh/urls.py index f7df456..b4bbb41 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -51,7 +51,9 @@ urlpatterns = [ url(r'^manage/addquiz/$', views.add_quiz, name='add_quiz'), url(r'^manage/add_exercise/$', views.add_exercise, name='add_exercise'), url(r'^manage/add_exercise/(?P<quiz_id>\d+)/$', views.add_exercise, - name='add_exercise'), + name='edit_exercise'), + url(r'^manage/add_exercise/(?P<quiz_id>\d+)/(?P<course_id>\d+)/$', + views.add_exercise, name='edit_exercise'), url(r'^manage/addquiz/(?P<quiz_id>\d+)/$', views.add_quiz, name='edit_quiz'), url(r'^manage/addquiz/(?P<quiz_id>\d+)/(?P<course_id>\d+)$', diff --git a/yaksh/views.py b/yaksh/views.py index 302ef9e..fd07ade 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -568,7 +568,7 @@ def show_question(request, question, paper, error_message=None, notification=Non delay_time = paper.time_left_on_question(question) if previous_question and quiz.is_exercise: - if delay_time <= 0: + if delay_time <= 0 or previous_question in paper.questions_answered.all(): can_skip = True question = previous_question if not question: @@ -639,9 +639,8 @@ def skip(request, q_id, next_q=None, attempt_num=None, questionpaper_id=None, question = get_object_or_404(Question, pk=q_id) if paper.question_paper.quiz.is_exercise: - if paper.time_left_on_question(question) <= 0: - paper.start_time = timezone.now() - paper.save() + paper.start_time = timezone.now() + paper.save() if request.method == 'POST' and question.type == 'code': if not paper.answers.filter(question=question, correct=True).exists(): @@ -775,7 +774,7 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None, user_answer, current_question, json_data, uid ) if current_question.type in ['code', 'upload']: - if paper.time_left() <= 0: + if paper.time_left() <= 0 and not paper.question_paper.quiz.is_exercise: url = 'http://localhost:%s' % SERVER_POOL_PORT result_details = get_result_from_code_server(url, uid, block=True) result = json.loads(result_details.get('result')) |