Commit 859aaff4 by dragonfi

Use str instead of mixed types for completion status

parent beb43c10
...@@ -121,18 +121,18 @@ class AnswerBlock(LightChild, StepMixin): ...@@ -121,18 +121,18 @@ class AnswerBlock(LightChild, StepMixin):
log.info(u'Answer submitted for`{}`: "{}"'.format(self.name, self.student_input)) log.info(u'Answer submitted for`{}`: "{}"'.format(self.name, self.student_input))
return { return {
'student_input': self.student_input, 'student_input': self.student_input,
'completed': self.completed, 'status': self.status,
'weight': self.weight, 'weight': self.weight,
'score': 1 if self.completed else 0, 'score': 1 if self.status == 'correct' else 0,
} }
@property @property
def completed(self): def status(self):
answer_length_ok = self.student_input answer_length_ok = self.student_input
if self.min_characters > 0: if self.min_characters > 0:
answer_length_ok = len(self.student_input.strip()) >= self.min_characters answer_length_ok = len(self.student_input.strip()) >= self.min_characters
return bool(self.read_only or answer_length_ok) return 'correct' if (self.read_only or answer_length_ok) else 'incorrect'
def save(self): def save(self):
""" """
......
...@@ -52,31 +52,31 @@ class MCQBlock(QuestionnaireAbstractBlock): ...@@ -52,31 +52,31 @@ class MCQBlock(QuestionnaireAbstractBlock):
def submit(self, submission): def submit(self, submission):
log.debug(u'Received MCQ submission: "%s"', submission) log.debug(u'Received MCQ submission: "%s"', submission)
completed = True correct = True
tips_fragments = [] tips_fragments = []
for tip in self.get_tips(): for tip in self.get_tips():
completed = completed and self.is_tip_completed(tip, submission) correct = correct and self.is_tip_correct(tip, submission)
if submission in tip.display_with_defaults: if submission in tip.display_with_defaults:
tips_fragments.append(tip.render()) tips_fragments.append(tip.render())
formatted_tips = render_template('templates/html/tip_choice_group.html', { formatted_tips = render_template('templates/html/tip_choice_group.html', {
'self': self, 'self': self,
'tips_fragments': tips_fragments, 'tips_fragments': tips_fragments,
'completed': completed, 'completed': correct,
}) })
self.student_choice = submission self.student_choice = submission
result = { result = {
'submission': submission, 'submission': submission,
'completed': completed, 'status': 'correct' if correct else 'incorrect',
'tips': formatted_tips, 'tips': formatted_tips,
'weight': self.weight, 'weight': self.weight,
'score': 1 if completed else 0, 'score': 1 if correct else 0,
} }
log.debug(u'MCQ submission result: %s', result) log.debug(u'MCQ submission result: %s', result)
return result return result
def is_tip_completed(self, tip, submission): def is_tip_correct(self, tip, submission):
if not submission: if not submission:
return False return False
......
...@@ -113,9 +113,9 @@ class MentoringBlock(XBlockWithLightChildren, StepParentMixin): ...@@ -113,9 +113,9 @@ class MentoringBlock(XBlockWithLightChildren, StepParentMixin):
if total_child_weight == 0: if total_child_weight == 0:
return (0, 0, 0, 0) return (0, 0, 0, 0)
score = sum(r[1]['score'] * r[1]['weight'] for r in self.student_results) / total_child_weight score = sum(r[1]['score'] * r[1]['weight'] for r in self.student_results) / total_child_weight
correct = sum(1 for r in self.student_results if r[1]['completed'] is True) correct = sum(1 for r in self.student_results if r[1]['status'] == 'correct')
incorrect = sum(1 for r in self.student_results if r[1]['completed'] is False) incorrect = sum(1 for r in self.student_results if r[1]['status'] == 'incorrect')
partially_correct = sum(1 for r in self.student_results if r[1]['completed'] is 'partial') partially_correct = sum(1 for r in self.student_results if r[1]['status'] == 'partial')
return (score, int(round(score * 100)), correct, incorrect, partially_correct) return (score, int(round(score * 100)), correct, incorrect, partially_correct)
...@@ -217,7 +217,7 @@ class MentoringBlock(XBlockWithLightChildren, StepParentMixin): ...@@ -217,7 +217,7 @@ class MentoringBlock(XBlockWithLightChildren, StepParentMixin):
child_result = child.submit(submission) child_result = child.submit(submission)
submit_results.append([child.name, child_result]) submit_results.append([child.name, child_result])
child.save() child.save()
completed = completed and (child_result['completed'] is True) completed = completed and (child_result['status'] == 'correct')
if self.max_attempts_reached: if self.max_attempts_reached:
message = self.get_message_html('max_attempts_reached') message = self.get_message_html('max_attempts_reached')
...@@ -303,7 +303,7 @@ class MentoringBlock(XBlockWithLightChildren, StepParentMixin): ...@@ -303,7 +303,7 @@ class MentoringBlock(XBlockWithLightChildren, StepParentMixin):
del child_result['tips'] del child_result['tips']
self.student_results.append([child.name, child_result]) self.student_results.append([child.name, child_result])
child.save() child.save()
completed = child_result['completed'] completed = child_result['status'] == 'correct'
event_data = {} event_data = {}
......
...@@ -83,11 +83,11 @@ class MRQBlock(QuestionnaireAbstractBlock): ...@@ -83,11 +83,11 @@ class MRQBlock(QuestionnaireAbstractBlock):
self.student_choices = submissions self.student_choices = submissions
completed = False if score <= 0 else True if score >= len(results) else 'partial' status = 'incorrect' if score <= 0 else 'correct' if score >= len(results) else 'partial'
result = { result = {
'submissions': submissions, 'submissions': submissions,
'completed': completed, 'status': status,
'choices': results, 'choices': results,
'message': self.message, 'message': self.message,
'weight': self.weight, 'weight': self.weight,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment