Commit bef01e81 by Tim Krones

DRY out code that computes current status (correct/partial/incorrect) of step.

parent 1a3602d8
......@@ -36,9 +36,9 @@ function MentoringWithStepsBlock(runtime, element) {
}
function showFeedback(response) {
if (response.completed === 'correct') {
if (response.step_status === 'correct') {
checkmark.addClass('checkmark-correct icon-ok fa-check');
} else if (response.completed === 'partial') {
} else if (response.step_status === 'partial') {
checkmark.addClass('checkmark-partially-correct icon-ok fa-check');
} else {
checkmark.addClass('checkmark-incorrect icon-exclamation fa-exclamation');
......
......@@ -142,19 +142,10 @@ class MentoringStepBlock(
for result in submit_results:
self.student_results.append(result)
# Compute "answer status" for this step
if all(result[1]['status'] == 'correct' for result in submit_results):
completed = Correctness.CORRECT
elif all(result[1]['status'] == 'incorrect' for result in submit_results):
completed = Correctness.INCORRECT
else:
completed = Correctness.PARTIAL
return {
'message': 'Success!',
'completed': completed,
'step_status': self.answer_status,
'results': submit_results,
'attempt_complete': self.is_last_step
}
@XBlock.json_handler
......@@ -166,24 +157,26 @@ class MentoringStepBlock(
result = question.get_results(previous_results)
results[question.name] = result
# Compute "answer status" for this step
if all(result[1]['status'] == 'correct' for result in self.student_results):
completed = Correctness.CORRECT
elif all(result[1]['status'] == 'incorrect' for result in self.student_results):
completed = Correctness.INCORRECT
else:
completed = Correctness.PARTIAL
# Add 'message' to results? Looks like it's not used on the client ...
return {
'results': results,
'completed': completed,
'step_status': self.answer_status,
}
def reset(self):
while self.student_results:
self.student_results.pop()
@property
def answer_status(self):
if all(result[1]['status'] == 'correct' for result in self.student_results):
answer_status = Correctness.CORRECT
elif all(result[1]['status'] == 'incorrect' for result in self.student_results):
answer_status = Correctness.INCORRECT
else:
answer_status = Correctness.PARTIAL
return answer_status
def author_edit_view(self, context):
"""
Add some HTML to the author view that allows authors to add child blocks.
......
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