From 4989e4bda7e75caa552e3887117b882596fff110 Mon Sep 17 00:00:00 2001 From: Tom Walker Date: Wed, 25 Jun 2014 22:40:19 +0100 Subject: [PATCH] moved templates around, fiddled with a few, some changes to template tags and tests --- .../templates}/answers_for_mc_question.html | 0 quiz/admin.py | 2 +- {templates/quiz => quiz/templates}/base.html | 17 ++----- quiz/templates/correct_answer.html | 42 +++++++++++++++ .../templates}/list_categories.html | 0 .../quiz => quiz/templates}/progress.html | 0 .../quiz => quiz/templates}/question.html | 5 +- .../quiz => quiz/templates}/quiz_index.html | 0 .../quiz => quiz/templates}/result.html | 51 ++++++++++--------- .../quiz => quiz/templates}/signup.html | 0 .../templates}/user_previous_exam.html | 0 .../templates}/view_quiz_category.html | 0 quiz/templatetags/quiz_tags.py | 22 +++++++- quiz/tests.py | 11 +++- quiz/views.py | 2 +- templates/quiz/answers_for_question.html | 0 templates/quiz/correct_answer.html | 31 ----------- .../templates}/answers_for_tf_question.html | 0 18 files changed, 105 insertions(+), 78 deletions(-) rename {templates/quiz => multichoice/templates}/answers_for_mc_question.html (100%) rename {templates/quiz => quiz/templates}/base.html (69%) create mode 100644 quiz/templates/correct_answer.html rename {templates/quiz => quiz/templates}/list_categories.html (100%) rename {templates/quiz => quiz/templates}/progress.html (100%) rename {templates/quiz => quiz/templates}/question.html (88%) rename {templates/quiz => quiz/templates}/quiz_index.html (100%) rename {templates/quiz => quiz/templates}/result.html (79%) rename {templates/quiz => quiz/templates}/signup.html (100%) rename {templates/quiz => quiz/templates}/user_previous_exam.html (100%) rename {templates/quiz => quiz/templates}/view_quiz_category.html (100%) delete mode 100644 templates/quiz/answers_for_question.html delete mode 100644 templates/quiz/correct_answer.html rename {templates/quiz => true_false/templates}/answers_for_tf_question.html (100%) diff --git a/templates/quiz/answers_for_mc_question.html b/multichoice/templates/answers_for_mc_question.html similarity index 100% rename from templates/quiz/answers_for_mc_question.html rename to multichoice/templates/answers_for_mc_question.html diff --git a/quiz/admin.py b/quiz/admin.py index 97ebe7b..914b77d 100644 --- a/quiz/admin.py +++ b/quiz/admin.py @@ -44,6 +44,7 @@ class QuizAdminForm(forms.ModelForm): self.save_m2m() return quiz + class QuizAdmin(admin.ModelAdmin): form = QuizAdminForm @@ -52,7 +53,6 @@ class QuizAdmin(admin.ModelAdmin): search_fields = ('description', 'category', ) - class CategoryAdmin(admin.ModelAdmin): search_fields = ('category', ) diff --git a/templates/quiz/base.html b/quiz/templates/base.html similarity index 69% rename from templates/quiz/base.html rename to quiz/templates/base.html index 0f68190..de93368 100644 --- a/templates/quiz/base.html +++ b/quiz/templates/base.html @@ -6,20 +6,14 @@ Example Quiz Website | {% block title %}{% endblock %} - - - - - + - - @@ -27,15 +21,12 @@ +{% block content %} - -{% block content %}{% endblock %} +{% endblock %} - - - - \ No newline at end of file + diff --git a/quiz/templates/correct_answer.html b/quiz/templates/correct_answer.html new file mode 100644 index 0000000..1edf214 --- /dev/null +++ b/quiz/templates/correct_answer.html @@ -0,0 +1,42 @@ + +{% if user_was_incorrect %} + +
+ + You answered the above question incorrectly + +
+ +{% else %} + +
+ + You answered the above question correctly + +
+ +{% endif %} + + + + + {% for answer in answers %} + + {% if answer.correct %} + + + + + + {% else %} + + + + + {% endif %} + + + {% endfor %} + + +
{{ answer.content }}This is the correct answer
{{ answer.content }}
diff --git a/templates/quiz/list_categories.html b/quiz/templates/list_categories.html similarity index 100% rename from templates/quiz/list_categories.html rename to quiz/templates/list_categories.html diff --git a/templates/quiz/progress.html b/quiz/templates/progress.html similarity index 100% rename from templates/quiz/progress.html rename to quiz/templates/progress.html diff --git a/templates/quiz/question.html b/quiz/templates/question.html similarity index 88% rename from templates/quiz/question.html rename to quiz/templates/question.html index c4913d8..7cfd37f 100644 --- a/templates/quiz/question.html +++ b/quiz/templates/question.html @@ -21,7 +21,7 @@
{% endifequal %} -

