From 9f674808a5681a0380531ff62079b94874641c1e Mon Sep 17 00:00:00 2001 From: Prabhu Ramachandran Date: Thu, 17 Nov 2011 17:35:30 +0530 Subject: 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. --- exam/views.py | 12 ++++++------ templates/404.html | 5 +++++ templates/500.html | 7 +++++++ templates/base.html | 22 ++++++++++++++++++++++ templates/exam/complete.html | 8 ++++++++ templates/exam/index.html | 12 ------------ templates/exam/intro.html | 7 +++++++ templates/exam/login.html | 6 ++++++ templates/exam/monitor.html | 9 ++++++++- templates/exam/question.html | 18 ++++++++++++------ templates/exam/quit.html | 6 ++++++ templates/exam/register.html | 7 +++++++ 12 files changed, 94 insertions(+), 25 deletions(-) create mode 100644 templates/404.html create mode 100644 templates/500.html create mode 100644 templates/base.html delete mode 100644 templates/exam/index.html 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.
+This event will be reported.
+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 @@ + + + + + +{% block title %} +{% endblock %} + +{% block meta %} +{% endblock%} +{% block script %} +{% endblock %} + + + + +{% block content %} +{% endblock %} + + + \ 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 %}

Good bye!

+

{{message}}


You may now close the browser.

+ +{% 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 @@ -

Welcome to the Examination.

-

- -{% if question_list %} - -{% else %} -

Lucky you, no questions available.

-{% 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 %}

Important rules and instructions

Welcome {{user.first_name.title}} {{user.last_name.title}}, @@ -44,3 +49,5 @@ carefully. {% csrf_token %} + +{% 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 %}

Welcome to the Examination. Please login to proceed.

@@ -10,3 +15,4 @@ Please login to proceed.

New User Registration +{% 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 %} {% endblock meta %} + +{% block content %}

Current quiz results

- {% if paper_list %} @@ -21,3 +27,4 @@

No answer papers so far.

{% 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 @@ -

{{ question.summary }}

+{% extends "base.html" %} + +{% block title %} Answer question {% endblock %} +{% block script %} +{% endblock script %} - +{% block onload %} onload="update_time()" {% endblock %} + +{% block content %} +

{{ question.summary }}

{{ question.description }}

@@ -75,4 +81,4 @@ you have {{ paper.questions_left }} question(s) left in {{ quiz_name }}.

- \ 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 %}

Your current answers are saved.

Are you sure you wish to quit the exam?

@@ -6,3 +11,4 @@ +{% 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. {% csrf_token %} @@ -6,3 +11,5 @@ Please provide the following details. + +{% endblock content %} \ No newline at end of file -- cgit