From: Tom Walker Date: Wed, 25 Jun 2014 21:40:19 +0000 (+0100) Subject: moved templates around, fiddled with a few, some changes to template tags and tests X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=4989e4bda7e75caa552e3887117b882596fff110;p=django_quiz.git moved templates around, fiddled with a few, some changes to template tags and tests --- diff --git a/multichoice/templates/answers_for_mc_question.html b/multichoice/templates/answers_for_mc_question.html new file mode 100644 index 0000000..0a06931 --- /dev/null +++ b/multichoice/templates/answers_for_mc_question.html @@ -0,0 +1,10 @@ +{% for answer in answers %} + + + + + +{% endfor %} 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/quiz/templates/base.html b/quiz/templates/base.html new file mode 100644 index 0000000..de93368 --- /dev/null +++ b/quiz/templates/base.html @@ -0,0 +1,32 @@ + + + + + +Example Quiz Website | {% block title %}{% endblock %} + + + + + + + + + + + + + + + +{% block content %} + +{% endblock %} + + + + + + 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/quiz/templates/list_categories.html b/quiz/templates/list_categories.html new file mode 100644 index 0000000..1ae019b --- /dev/null +++ b/quiz/templates/list_categories.html @@ -0,0 +1,21 @@ +{% extends 'base.html' %} +{% block title %}All Quizzes{% endblock %} + +{% block content %} +

Category list

+ + + +{% endblock %} + +{% block right-sidebar %} +

Sponsored Advertisements

+{% endblock %} diff --git a/quiz/templates/progress.html b/quiz/templates/progress.html new file mode 100644 index 0000000..32c6902 --- /dev/null +++ b/quiz/templates/progress.html @@ -0,0 +1,154 @@ +{% extends "base.html" %} + +{% load quiz_tags %} + +{% block title %} Progress Page {% endblock %} +{% block description %} User Progress Page {% endblock %} + +{% block content %} + +
+ +{% if new_user %} + +
+ +
    +
  • +

    Thank you for joining this website. Welcome to your progress page.

    +
  • +
+
+ +{% endif %} + + +{% if cat_scores %} + +

Question Category Scores

+

+ Below are the categories of questions that you have attempted. Blue is the percentage that are correct. +

+ + + + + {% for cat, value in cat_scores.items %} + + {% ifnotequal cat "empty" %} + + {% if forloop.first %} +
+
    + {% endif %} + + {% ifequal forloop.counter 5 %} +
+
+
+
    + {% endifequal %} + + {% ifequal forloop.counter 9 %} +
+
+
+
    + {% endifequal %} + + {% ifequal forloop.counter 13 %} +
+
+
+
    + {% endifequal %} + + {% ifequal forloop.counter 17 %} +
+
+
+
    + {% endifequal %} + +
  • +
    + + +
    +
    +
  • + + {% endifnotequal %} + + + {% endfor %} +
+
+ +{% endif %} + +{% if exams %} + +
+ +

Previous exam papers

+

+ Below are the results of exams that you have sat. +

+ + + + + + + + + + + + + + + {% for exam in exams %} + + + {% user_previous_exam exam %} + + + {% endfor %} + + + +
Quiz TitleScorePossible Score%
+ +{% endif %} + +
+ +{% endblock %} diff --git a/quiz/templates/question.html b/quiz/templates/question.html new file mode 100644 index 0000000..7cfd37f --- /dev/null +++ b/quiz/templates/question.html @@ -0,0 +1,74 @@ +{% extends "base.html" %} + +{% load quiz_tags %} + +{% block title %} {{ quiz.title }} {% endblock %} +{% block description %} {{ quiz.title }} - {{ quiz.description }} {% endblock %} + +{% block content %} + +
+ + +{% if previous %} + +

The previous question:

+

{{ previous.previous_question }}

+ + {% ifequal previous.previous_outcome 'correct' %} +
+ {% else %} +
+ {% endifequal %} + +

Your answer was {{ previous.previous_outcome }}

+
+ + {% correct_answer previous %} +

Explanation:

+
+

{{ previous.previous_question.explanation }}

+
+ + +
+ +{% endif %} + +
+ + +{% if question %} + +

Question category: {{ question.category }}

+

{{ question.content }}

+ +
+ + + + + + {% ifequal question_type 'TF_Question' %} + {% include 'answers_for_tf_question.html' %} + {% endifequal %} + + {% ifequal question_type 'MCQuestion' %} + {% answers_for_mc_question question %} + {% endifequal %} + + +
+ +
+ + +{% endif %} + +
+ + + +
+ +{% endblock %} diff --git a/quiz/templates/quiz_index.html b/quiz/templates/quiz_index.html new file mode 100644 index 0000000..a5466ea --- /dev/null +++ b/quiz/templates/quiz_index.html @@ -0,0 +1,19 @@ +{% extends 'base.html' %} +{% block title %}All Quizzes{% endblock %} + +{% block content %} +

