summaryrefslogtreecommitdiff
path: root/testapp/exam
diff options
context:
space:
mode:
Diffstat (limited to 'testapp/exam')
-rw-r--r--testapp/exam/templates/exam/question.html20
-rw-r--r--testapp/exam/views.py23
2 files changed, 37 insertions, 6 deletions
diff --git a/testapp/exam/templates/exam/question.html b/testapp/exam/templates/exam/question.html
index 96e7bd6..5d03b37 100644
--- a/testapp/exam/templates/exam/question.html
+++ b/testapp/exam/templates/exam/question.html
@@ -48,7 +48,12 @@ function setSnippetHeight()
ta.style.height = height;
autoresize();
}
-
+function call_skip(url)
+{
+ form = document.forms["code"]
+ form.action = url
+ form.submit();
+}
</script>
{% endblock script %}
@@ -82,17 +87,18 @@ function setSnippetHeight()
</div>
</div>
</div>
+
<div class = container>
-<div class="sidebar">
+ <div class="sidebar">
<p>Question Navigator </p>
<div class="pagination">
<ul>
{% for qid, num in questions.items %}
{% if qid in to_attempt %}
{% if qid == question.id|slugify %}
- <li class="active"><a href="{{ URL_ROOT }}/exam/{{ qid }}/{{ paper.attempt_number }}/{{ paper.question_paper.id }}/">{{ num }}</a></li>
+ <li class="active"><a href="#" onclick="call_skip('{{ URL_ROOT }}/exam/{{ qid }}/{{ paper.attempt_number }}/{{ paper.question_paper.id }}/')">{{ num }}</a></li>
{% else %}
- <li><a href="{{ URL_ROOT }}/exam/{{ qid }}/{{ paper.attempt_number }}/{{ paper.question_paper.id }}/">{{ num }}</a></li>
+ <li><a href="#" onclick="call_skip('{{ URL_ROOT }}/exam/{{ qid }}/{{ paper.attempt_number }}/{{ paper.question_paper.id }}/')">{{ num }}</a></li>
{% endif %}
{% endif %}
{% if qid in submitted %}
@@ -101,7 +107,7 @@ function setSnippetHeight()
{% endfor %}
</ul>
</div>
-</div>
+ </div>
</div>
<h4><u> {{ question.summary }} </u><font class=pull-right>(Marks : {{ question.points }}) </font></h4><br>
@@ -117,7 +123,9 @@ function setSnippetHeight()
<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 %}
+ {% csrf_token %}
+ <input type=hidden name="question_id" id="question_id" value={{ question.id }}></input>
+
{% if question.type == "mcq" %}
{% for option in question.options.strip.splitlines %}
<input name="answer" type="radio" value="{{option}}" />{{option}} <br/>
diff --git a/testapp/exam/views.py b/testapp/exam/views.py
index 576405f..ba48b60 100644
--- a/testapp/exam/views.py
+++ b/testapp/exam/views.py
@@ -754,6 +754,29 @@ def question(request, q_id, attempt_no, questionpaper_id, success_msg=None):
def show_question(request, q_id, attempt_no, questionpaper_id, success_msg=None):
"""Show a question if possible."""
+ user = request.user
+ q_paper = QuestionPaper.objects.get(id=questionpaper_id)
+ paper = AnswerPaper.objects.get(user=request.user, attempt_number=attempt_no,
+ question_paper=q_paper)
+ if not user.is_authenticated() or paper.end_time < datetime.datetime.now():
+ return my_redirect('/exam/login/')
+ old_qid = request.POST.get('question_id')
+ if old_qid is not None:
+
+ quest = Question.objects.get(pk=old_qid)
+ user_code = request.POST.get('answer')
+ if quest.type == 'code':
+ user_answer = user_code # not taking snippet here.
+ old_skipped = paper.answers.filter(question=quest, skipped=True)
+ if old_skipped:
+ skipped_answer = old_skipped[0]
+ skipped_answer.answer=user_answer
+ skipped_answer.save()
+ else:
+ skipped_answer = Answer(question=quest, answer=user_answer,
+ correct=False, skipped=True)
+ skipped_answer.save()
+ paper.answers.add(skipped_answer)
if len(q_id) == 0:
msg = 'Congratulations! You have successfully completed the quiz.'
return complete(request, msg, attempt_no, questionpaper_id)