Commit 677ffef8 by Tim Krones

Update num_attempts field of new mentoring block after submitting last step.

parent 839840a3
...@@ -976,6 +976,11 @@ class MentoringWithExplicitStepsBlock(BaseMentoringBlock, StudioContainerWithNes ...@@ -976,6 +976,11 @@ class MentoringWithExplicitStepsBlock(BaseMentoringBlock, StudioContainerWithNes
} }
@XBlock.json_handler @XBlock.json_handler
def update_num_attempts(self, data, suffix=''):
self.num_attempts += 1
return {}
@XBlock.json_handler
def try_again(self, data, suffix=''): def try_again(self, data, suffix=''):
self.active_step = 0 self.active_step = 0
......
...@@ -26,9 +26,17 @@ function MentoringWithStepsBlock(runtime, element) { ...@@ -26,9 +26,17 @@ function MentoringWithStepsBlock(runtime, element) {
}); });
} }
function updateNumAttempts() {
var handlerUrl = runtime.handlerUrl(element, 'update_num_attempts');
$.post(handlerUrl, JSON.stringify({}));
}
function handleResults(response) { function handleResults(response) {
// Update active step so next step is shown on page reload (even if user does not click "Next Step") // Update active step so next step is shown on page reload (even if user does not click "Next Step")
updateActiveStep(activeStep+1); updateActiveStep(activeStep+1);
if (response.update_attempts) {
updateNumAttempts();
}
// Update UI // Update UI
if (response.completed === 'correct') { if (response.completed === 'correct') {
......
...@@ -103,6 +103,11 @@ class MentoringStepBlock( ...@@ -103,6 +103,11 @@ class MentoringStepBlock(
return self.get_parent().steps return self.get_parent().steps
@property @property
def is_last_step(self):
parent = self.get_parent()
return self.step_number == len(parent.steps)
@property
def allowed_nested_blocks(self): def allowed_nested_blocks(self):
""" """
Returns a list of allowed nested XBlocks. Each item can be either Returns a list of allowed nested XBlocks. Each item can be either
...@@ -149,6 +154,7 @@ class MentoringStepBlock( ...@@ -149,6 +154,7 @@ class MentoringStepBlock(
'message': 'Success!', 'message': 'Success!',
'completed': completed, 'completed': completed,
'results': submit_results, 'results': submit_results,
'update_attempts': self.is_last_step
} }
def reset(self): def reset(self):
......
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