return str(self)
+class MatchingQuestion(BaseQuizQuestion):
+ def __init__(self, question_text, left_column, right_column, left_right_mapping):
+ self.question_text = question_text
+ self.left_column = left_column
+ self.right_column = right_column
+ self.left_right_mapping = left_right_mapping
+
+ def rows(self):
+ return zip(self.left_column, self.right_column)
+
+ def __unicode__(self):
+ return u"Matching question: {0} / {1}".format(self.left_column, self.right_column)
+
+ def __str__(self):
+ return unicode(self)
+
+ def __repr__(self):
+ return str(self)
+
+
KEYWORD_MULTIPLE_CHOICE = 1
DEFINITION_MULTIPLE_CHOICE = 2
KEYWORD_DEFINITION_TRUE_FALSE = 3
+KEYWORD_DEFINITION_MATCHING = 4
GENERATED_QUESTION_TYPE = (
KEYWORD_MULTIPLE_CHOICE,
DEFINITION_MULTIPLE_CHOICE,
KEYWORD_DEFINITION_TRUE_FALSE,
+ KEYWORD_DEFINITION_MATCHING,
)
MULTIPLE_CHOICE_CHOICES = 4
return TrueFalseQuestion(question_text, true)
+def _create_keyword_definition_matching(keyword, keywords):
+ question_keywords = [keyword]
+ question_keywords.extend(random.sample(keywords.exclude(id=keyword.id), MULTIPLE_CHOICE_CHOICES - 1))
+
+ answer_mapping = {k.word: k.definition for k in question_keywords}
+ word_column = [k.word for k in question_keywords]
+ random.shuffle(word_column)
+ definition_column = [k.definition for k in question_keywords]
+ random.shuffle(definition_column)
+
+ question_text = u'Match the words with their definitions'
+
+ return MatchingQuestion(question_text, left_column=word_column,
+ right_column=definition_column, left_right_mapping=answer_mapping)
+
+
def quiz_from_keywords(note):
keywords = Keyword.objects.filter(note=note).exclude(word__iexact='').exclude(definition__iexact='')
questions = []
elif question_type is KEYWORD_DEFINITION_TRUE_FALSE:
questions.append(_create_keyword_definition_true_false(keyword, keywords))
+ elif question_type is KEYWORD_DEFINITION_MATCHING:
+ questions.append(_create_keyword_definition_matching(keyword, keywords))
+
return questions
$('.quiz-question-wrapper').each(function() {
var choice = $(this).find('input:checked');
if (choice.length) {
- console.log(choice);
if (choice.data('correct') == true) {
markQuestionCorrect($(this));
} else {
markQuestionIncorrect($(this));
}
}
+
+ var matching_correct = false;
+ var options_selected = $(this).find('option:selected');
+ if (options_selected.length > 0) {
+ matching_correct = true
+ }
+ options_selected.each(function() {
+ if ($(this).data('correct') == false) {
+ matching_correct = false;
+ }
+ });
+ if (matching_correct) {
+ markQuestionCorrect($(this));
+ } else {
+ markQuestionIncorrect($(this));
+ }
+
});
});
}
+{% load notes %}
+
<div id="quiz" class="content">
<div class="row">
<div class="small-12 columns">
<label for="choice_{{ forloop.counter0 }}_false">False</label>
</div>
{% endif %}
+ {% if question.question_type == 'MatchingQuestion' %}
+ {% for row in question.rows %}
+ <div class="question-choices row">
+ <div class="small-6 columns">
+ {% with left_row=row.0 %}
+ <div class="matching-choice">
+ <div class="select-wrapper matching-select-wrapper inline">
+ <select class="inline matching-select" id="group_{ forloop.parentloop.counter0 }}_{{ forloop.counter0 }}">
+ {% for right_row in question.right_column %}
+ <option {% if question.left_right_mapping|keyvalue:left_row == right_row %}
+ data-correct="true"
+ {% else %}
+ data-correct="false"
+ {% endif %}>
+ {{ forloop.counter0|ordinal_letter }}
+ </option>
+ {% endfor %}
+ </select>
+ </div>
+ <label class="matching-select-label" for="group_{ forloop.parentloop.counter0 }}_{{ forloop.counter0 }}">{{ left_row }}</label>
+ </div>
+ {% endwith %}
+ </div>
+ <div class="small-6 columns">
+ {% with right_row=row.1 %}
+ <div class="matching-choice">
+ <strong>{{ forloop.counter0|ordinal_letter }}.</strong> {{ right_row }}
+ </div>
+ {% endwith %}
+ </div>
+ </div>
+ {% endfor %}
+ {% endif %}
</div>
</div>
</div>