class MCQuestion(Question):
+ def check_if_correct(self, guess):
+ answer = Answer.objects.get(id = guess)
+
+ if answer.correct == True:
+ return True
+ else:
+ return False
+
class Meta:
verbose_name = "Multiple Choice Question"
verbose_name_plural = "Multiple Choice Questions"
def update_score(self, category_queried, score_to_add, possible_to_add):
"""
- Pass in category, amount to increase score and max possible
- increase if all were correct.
+ Pass in category, amount to increase score and max possible.
+ Increase if all were correct.
Does not return anything.
"""
self.save()
def add_to_score(self, points):
- present_score = self.get_current_score()
+ present_score = int(self.get_current_score())
updated_score = present_score + int(points)
self.current_score = updated_score
self.save()
register = template.Library()
-@register.inclusion_tag('answers_for_question.html', takes_context=True)
-def answers_for_question(context, question, quiz):
- """
- Displays the possible answers to a question
- """
+@register.inclusion_tag('answers_for_mc_question.html', takes_context=True)
+def answers_for_mc_question(context, question, quiz):
answers = Answer.objects.filter(question__id=question.id).order_by('?')
- return {'answers': answers, 'quiz': quiz}
+ return {'answers': answers,}
@register.inclusion_tag('correct_answer.html', takes_context=True)
def correct_answer(context, previous):
# if there has been a previous question
# returns a dictionary with previous question details
previous = question_check_anon(request, quiz)
-
- request.session[str(quiz.id)+ "_q_list"] = question_list[1:]
+ question_list = question_list[1:]
+ request.session[str(quiz.id)+ "_q_list"] = question_list
request.session['page_count'] = request.session['page_count'] + 1
if not request.session[str(quiz.id)+ "_q_list"]:
# except KeyError:
# request.session['page_count'] = 0
- next_question = Question.objects.get_subclass(id = next_question_id)
+ next_question = Question.objects.get_subclass(id = question_ID)
question_type = next_question.__class__.__name__
return render_to_response('question.html',
def question_check_anon(request, quiz):
guess = request.GET['guess']
- answer = Answer.objects.get(id = guess)
- question = answer.question # the id of the question
+ question_id = request.GET['question_id']
+ question = Question.objects.get_subclass(id = question_id)
+ is_correct = question.check_if_correct(guess)
- if answer.correct == True:
+ if is_correct == True:
outcome = "correct"
current = request.session[str(quiz.id) + "_score"]
request.session[str(quiz.id) + "_score"] = int(current) + 1
anon_session_score(request, 0, 1)
if quiz.answers_at_end != True:
- return {'previous_answer': answer,
+ return {'previous_answer': guess,
'previous_outcome': outcome,
'previous_question': question,}
def question_check_user(request, quiz, sitting):
guess = request.GET['guess']
- answer = Answer.objects.get(id = guess)
- question = answer.question
+ question_id = request.GET['question_id']
+ question = Question.objects.get_subclass(id = question_id)
+ is_correct = question.check_if_correct(guess)
- if answer.correct == True:
+ if is_correct == True:
outcome = "correct"
sitting.add_to_score(1)
user_progress_score_update(request, question.category, 1, 1)
user_progress_score_update(request, question.category, 0, 1)
if quiz.answers_at_end != True:
- return {'previous_answer': answer,
+ return {'previous_answer': guess,
'previous_outcome': outcome,
'previous_question': question,}
else:
--- /dev/null
+{% for answer in answers %}
+<tr>
+ <td>
+ <label>
+ <input type="radio" name="guess" value="{{ answer.id }}" class="form-radio">
+ {{ answer.content }}
+ </label>
+ </td>
+</tr>
+{% endfor %}
-<form action="/{{ quiz.url }}/take/" method="get">
-
-
-<table class="table table-hover table-bordered" id="answerchoice">
-<tbody>
-
-
-{% for answer in answers %}
- <tr>
- <td>
- <label>
- <input type="radio" name="guess" value="{{ answer.id }}" class="form-radio">
- {{ answer.content }}
- </label>
- </td>
- </tr>
-{% endfor %}
-</form>
-</tbody>
-</table>
-<input type="submit" value="Check" class="btn btn-large btn-block btn-warning" >
--- /dev/null
+<tr>
+ <td>
+ <label>
+ <input type="radio" name="guess" value="T" class="form-radio">
+ True
+ </label>
+ </td>
+</tr>
+<tr>
+ <td>
+ <label>
+ <input type="radio" name="guess" value="F" class="form-radio">
+ False
+ </label>
+ </td>
+</tr>
<p>{{ question.id }}</p>
<p>{{ question_type }}</p>
<p class="lead">{{ question.content }}</p>
- {% answers_for_question question quiz %}
+
+ <form action="{% url 'quiz_question' quiz.url %}" method="get">
+ <p>quid {{ question.id }}</p>
+ <input type=hidden name="question_id" value="{{ question.id }}">
+
+ <table class="table table-hover table-bordered" id="answerchoice">
+ <tbody>
+
+ {% ifequal question_type 'TF_Question' %}
+ {% include 'answers_for_tf_question.html' %}
+ {% endifequal %}
+
+ {% ifequal question_type 'MCQuestion' %}
+ {% answers_for_mc_question question quiz %}
+ {% endifequal %}
+
+ </tbody>
+ </table>
+ <input type="submit" value="Check" class="btn btn-large btn-block btn-warning" >
+ </form>
+
{% endif %}
default = False,
help_text = ("Tick this if the question " +
"is true. Leave it blank for" +
- "false."),)
+ " false."),)
+
+ def check_if_correct(self, guess):
+ if guess == "T":
+ guess_bool = True
+ else:
+ guess_bool = False
+
+ if guess_bool == self.correct:
+ return True
+ else:
+ return False
class Meta:
verbose_name = "True/False Question"