Quiz list

+ {% if quiz_list %} + + {% else %} +

There are no available quizzes.

+ {% endif %} +{% endblock %} + +{% block right-sidebar %} +

Sponsored Advertisements

+{% endblock %} diff --git a/quiz/templates/result.html b/quiz/templates/result.html new file mode 100644 index 0000000..c24c6d5 --- /dev/null +++ b/quiz/templates/result.html @@ -0,0 +1,75 @@ +{% extends "base.html" %} + +{% load quiz_tags %} + +{% block title %} Exam Paper Result {% endblock %} +{% block description %} Exam Results {% endblock %} + +{% block content %} + +
+ +{% if previous %} + +

The previous question:

+

{{ previous.previous_question }}

+

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 %} + + + + + {% endfor %} + +{% endif %} + + + +
+ +{% endblock %} diff --git a/quiz/templates/signup.html b/quiz/templates/signup.html new file mode 100644 index 0000000..dbdcaad --- /dev/null +++ b/quiz/templates/signup.html @@ -0,0 +1,9 @@ +{% extends 'base.html' %} +{% block title %}Progress{% endblock %} + +{% block content %} +

Sign up

+ +

Your current score is {{ anon_score }} out of {{ anon_possible }}

+ +{% endblock %} diff --git a/quiz/templates/user_previous_exam.html b/quiz/templates/user_previous_exam.html new file mode 100644 index 0000000..42bda82 --- /dev/null +++ b/quiz/templates/user_previous_exam.html @@ -0,0 +1,4 @@ +{{ title }} +{{ score }} +{{ possible }} +{{ percent }} diff --git a/quiz/templates/view_quiz_category.html b/quiz/templates/view_quiz_category.html new file mode 100644 index 0000000..b60a0c9 --- /dev/null +++ b/quiz/templates/view_quiz_category.html @@ -0,0 +1,20 @@ +{% extends 'base.html' %} +{% block title %}Quizzes related to {{ category.category }}{% endblock %} + +{% block content %} +

Quizzes in {{ category.category }}

+ + {% if quizzes %} + + {% else %} +

There are no quizzes

+ {% endif %} +{% endblock %} 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_mc_question.html b/templates/quiz/answers_for_mc_question.html deleted file mode 100644 index 0a06931..0000000 --- a/templates/quiz/answers_for_mc_question.html +++ /dev/null @@ -1,10 +0,0 @@ -{% for answer in answers %} - - - - - -{% endfor %} 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/answers_for_tf_question.html b/templates/quiz/answers_for_tf_question.html deleted file mode 100644 index 63c3f94..0000000 --- a/templates/quiz/answers_for_tf_question.html +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - diff --git a/templates/quiz/base.html b/templates/quiz/base.html deleted file mode 100644 index 0f68190..0000000 --- a/templates/quiz/base.html +++ /dev/null @@ -1,41 +0,0 @@ - - - - - -Example Quiz Website | {% block title %}{% endblock %} - - - - - - - - - - - - - - - - - - - - - - - -{% block content %}{% endblock %} - - - - - - - - - \ No newline at end of file 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/list_categories.html b/templates/quiz/list_categories.html deleted file mode 100644 index 1ae019b..0000000 --- a/templates/quiz/list_categories.html +++ /dev/null @@ -1,21 +0,0 @@ -{% extends 'base.html' %} -{% block title %}All Quizzes{% endblock %} - -{% block content %} -

Category list

- - - -{% endblock %} - -{% block right-sidebar %} -

Sponsored Advertisements

-{% endblock %} diff --git a/templates/quiz/progress.html b/templates/quiz/progress.html deleted file mode 100644 index 32c6902..0000000 --- a/templates/quiz/progress.html +++ /dev/null @@ -1,154 +0,0 @@ -{% extends "base.html" %} - -{% load quiz_tags %} - -{% block title %} Progress Page {% endblock %} -{% block description %} User Progress Page {% endblock %} - -{% block content %} - -
- -{% if new_user %} - -
- -
    -
  • -

    Thank you for joining this website. Welcome to your progress page.

    -
  • -
-
- -{% endif %} - - -{% if cat_scores %} - -

Question Category Scores

-

- Below are the categories of questions that you have attempted. Blue is the percentage that are correct. -

- - - - - {% for cat, value in cat_scores.items %} - - {% ifnotequal cat "empty" %} - - {% if forloop.first %} -
-
    - {% endif %} - - {% ifequal forloop.counter 5 %} -
-
-
-
    - {% endifequal %} - - {% ifequal forloop.counter 9 %} -
-
-
-
    - {% endifequal %} - - {% ifequal forloop.counter 13 %} -
