diff options
author | Prabhu Ramachandran | 2011-11-17 17:35:30 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2011-11-17 17:35:30 +0530 |
commit | 9f674808a5681a0380531ff62079b94874641c1e (patch) | |
tree | 63fdb2f431d9fc68705e1170cc4e536a36c18169 | |
parent | 78e18eae416a37fdb2e27d4dde7ed9675692ac7d (diff) | |
download | online_test-9f674808a5681a0380531ff62079b94874641c1e.tar.gz online_test-9f674808a5681a0380531ff62079b94874641c1e.tar.bz2 online_test-9f674808a5681a0380531ff62079b94874641c1e.zip |
BUG/ENH: Cleaning up page templates and fixing bug
If you complete the quiz it was going into a redirect loop, this is
fixed. Also cleaned up all the page templates with proper block
contents.
-rw-r--r-- | exam/views.py | 12 | ||||
-rw-r--r-- | templates/404.html | 5 | ||||
-rw-r--r-- | templates/500.html | 7 | ||||
-rw-r--r-- | templates/base.html | 22 | ||||
-rw-r--r-- | templates/exam/complete.html | 8 | ||||
-rw-r--r-- | templates/exam/index.html | 12 | ||||
-rw-r--r-- | templates/exam/intro.html | 7 | ||||
-rw-r--r-- | templates/exam/login.html | 6 | ||||
-rw-r--r-- | templates/exam/monitor.html | 9 | ||||
-rw-r--r-- | templates/exam/question.html | 18 | ||||
-rw-r--r-- | templates/exam/quit.html | 6 | ||||
-rw-r--r-- | templates/exam/register.html | 7 |
12 files changed, 94 insertions, 25 deletions
diff --git a/exam/views.py b/exam/views.py index ad8a04f..2437fba 100644 --- a/exam/views.py +++ b/exam/views.py @@ -94,8 +94,8 @@ def start(request): return complete(request, reason=msg) try: old_paper = QuestionPaper.objects.get(user=user, quiz=quiz) - p = old_paper.current_question() - return redirect('/exam/%s'%p) + q = old_paper.current_question() + return show_question(request, q) except QuestionPaper.DoesNotExist: ip = request.META['REMOTE_ADDR'] key = gen_key(10) @@ -198,11 +198,11 @@ def quit(request): def complete(request, reason=None): user = request.user - yes = True + no = False message = reason or 'The quiz has been completed. Thank you.' - if request.method == 'POST': - yes = request.POST.get('yes', None) - if yes: + if request.method == 'POST' and 'no' in request.POST: + no = request.POST.get('no', False) + if not no: # Logout the user and quit with the message given. logout(request) context = {'message': message} diff --git a/templates/404.html b/templates/404.html new file mode 100644 index 0000000..7d33dd3 --- /dev/null +++ b/templates/404.html @@ -0,0 +1,5 @@ +{% extends "base.html" %} + +{% block content %} +The requested page does not exist. +{% endblock %} diff --git a/templates/500.html b/templates/500.html new file mode 100644 index 0000000..d02721f --- /dev/null +++ b/templates/500.html @@ -0,0 +1,7 @@ +{% extends "base.html" %} + +{% block content %} +Internal Server error.<br /> +This event will be reported.<br /> +Sorry for the inconvinience. +{% endblock %} diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..22e9ba2 --- /dev/null +++ b/templates/base.html @@ -0,0 +1,22 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> + +<head> +<title> +{% block title %} +{% endblock %} +</title> +{% block meta %} +{% endblock%} +{% block script %} +{% endblock %} +</head> + +<body {% block onload %}{% endblock %}> + +{% block content %} +{% endblock %} + +</body> +</html>
\ No newline at end of file diff --git a/templates/exam/complete.html b/templates/exam/complete.html index bd90e6d..4c3f3d5 100644 --- a/templates/exam/complete.html +++ b/templates/exam/complete.html @@ -1,4 +1,12 @@ +{% extends "base.html" %} + +{% block title %}Good bye!{% endblock %} + +{% block content %} <h2> Good bye! </h2> + <p> {{message}} </p> <br /> <p>You may now close the browser.</p> + +{% endblock content %} diff --git a/templates/exam/index.html b/templates/exam/index.html deleted file mode 100644 index 5470cf5..0000000 --- a/templates/exam/index.html +++ /dev/null @@ -1,12 +0,0 @@ -<p> Welcome to the Examination. </p> -<br></br> - -{% if question_list %} - <ul> - {% for question in question_list %} - <li> <a href="/exam/{{ question.id }}/">{{ question.summary }} </a> </li> - {% endfor %} - </ul> -{% else %} - <p> Lucky you, no questions available.</p> -{% endif %} diff --git a/templates/exam/intro.html b/templates/exam/intro.html index 0d673b3..75de639 100644 --- a/templates/exam/intro.html +++ b/templates/exam/intro.html @@ -1,3 +1,8 @@ +{% extends "base.html" %} + +{% block title %}Instructions and Rules {% endblock %} + +{% block content %} <h2>Important rules and instructions</h2> <p> Welcome <strong>{{user.first_name.title}} {{user.last_name.title}}</strong>, @@ -44,3 +49,5 @@ carefully. {% csrf_token %} <input type="submit" name="start" value="Start Exam!"> </form> + +{% endblock content %}
\ No newline at end of file diff --git a/templates/exam/login.html b/templates/exam/login.html index c8e27e4..b8594f4 100644 --- a/templates/exam/login.html +++ b/templates/exam/login.html @@ -1,3 +1,8 @@ +{% extends "base.html" %} + +{% block title %}Login{% endblock title %} + +{% block content %} <p> Welcome to the Examination. Please login to proceed.</p> @@ -10,3 +15,4 @@ Please login to proceed.</p> </form> <!-- <a href="/exam/forgotpassword/">Forgot Password</a> <br /> --> <a href="/exam/register/">New User Registration</a> +{% endblock content %}
\ No newline at end of file diff --git a/templates/exam/monitor.html b/templates/exam/monitor.html index f1c7779..d79bb35 100644 --- a/templates/exam/monitor.html +++ b/templates/exam/monitor.html @@ -1,6 +1,12 @@ +{% extends "base.html" %} + +{% block title %} Quiz results {% endblock title %} + +{% block meta %} <meta http-equiv="refresh" content="30"/> {% endblock meta %} + +{% block content %} <h1> Current quiz results </h1> -<meta http-equiv="refresh" content="30"/> {% if paper_list %} <table border="1" cellpadding="3"> @@ -21,3 +27,4 @@ <p> No answer papers so far. </p> {% endif %} +{% endblock content %} diff --git a/templates/exam/question.html b/templates/exam/question.html index 2267efc..9ea27c4 100644 --- a/templates/exam/question.html +++ b/templates/exam/question.html @@ -1,5 +1,8 @@ -<h2> {{ question.summary }} </h2> +{% extends "base.html" %} + +{% block title %} Answer question {% endblock %} +{% block script %} <script type="text/javascript"> <!-- var time_left = {{ time_left }}; @@ -25,24 +28,27 @@ function secs_to_time(secs) return h_s + m_s + s_s; } -function dec_time() +function update_time() { time_left -= 1; if (time_left) { var elem = document.getElementById("time_left"); var t_str = secs_to_time(time_left); elem.innerHTML = "<strong> Time left: " + t_str + "</strong>"; - setTimeout("dec_time()", 1000); + setTimeout("update_time()", 1000); } else { document.forms["logout"].submit(); } } - //--> </script> +{% endblock script %} -<body onload="dec_time()"> +{% block onload %} onload="update_time()" {% endblock %} + +{% block content %} +<h2> {{ question.summary }} </h2> <p>{{ question.description }} </p> @@ -75,4 +81,4 @@ you have {{ paper.questions_left }} question(s) left in {{ quiz_name }}.</p> <input type="submit" name="quit" value="Quit exam and logout" /> </form> -</body>
\ No newline at end of file +{% endblock content %}
\ No newline at end of file diff --git a/templates/exam/quit.html b/templates/exam/quit.html index ea4b8df..a9d3515 100644 --- a/templates/exam/quit.html +++ b/templates/exam/quit.html @@ -1,3 +1,8 @@ +{% extends "base.html" %} + +{% block title %}Quit exam {% endblock %} + +{% block content %} <p>Your current answers are saved.</p> <p> Are you sure you wish to quit the exam?</p> @@ -6,3 +11,4 @@ <input type="submit" name="yes" value="Yes!" /> <input type="submit" name="no" value="No!" /> </form> +{% endblock content %}
\ No newline at end of file diff --git a/templates/exam/register.html b/templates/exam/register.html index 2ffc140..d002570 100644 --- a/templates/exam/register.html +++ b/templates/exam/register.html @@ -1,3 +1,8 @@ +{% extends "base.html" %} + +{% block title %}Registration form {% endblock %} + +{% block content %} Please provide the following details. <form action="" method="post"> {% csrf_token %} @@ -6,3 +11,5 @@ Please provide the following details. <input type="submit" value="Register" /> </form> + +{% endblock content %}
\ No newline at end of file |