summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
authorankitjavalkar2017-03-03 16:35:18 +0530
committerankitjavalkar2017-03-06 17:35:17 +0530
commitd0d4c9ab3a409c68766bc044825bf22b0519f6a3 (patch)
tree2204a5b84caa3db7595c9ad6341964166b146190 /yaksh
parent0f2a42799d3140de132c203cc255516caa69d617 (diff)
downloadonline_test-d0d4c9ab3a409c68766bc044825bf22b0519f6a3.tar.gz
online_test-d0d4c9ab3a409c68766bc044825bf22b0519f6a3.tar.bz2
online_test-d0d4c9ab3a409c68766bc044825bf22b0519f6a3.zip
Multiple changes:
- Fix movement from one question to another in next_question - Fix random display of errors from MCQs - Add Notification display if question has been attempted - Fix test cases for changes made
Diffstat (limited to 'yaksh')
-rw-r--r--yaksh/models.py6
-rw-r--r--yaksh/templates/yaksh/question.html24
-rw-r--r--yaksh/test_models.py8
-rw-r--r--yaksh/views.py17
4 files changed, 32 insertions, 23 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index b80482c..f0f4ca6 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -1000,8 +1000,8 @@ class AnswerPaper(models.Model):
Skips the current question and returns the next sequentially
available question.
"""
- unanswered_questions = self.questions_unanswered.all()
- questions = list(unanswered_questions.values_list('id', flat=True))
+ all_questions = self.questions.all()
+ questions = list(all_questions.values_list('id', flat=True))
if len(questions) == 0:
return None
try:
@@ -1009,7 +1009,7 @@ class AnswerPaper(models.Model):
next_id = questions[index+1]
except (ValueError, IndexError):
next_id = questions[0]
- return unanswered_questions.get(id=next_id)
+ return all_questions.get(id=next_id)
def time_left(self):
"""Return the time remaining for the user in seconds."""
diff --git a/yaksh/templates/yaksh/question.html b/yaksh/templates/yaksh/question.html
index 1f6e67d..f94298e 100644
--- a/yaksh/templates/yaksh/question.html
+++ b/yaksh/templates/yaksh/question.html
@@ -135,13 +135,19 @@ function call_skip(url)
{% block onload %} onload="updateTime();" {% endblock %}
{% block main %}
- <p id="status"></p>
- <form id="code" action="{{URL_ROOT}}/exam/{{ question.id }}/check/{{ paper.attempt_number }}/{{ paper.question_paper.id }}/" method="post" enctype="multipart/form-data">
- {% csrf_token %}
- <input type=hidden name="question_id" id="question_id" value={{ question.id }}></input>
- <div class="panel panel-default">
- <div class="panel-heading">
- <h4><u> {{ question.summary }}
+ <p id="status"></p>
+ {% if notification %}
+ <div class="alert alert-warning" role="alert">
+ <strong>Note:</strong> {{ notification }}
+ </div>
+ {% endif %}
+ <form id="code" action="{{URL_ROOT}}/exam/{{ question.id }}/check/{{ paper.attempt_number }}/{{ paper.question_paper.id }}/" method="post" enctype="multipart/form-data">
+ {% csrf_token %}
+ <input type=hidden name="question_id" id="question_id" value={{ question.id }}></input>
+ <div class="panel panel-default">
+ <div class="panel-heading">
+ <h4>
+ <u> {{ question.summary }}
{% if question.type == "mcq" %}
(Single Correct Choice Questions)
{% elif question.type == "mcc" %}
@@ -151,8 +157,8 @@ function call_skip(url)
{% elif question.type == "upload" %}
(ASSIGNMENT UPLOAD)
{% endif %}
- </u>
- <font class=pull-right>(Marks : {{ question.points }}) </font>
+ </u>
+ <font class=pull-right>(Marks : {{ question.points }}) </font>
</h4>
<font size=3 face=arial> {{ question.description|safe }} </font>
{% if files %}
diff --git a/yaksh/test_models.py b/yaksh/test_models.py
index a8d48e2..b6934e3 100644
--- a/yaksh/test_models.py
+++ b/yaksh/test_models.py
@@ -694,7 +694,7 @@ class AnswerPaperTestCases(unittest.TestCase):
# Then
self.assertTrue(next_question_id is not None)
- self.assertEqual(next_question_id.id, 2)
+ self.assertEqual(next_question_id.id, 1)
# Given, last question in the list
current_question_id = 3
@@ -704,7 +704,7 @@ class AnswerPaperTestCases(unittest.TestCase):
# Then
self.assertTrue(next_question_id is not None)
- self.assertEqual(next_question_id.id, 2)
+ self.assertEqual(next_question_id.id, 1)
# Test get_questions_answered() method
# When
@@ -735,13 +735,13 @@ class AnswerPaperTestCases(unittest.TestCase):
# Then
self.assertEqual(self.answerpaper.questions_left(), 0)
- self.assertTrue(current_question is None)
+ self.assertTrue(current_question is not None)
# When
next_question_id = self.answerpaper.next_question(current_question_id)
# Then
- self.assertTrue(next_question_id is None)
+ self.assertTrue(next_question_id is not None)
def test_update_marks(self):
""" Test update_marks method of AnswerPaper"""
diff --git a/yaksh/views.py b/yaksh/views.py
index 16299a8..163c12f 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -400,7 +400,7 @@ def start(request, questionpaper_id=None, attempt_num=None):
@login_required
-def show_question(request, question, paper, error_message=None):
+def show_question(request, question, paper, error_message=None, notification=None):
"""Show a question if possible."""
user = request.user
if not question:
@@ -412,10 +412,12 @@ def show_question(request, question, paper, error_message=None):
if paper.time_left() <= 0:
reason='Your time is up!'
return complete(request, reason, paper.attempt_number, paper.question_paper.id)
+ if question in paper.questions_answered.all():
+ notification = 'You have already attempted this question'
test_cases = question.get_test_cases()
files = FileUpload.objects.filter(question_id=question.id, hide=False)
context = {'question': question, 'paper': paper, 'error_message': error_message,
- 'test_cases': test_cases, 'files': files,
+ 'test_cases': test_cases, 'files': files, 'notification': notification,
'last_attempt': question.snippet.encode('unicode-escape')}
answers = paper.get_previous_answers(question)
if answers:
@@ -472,14 +474,14 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None):
assign.assignmentFile = request.FILES['assignment']
assign.save()
user_answer = 'ASSIGNMENT UPLOADED'
- next_q = paper.completed_question(current_question.id)
+ next_q = paper.add_completed_question(current_question.id)
return show_question(request, next_q, paper)
else:
user_code = request.POST.get('answer')
user_answer = snippet_code + "\n" + user_code if snippet_code else user_code
if not user_answer:
msg = ["Please submit a valid option or code"]
- return show_question(request, current_question, paper, msg)
+ return show_question(request, current_question, paper, notification=msg)
new_answer = Answer(question=current_question, answer=user_answer,
correct=False, error=json.dumps([]))
new_answer.save()
@@ -497,15 +499,16 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None):
new_answer.correct = result.get('success')
error_message = None
new_answer.error = json.dumps(result.get('error'))
- next_question = paper.completed_question(current_question.id)
+ next_question = paper.add_completed_question(current_question.id)
else:
new_answer.marks = (current_question.points * result['weight'] /
current_question.get_maximum_test_case_weight()) \
if current_question.partial_grading and current_question.type == 'code' else 0
- error_message = result.get('error')
+ error_message = result.get('error') if current_question.type == 'code' \
+ else None
new_answer.error = json.dumps(result.get('error'))
next_question = current_question if current_question.type == 'code' \
- else paper.completed_question(current_question.id)
+ else paper.add_completed_question(current_question.id)
new_answer.save()
paper.update_marks('inprogress')
paper.set_end_time(timezone.now())