Your answer was {{ previous.previous_answer }} which is {{ previous.previous_outcome }}

+

Your answer was {{ previous.previous_outcome }}

{% correct_answer previous %} @@ -41,12 +41,9 @@ {% if question %}

Question category: {{ question.category }}

-

{{ question.id }}

-

{{ question_type }}

{{ question.content }}

-

quid {{ question.id }}

diff --git a/templates/quiz/quiz_index.html b/quiz/templates/quiz_index.html similarity index 100% rename from templates/quiz/quiz_index.html rename to quiz/templates/quiz_index.html diff --git a/templates/quiz/result.html b/quiz/templates/result.html similarity index 79% rename from templates/quiz/result.html rename to quiz/templates/result.html index 2cb671e..c24c6d5 100644 --- a/templates/quiz/result.html +++ b/quiz/templates/result.html @@ -10,63 +10,66 @@
{% if previous %} - -

The previous question:

+ +

The previous question:

{{ previous.previous_question }}

-

Your answer was {{ previous.previous_answer }} which is {{ previous.previous_outcome }}

+

Your answer was {{ previous.previous_outcome }}

{% correct_answer previous %}

Explanation:

{{ previous.previous_question.explanation }}


- + {% endif %} {% if score %} - +

Exam results

Exam title: {{ quiz.title }}

- +

You answered {{ score }} questions correctly out of {{ max_score }}, giving you {{ percent }} percent correct

- +

Review the questions below and try the exam again in the future.

- + {% if user.is_authenticated %} - +

The result of this exam will be stored in your progress section so you can review and monitor your progression.

- + {% endif %}
- - + + {% endif %} - +
- + {% if session and possible %} - +

Your session score is {{ session }} out of a possible {{ possible }}

- +
- + {% endif %} - + {% if questions %} - + {% for question in questions %} - +

{{ question.content }}

- {% correct_answer_for_all_with_users_incorrect question incorrect_questions %} - + {% correct_answer_for_all_with_users_incorrect question incorrect_questions %} + + + + {% endfor %} - + {% endif %}
-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/templates/quiz/signup.html b/quiz/templates/signup.html similarity index 100% rename from templates/quiz/signup.html rename to quiz/templates/signup.html diff --git a/templates/quiz/user_previous_exam.html b/quiz/templates/user_previous_exam.html similarity index 100% rename from templates/quiz/user_previous_exam.html rename to quiz/templates/user_previous_exam.html diff --git a/templates/quiz/view_quiz_category.html b/quiz/templates/view_quiz_category.html similarity index 100% rename from templates/quiz/view_quiz_category.html rename to quiz/templates/view_quiz_category.html diff --git a/quiz/templatetags/quiz_tags.py b/quiz/templatetags/quiz_tags.py index 02d7f27..8543c04 100644 --- a/quiz/templatetags/quiz_tags.py +++ b/quiz/templatetags/quiz_tags.py @@ -14,7 +14,16 @@ def correct_answer(context, previous): processes the correct answer based on the previous question dict """ q = previous['previous_question'] - answers = Answer.objects.filter(question__id=q.id) + + if q.__class__.__name__ == "MCQuestion": + answers = Answer.objects.filter(question__id=q.id) + + if q.__class__.__name__ == "TF_Question": + answers = [{'correct': q.check_if_correct('T'), + 'content': 'True'}, + {'correct': q.check_if_correct('F'), + 'content': 'False'}] + return {'answers': answers, } @register.inclusion_tag('correct_answer.html', takes_context=True) @@ -31,12 +40,21 @@ def correct_answer_for_all_with_users_incorrect(context, question, incorrect_lis processes the correct answer based on a given question object if the answer is incorrect, informs the user """ - answers = Answer.objects.filter(question__id=question.id) question_id = str(question.id) if question_id in incorrect_list: user_was_incorrect = True else: user_was_incorrect = False + + if question.__class__.__name__ == "MCQuestion": + answers = Answer.objects.filter(question__id=question.id) + + if question.__class__.__name__ == "TF_Question": + answers = [{'correct': question.check_if_correct('T'), + 'content': 'True'}, + {'correct': question.check_if_correct('F'), + 'content': 'False'}] + return {'answers': answers, 'user_was_incorrect': user_was_incorrect, } @register.inclusion_tag('user_previous_exam.html', takes_context=True) diff --git a/quiz/tests.py b/quiz/tests.py index 35dc699..fee8060 100644 --- a/quiz/tests.py +++ b/quiz/tests.py @@ -442,7 +442,11 @@ class TestQuestionViewsUser(TestCase): question2 = MCQuestion.objects.create(id = 2, content = "squeek") question2.quiz.add(quiz1) - question2.quiz.add(quiz2) + + question3 = TF_Question.objects.create(id = 3, + content = "oink", + correct = True) + question3.quiz.add(quiz2) Answer.objects.create(id = 123, question = question1, @@ -544,13 +548,16 @@ class TestQuestionViewsUser(TestCase): {'guess': 456, 'question_id': 2}) question1 = Question.objects.get_subclass(id = 1) - question2 = Question.objects.get_subclass(id = 2) + question2 = Question.objects.get_subclass(id = 3) self.assertEqual(response.context['score'], 1) self.assertEqual(response.context['max_score'], 2) self.assertEqual(response.context['percent'], 50) self.assertIn(question1, response.context['questions']) self.assertIn(question2, response.context['questions']) + self.assertContains(response, 'correctly') + self.assertContains(response, 'incorrectly') + self.assertContains(response, 'True') sitting = Sitting.objects.get(quiz = Quiz.objects.get(id = 2), diff --git a/quiz/views.py b/quiz/views.py index 7aa94a4..c288f02 100644 --- a/quiz/views.py +++ b/quiz/views.py @@ -192,7 +192,7 @@ def final_result_anon(request, quiz, previous): max_score = quiz.question_set.all().select_subclasses().count() percent = int(round((float(score) / max_score) * 100)) if score == 0: - score = "nil points" + score = "0" session_score, session_possible = anon_session_score(request) del request.session[quiz_id + "_q_list"] diff --git a/templates/quiz/answers_for_question.html b/templates/quiz/answers_for_question.html deleted file mode 100644 index e69de29..0000000 diff --git a/templates/quiz/correct_answer.html b/templates/quiz/correct_answer.html deleted file mode 100644 index 0ad26d4..0000000 --- a/templates/quiz/correct_answer.html +++ /dev/null @@ -1,31 +0,0 @@ - -{% if user_was_incorrect %} - -
- - You answered the above question incorrectly - -
- - -{% endif %} - -
- -{% for answer in answers %} - - {% if answer.correct %} - - - - - {% else %} - - - - {% endif %} - -{% endfor %} - - -
{{ answer.content }} correct answer
{{ answer.content }}
\ No newline at end of file diff --git a/templates/quiz/answers_for_tf_question.html b/true_false/templates/answers_for_tf_question.html similarity index 100% rename from templates/quiz/answers_for_tf_question.html rename to true_false/templates/answers_for_tf_question.html -- 2.39.5