From e14514e01052fb36cd9f14675cbe7ca940945a34 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Tue, 2 Jan 2018 16:46:52 +0530 Subject: Allowed user to skip and view solution if the answer is correct. Added solution attribute to the Question model. --- yaksh/models.py | 2 ++ yaksh/static/yaksh/js/add_question.js | 4 ++++ yaksh/static/yaksh/js/requesthandler.js | 5 +++-- yaksh/templates/yaksh/add_question.html | 2 ++ yaksh/templates/yaksh/courses.html | 9 +++++++-- yaksh/templates/yaksh/question.html | 17 +++++++++++++++++ yaksh/test_views.py | 2 +- yaksh/urls.py | 4 +++- 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 @@