-
-
-
    - {% endifequal %} - - {% ifequal forloop.counter 17 %} -
-
-
-
    - {% endifequal %} - -
  • -
    - - -
    -
    -
  • - - {% endifnotequal %} - - - {% endfor %} -
-
- -{% endif %} - -{% if exams %} - -
- -

Previous exam papers

-

- Below are the results of exams that you have sat. -

- - - - - - - - - - - - - - - {% for exam in exams %} - - - {% user_previous_exam exam %} - - - {% endfor %} - - - -
Quiz TitleScorePossible Score%
- -{% endif %} - -
- -{% endblock %} diff --git a/templates/quiz/question.html b/templates/quiz/question.html deleted file mode 100644 index c4913d8..0000000 --- a/templates/quiz/question.html +++ /dev/null @@ -1,77 +0,0 @@ -{% extends "base.html" %} - -{% load quiz_tags %} - -{% block title %} {{ quiz.title }} {% endblock %} -{% block description %} {{ quiz.title }} - {{ quiz.description }} {% endblock %} - -{% block content %} - -
- - -{% if previous %} - -

The previous question:

-

{{ previous.previous_question }}

- - {% ifequal previous.previous_outcome 'correct' %} -
- {% else %} -
- {% endifequal %} - -

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

-
- - {% correct_answer previous %} -

Explanation:

-
-

{{ previous.previous_question.explanation }}

-
- - -
- -{% endif %} - -
- - -{% if question %} - -

Question category: {{ question.category }}

-

{{ question.id }}

-

{{ question_type }}

-

{{ question.content }}

- -
-

quid {{ question.id }}

- - - - - - {% ifequal question_type 'TF_Question' %} - {% include 'answers_for_tf_question.html' %} - {% endifequal %} - - {% ifequal question_type 'MCQuestion' %} - {% answers_for_mc_question question %} - {% endifequal %} - - -
- -
- - -{% endif %} - -
- - - -
- -{% endblock %} diff --git a/templates/quiz/quiz_index.html b/templates/quiz/quiz_index.html deleted file mode 100644 index a5466ea..0000000 --- a/templates/quiz/quiz_index.html +++ /dev/null @@ -1,19 +0,0 @@ -{% extends 'base.html' %} -{% block title %}All Quizzes{% endblock %} - -{% block content %} -

Quiz list

- {% if quiz_list %} - - {% else %} -

There are no available quizzes.

- {% endif %} -{% endblock %} - -{% block right-sidebar %} -

Sponsored Advertisements

-{% endblock %} diff --git a/templates/quiz/result.html b/templates/quiz/result.html deleted file mode 100644 index 2cb671e..0000000 --- a/templates/quiz/result.html +++ /dev/null @@ -1,72 +0,0 @@ -{% extends "base.html" %} - -{% load quiz_tags %} - -{% block title %} Exam Paper Result {% endblock %} -{% block description %} Exam Results {% endblock %} - -{% block content %} - -
- -{% if previous %} - -

The previous question:

-

{{ previous.previous_question }}

-

Your answer was {{ previous.previous_answer }} which is {{ 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 %} - - {% endfor %} - -{% endif %} - - - -
- -{% endblock %} \ No newline at end of file diff --git a/templates/quiz/signup.html b/templates/quiz/signup.html deleted file mode 100644 index dbdcaad..0000000 --- a/templates/quiz/signup.html +++ /dev/null @@ -1,9 +0,0 @@ -{% extends 'base.html' %} -{% block title %}Progress{% endblock %} - -{% block content %} -

Sign up

- -

Your current score is {{ anon_score }} out of {{ anon_possible }}

- -{% endblock %} diff --git a/templates/quiz/user_previous_exam.html b/templates/quiz/user_previous_exam.html deleted file mode 100644 index 42bda82..0000000 --- a/templates/quiz/user_previous_exam.html +++ /dev/null @@ -1,4 +0,0 @@ -{{ title }} -{{ score }} -{{ possible }} -{{ percent }} diff --git a/templates/quiz/view_quiz_category.html b/templates/quiz/view_quiz_category.html deleted file mode 100644 index b60a0c9..0000000 --- a/templates/quiz/view_quiz_category.html +++ /dev/null @@ -1,20 +0,0 @@ -{% extends 'base.html' %} -{% block title %}Quizzes related to {{ category.category }}{% endblock %} - -{% block content %} -

Quizzes in {{ category.category }}

- - {% if quizzes %} - - {% else %} -

There are no quizzes

- {% endif %} -{% endblock %} diff --git a/true_false/templates/answers_for_tf_question.html b/true_false/templates/answers_for_tf_question.html new file mode 100644 index 0000000..63c3f94 --- /dev/null +++ b/true_false/templates/answers_for_tf_question.html @@ -0,0 +1,16 @@ + + + + + + + + + +