*.*~
*~
*.pyc
+#*#
/db.sqlite3
/manage.py
/mysite*
def __unicode__(self):
return unicode(self.title)
+ def get_max_score(self):
+ return self.question_set.count()
+
"""
Progress is used to track an individual signed in users score on different
quiz's and categories
.exists()
if category_test is False:
- return "error", "category does not exist"
+ return "error", "category does not exist"
to_find = re.escape(category_queried) + r",(\d+),(\d+),"
if any([category_test is False, score_to_add is False,
possible_to_add is False, str(score_to_add).isdigit() is False,
str(possible_to_add).isdigit() is False]):
- return "error", "category does not exist or invalid score"
+ return "error", "category does not exist or invalid score"
to_find = re.escape(str(category_queried)) + r",(\d+),(\d+),"
def remove_first_question(self):
first_comma = self.question_list.find(',')
if first_comma != -1 or first_comma != 0:
- self.question_list = self.question_list[first_comma+1:]
+ self.question_list = self.question_list[first_comma + 1:]
self.save()
def add_to_score(self, points):
<div class="container">
-{% if previous %}
+ {% if previous %}
- <p class="muted"><small>The previous question:</small></p>
- <p>{{ previous.previous_question }}</p>
- <p>Your answer was <strong>{{ previous.previous_outcome }}</strong></p>
- {% correct_answer previous %}
- <p><strong>Explanation:</strong></p>
- <div class="well " style="background-color: #fcf8e3;">
- <p>{{ previous.previous_question.explanation }}</p>
- </div>
-<hr>
+ <p class="muted"><small>The previous question:</small></p>
+ <p>{{ previous.previous_question }}</p>
+ <p>Your answer was <strong>{{ previous.previous_outcome }}</strong></p>
+ {% correct_answer previous %}
+ <p><strong>Explanation:</strong></p>
+ <div class="well " style="background-color: #fcf8e3;">
+ <p>{{ previous.previous_question.explanation }}</p>
+ </div>
+ <hr>
-{% endif %}
+ {% endif %}
-{% if score or max_score %}
+ {% if score or max_score %}
- <div>
- <h2>Exam results</h2>
- <p><small class="muted">Exam title:</small> <strong>{{ quiz.title }}</strong></p>
+ <div>
+ <h2>Exam results</h2>
+ <p>
+ <small class="muted">Exam title: </small>
+ <strong>{{ quiz.title }}</strong></p>
- <p class="lead">You answered {{ score }} questions correctly out of {{ max_score }}, giving you {{ percent }} percent correct</p>
+ <p class="lead">
+ You answered {{ score }} questions correctly out of {{ max_score }}, giving you {{ percent }} percent correct
+ </p>
- <p>Review the questions below and try the exam again in the future.</p>
+ <p>Review the questions below and try the exam again in the future.</p>
- {% if user.is_authenticated %}
+ {% if user.is_authenticated %}
- <p>The result of this exam will be stored in your progress section so you can review and monitor your progression.</p>
+ <p>The result of this exam will be stored in your progress section so you can review and monitor your progression.</p>
- {% endif %}
- </div>
+ {% endif %}
+ </div>
-{% endif %}
+ {% endif %}
- <hr>
+ <hr>
-{% if session and possible %}
+ {% if session and possible %}
- <p class="lead">Your session score is {{ session }} out of a possible {{ possible }}</p>
+ <p class="lead">
+ Your session score is {{ session }} out of a possible {{ possible }}
+ </p>
- <hr>
+ <hr>
-{% endif %}
+ {% endif %}
-{% if questions %}
+ {% if questions %}
- {% for question in questions %}
+ {% for question in questions %}
- <p class="lead">{{ question.content }}</p>
- {% correct_answer_for_all_with_users_incorrect question incorrect_questions %}
+ <p class="lead">
+ {{ question.content }}
+ </p>
+ {% correct_answer_for_all question %}
+ {% endfor %}
-
- {% endfor %}
-
-{% endif %}
+ {% endif %}
from django import template
from multichoice.models import Answer, MCQuestion
-from true_false.models import TF_Question
register = template.Library()
@register.inclusion_tag('answers_for_mc_question.html', takes_context=True)
def answers_for_mc_question(context, question):
- answers = Answer.objects.filter(question__id=question.id).order_by('?')
- return {'answers': answers}
+ return {'answers': Answer.objects.filter(question=question).order_by('?')}
@register.inclusion_tag('correct_answer.html', takes_context=True)
"""
q = previous['previous_question']
q_type = q.__class__.__name__
- answers = q.get_answers()
previous_answer_id = context['previous']['previous_answer']
if isinstance(q, MCQuestion):
previous_answer_id = int(previous_answer_id)
- return {'answers': answers,
+ return {'answers': q.get_answers(),
'question_type': {q_type: True},
'previous_answer_id': previous_answer_id}
@register.inclusion_tag('correct_answer.html', takes_context=True)
-def correct_answer_for_all_with_users_incorrect(context,
- question,
- incorrect_list):
+def correct_answer_for_all(context, question):
"""
processes the correct answer based on a given question object
if the answer is incorrect, informs the user
"""
- question_id = str(question.id)
- if question_id in incorrect_list:
+ answers = question.get_answers()
+ incorrect_list = context.get('incorrect_questions', '')
+ if str(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}
"""
Provides details of finished exams
"""
- title = exam.quiz.title
final_score = exam.current_score
- possible_score = exam.quiz.question_set.count()
+ possible_score = exam.quiz.get_max_score()
percent = int(round((float(final_score) / float(possible_score)) * 100))
- return {'title': title, 'score': final_score,
- 'possible': possible_score, 'percent': percent}
+ return {'title': exam.quiz.title,
+ 'score': final_score,
+ 'possible': possible_score,
+ 'percent': percent}
self.quiz1 = Quiz.objects.create(id=1,
title='test quiz 1',
description='d1',
- url='tq1',)
+ url='tq1')
self.quiz2 = Quiz.objects.create(id=2,
title='test quiz 2',
description='d2',
- url='t q2',)
+ url='t q2')
self.quiz3 = Quiz.objects.create(id=3,
title='test quiz 3',
description='d3',
- url='t q3',)
+ url='t q3')
self.quiz4 = Quiz.objects.create(id=4,
title='test quiz 4',
description='d4',
- url='T-!£$%^&*Q4',)
+ url='T-!£$%^&*Q4')
+
+ self.question1 = MCQuestion.objects.create(id=1,
+ content='squawk')
+ self.question1.quiz.add(self.quiz1)
def test_quiz_url(self):
self.assertEqual(self.quiz1.url, 'tq1')
description='d5',
url='tq5',
category=self.c1,
- exam_paper=True,)
+ exam_paper=True)
self.assertEqual(q5.category.category, self.c1.category)
self.assertEqual(q5.random_order, False)
self.assertEqual(self.quiz1.exam_paper, True)
+ def test_get_max_score(self):
+ self.assertEqual(self.quiz1.get_max_score(), 1)
+
class TestProgress(TestCase):
def setUp(self):
self.quiz1 = Quiz.objects.create(id=1,
title='test quiz 1',
description='d1',
- url='tq1',)
+ url='tq1')
self.user = User.objects.create_user(username='jacob',
email='jacob@jacob.com',
self.quiz1 = Quiz.objects.create(id=1,
title='test quiz 1',
description='d1',
- url='tq1',)
+ url='tq1')
self.question1 = MCQuestion.objects.create(id=1,
- content='squawk',)
+ content='squawk')
self.question1.quiz.add(self.quiz1)
self.question2 = MCQuestion.objects.create(id=2,
- content='squeek',)
+ content='squeek')
self.question2.quiz.add(self.quiz1)
self.user = User.objects.create_user(username='jacob',
self.assertIn('1', self.sitting.get_incorrect_questions())
question3 = TF_Question.objects.create(id=3,
- content='oink',)
+ content='oink')
self.sitting.add_incorrect_question(question3)
self.assertIn('3', self.sitting.get_incorrect_questions())
self.quiz2 = Quiz.objects.create(id=2,
title='test quiz 2',
description='d2',
- url='t q2',)
+ url='t q2')
def test_index(self):
response = self.client.get('/q/')
category=self.c1)
self.question1 = MCQuestion.objects.create(id=1,
- content='squawk',)
+ content='squawk')
self.question1.quiz.add(self.quiz1)
self.question2 = MCQuestion.objects.create(id=2,
- content='squeek',)
+ content='squeek')
self.question2.quiz.add(self.quiz1)
self.answer1 = Answer.objects.create(id=123,
question=self.question1,
content='bing',
- correct=False,)
+ correct=False)
self.answer2 = Answer.objects.create(id=456,
question=self.question2,
content='bong',
- correct=True,)
+ correct=True)
def test_quiz_take_anon_view_only(self):
found = resolve('/q/tq1/take/')
self.answer1 = Answer.objects.create(id=123,
question=self.question1,
content='bing',
- correct=False,)
+ correct=False)
self.answer2 = Answer.objects.create(id=456,
question=self.question2,
content='bong',
- correct=True,)
+ correct=True)
def test_quiz_take_user_view_only(self):
sittings_before = Sitting.objects.count()
self.answer1 = Answer.objects.create(id=123,
question=self.question1,
content='bing',
- correct=False,)
+ correct=False)
self.answer2 = Answer.objects.create(id=456,
question=self.question1,
content='bong',
- correct=True,)
+ correct=True)
self.question2 = TF_Question.objects.create(id=3,
content='oink',
self.quiz1 = Quiz.objects.create(id=1,
title='test quiz 1',
description='d1',
- url='tq1',)
+ url='tq1')
self.question1.quiz.add(self.quiz1)
self.question2.quiz.add(self.quiz1)
def test_correct_answer_all_anon(self):
template = Template('{% load quiz_tags %}' +
- '{% correct_answer_for_all_with_users_incorrect' +
- ' question incorrect_questions %}')
+ '{% correct_answer_for_all question %}')
context = Context({'question': self.question1})
def test_correct_answer_all_user(self):
template = Template('{% load quiz_tags %}' +
- '{% correct_answer_for_all_with_users_incorrect ' +
- 'question incorrect_questions %}')
+ '{% correct_answer_for_all question %}')
context = Context({'question': self.question1,
'incorrect_questions': '1,'})