summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorprathamesh2015-04-07 15:33:23 +0530
committerprathamesh2015-04-07 15:33:23 +0530
commitbcfaf246852cb90a519aab3d0cea21599fd1fd55 (patch)
treeb5646fa2d68373310bbf55e75cf15bb8f3b2e333
parent1e26be51bc269fc3884d75ace33bfd6c4627547f (diff)
parentb0551e3cb8dc59fb83ea622375c9e53003fcb489 (diff)
downloadonline_test-bcfaf246852cb90a519aab3d0cea21599fd1fd55.tar.gz
online_test-bcfaf246852cb90a519aab3d0cea21599fd1fd55.tar.bz2
online_test-bcfaf246852cb90a519aab3d0cea21599fd1fd55.zip
Question navigator implemented
-rw-r--r--testapp/exam/static/exam/css/base.css70
-rw-r--r--testapp/exam/templates/exam/question.html24
-rw-r--r--testapp/exam/urls.py1
-rw-r--r--testapp/exam/views.py57
4 files changed, 139 insertions, 13 deletions
diff --git a/testapp/exam/static/exam/css/base.css b/testapp/exam/static/exam/css/base.css
index 051ba22..3570098 100644
--- a/testapp/exam/static/exam/css/base.css
+++ b/testapp/exam/static/exam/css/base.css
@@ -245,7 +245,30 @@ body {
.container:after {
clear: both;
}
-
+.container-fluid {
+ position: relative;
+ min-width: 940px;
+ padding-left: 20px;
+ padding-right: 20px;
+ zoom: 1;
+}
+.container-fluid:before, .container-fluid:after {
+ display: table;
+ content: "";
+ zoom: 1;
+}
+.container-fluid:after {
+ clear: both;
+}
+.container-fluid > .sidebar {
+ position: absolute;
+ top: 0;
+ left: 20px;
+ width: 220px;
+}
+.container-fluid > .content {
+ margin-left: 240px;
+}
a {
color: #0069d6;
text-decoration: none;
@@ -2257,3 +2280,48 @@ button.btn::-moz-focus-inner, input[type=submit].btn::-moz-focus-inner {
.tab-content > .active, .pill-content > .active {
display: block;
}
+.pagination {
+ height: 36px;
+ margin: 18px 0;
+}
+.pagination ul {
+ float: left;
+ margin: 0;
+ border: 1px solid #ddd;
+ border: 1px solid rgba(0, 0, 0, 0.15);
+ -webkit-border-radius: 3px;
+ -moz-border-radius: 3px;
+ border-radius: 3px;
+ -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
+ -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
+ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
+}
+.pagination li {
+ display: inline;
+}
+.pagination a {
+ float: left;
+ padding: 0 14px;
+ line-height: 34px;
+ border-right: 1px solid;
+ border-right-color: #ddd;
+ border-right-color: rgba(0, 0, 0, 0.15);
+ *border-right-color: #ddd;
+ /* IE6-7 */
+
+ text-decoration: none;
+}
+.pagination a:hover, .pagination .active a {
+ background-color: #c7eefe;
+}
+/*custom classes*/
+.pagination .done a {
+ background-color: #00CC66;
+}
+.pagination .disabled a, .pagination .disabled a:hover {
+ background-color: transparent;
+ color: #bfbfbf;
+}
+.pagination .next a {
+ border: 0;
+}
diff --git a/testapp/exam/templates/exam/question.html b/testapp/exam/templates/exam/question.html
index 977b388..57bfd53 100644
--- a/testapp/exam/templates/exam/question.html
+++ b/testapp/exam/templates/exam/question.html
@@ -97,9 +97,29 @@ function validate(){
</div>
</div>
</div>
+<div class = container>
+<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>
+ {% else %}
+ <li><a href="{{ URL_ROOT }}/exam/{{ qid }}/{{ paper.attempt_number }}/{{ paper.question_paper.id }}/">{{ num }}</a></li>
+ {% endif %}
+ {% endif %}
+ {% if qid in submitted %}
+ <li class="done"><a href="#">{{ num }}</a></li>
+ {% endif %}
+ {% endfor %}
+ </ul>
+ </div>
+</div>
+</div>
-
- <h4><u> {{ question.summary }} </u><font class=pull-right>(Marks : {{ question.points }}) </font></h4><br>
+ <h4><u> {{ question.summary }} </u><font class=pull-right>(Marks : {{ question.points }}) </font></h4><br>
<font size=3 face=arial> {{ question.description|safe }} </font>
{% if error_message %}
<div class="alert alert-error">
diff --git a/testapp/exam/urls.py b/testapp/exam/urls.py
index 8a01a81..43970ce 100644
--- a/testapp/exam/urls.py
+++ b/testapp/exam/urls.py
@@ -18,6 +18,7 @@ urlpatterns = patterns('testapp.exam.views',
url(r'^(?P<q_id>\d+)/check/(?P<attempt_num>\d+)/(?P<questionpaper_id>\d+)/$',\
'check'),
url(r'^intro/$', 'start'),
+ url(r'^(?P<q_id>\d+)/(?P<attempt_num>\d+)/(?P<questionpaper_id>\d+)/$', 'show_question'),
url(r'^manage/$', 'prof_manage'),
url(r'^manage/addquestion/$', 'add_question'),
diff --git a/testapp/exam/views.py b/testapp/exam/views.py
index 89b2fd7..bfac15f 100644
--- a/testapp/exam/views.py
+++ b/testapp/exam/views.py
@@ -4,7 +4,7 @@ import os
import stat
from os.path import dirname, pardir, abspath, join, exists
import datetime
-
+import collections
from django.http import HttpResponse
from django.contrib.auth import login, logout, authenticate
from django.shortcuts import render_to_response, get_object_or_404, redirect
@@ -693,6 +693,36 @@ def start(request, attempt_num=None, questionpaper_id=None):
return start(request, attempt_num, questionpaper_id)
+def get_questions(paper):
+ '''
+ Takes answerpaper as an argument. Returns the total questions as
+ ordered dictionary, the questions yet to attempt and the questions
+ attempted
+ '''
+ to_attempt = []
+ submitted = []
+ all_questions = []
+ questions = {}
+ if paper.questions:
+ to_attempt = (paper.questions).split('|')
+ if paper.questions_answered:
+ submitted = (paper.questions_answered).split('|')
+ if not to_attempt:
+ submitted.sort()
+ all_questions = submitted
+ if not submitted:
+ to_attempt.sort()
+ all_questions = to_attempt
+ if to_attempt and submitted:
+ q_append = to_attempt + submitted
+ q_append.sort()
+ all_questions = q_append
+ for num, value in enumerate(all_questions, 1):
+ questions[value] = num
+ questions = collections.OrderedDict(sorted(questions.items()))
+ return questions, to_attempt, submitted
+
+
def question(request, q_id, attempt_num, questionpaper_id, success_msg=None):
"""Check the credentials of the user and start the exam."""
@@ -716,15 +746,16 @@ def question(request, q_id, attempt_num, questionpaper_id, success_msg=None):
if time_left == 0:
return complete(request, reason='Your time is up!')
quiz_name = paper.question_paper.quiz.description
+ questions, to_attempt, submitted = get_questions(paper)
if success_msg is None:
- context = {'question': q, 'paper': paper, 'user': user,
- 'quiz_name': quiz_name,
- 'time_left': time_left, }
+ context = {'question': q, 'questions': questions, 'paper': paper,
+ 'user': user, 'quiz_name': quiz_name, 'time_left': time_left,
+ 'to_attempt': to_attempt, 'submitted': submitted}
else:
- context = {'question': q, 'paper': paper, 'user': user,
- 'quiz_name': quiz_name,
- 'time_left': time_left,
- 'success_msg': success_msg}
+ context = {'question': q, 'questions': questions, 'paper': paper,
+ 'user': user, 'quiz_name': quiz_name, 'time_left': time_left,
+ 'success_msg': success_msg, 'to_attempt': to_attempt,
+ 'submitted': submitted}
ci = RequestContext(request)
return my_render_to_response('exam/question.html', context,
context_instance=ci)
@@ -803,10 +834,16 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None):
if not paper.question_paper.quiz.active:
reason = 'The quiz has been deactivated!'
return complete(request, reason, attempt_num, questionpaper_id)
- context = {'question': question, 'error_message': err_msg,
+ if not paper.question_paper.quiz.active:
+ reason = 'The quiz has been deactivated!'
+ return complete(request, reason, attempt_num, questionpaper_id)
+ questions, to_attempt, submitted = get_questions(paper)
+ context = {'question': question, 'questions': questions,
+ 'error_message': err_msg,
'paper': paper, 'last_attempt': user_code,
'quiz_name': paper.question_paper.quiz.description,
- 'time_left': time_left}
+ 'time_left': time_left, 'to_attempt': to_attempt,
+ 'submitted': submitted}
ci = RequestContext(request)
return my_render_to_response('exam/question.html', context,