Commit f0c75daa by Xavier Antoviaque

Adds dependency between mentoring blocks & warning message when not met

parent 9918a144
...@@ -27,9 +27,20 @@ class MentoringBlock(XBlock, XBlockWithChildrenFragmentsMixin): ...@@ -27,9 +27,20 @@ class MentoringBlock(XBlock, XBlockWithChildrenFragmentsMixin):
student is a) provided mentoring advices and asked to alter his answer, or b) is given the student is a) provided mentoring advices and asked to alter his answer, or b) is given the
ok to continue. ok to continue.
""" """
attempted = Boolean(help="Has the student attempted this mentoring step?", default=False, scope=Scope.user_state) attempted = Boolean(help="Has the student attempted this mentoring step?",
completed = Boolean(help="Has the student completed this mentoring step?", default=False, scope=Scope.user_state) default=False, scope=Scope.user_state)
completed_message = String(help="Message to display upon completion", scope=Scope.content, default="") completed = Boolean(help="Has the student completed this mentoring step?",
default=False, scope=Scope.user_state)
completed_message = String(help="Message to display upon completion",
scope=Scope.content, default="")
next_step = String(help="url_name of the next step the student must complete (global to all blocks)",
default='mentoring_first', scope=Scope.preferences)
followed_by = String(help="url_name of the step after the current mentoring block in workflow",
default=None, scope=Scope.content)
url_name = String(help="Name of the current step, used for URL building",
default='mentoring', scope=Scope.content)
enforce_dependency = Boolean(help="Should the next step be the current block to complete?",
default=True, scope=Scope.content)
has_children = True has_children = True
@classmethod @classmethod
...@@ -57,6 +68,7 @@ class MentoringBlock(XBlock, XBlockWithChildrenFragmentsMixin): ...@@ -57,6 +68,7 @@ class MentoringBlock(XBlock, XBlockWithChildrenFragmentsMixin):
fragment.add_content(render_template('templates/html/mentoring.html', { fragment.add_content(render_template('templates/html/mentoring.html', {
'self': self, 'self': self,
'named_children': named_children, 'named_children': named_children,
'missing_dependency_url': self.has_missing_dependency and self.next_step_url,
})) }))
fragment.add_css(load_resource('static/css/mentoring.css')) fragment.add_css(load_resource('static/css/mentoring.css'))
fragment.add_javascript(load_resource('static/js/vendor/underscore-min.js')) fragment.add_javascript(load_resource('static/js/vendor/underscore-min.js'))
...@@ -71,6 +83,21 @@ class MentoringBlock(XBlock, XBlockWithChildrenFragmentsMixin): ...@@ -71,6 +83,21 @@ class MentoringBlock(XBlock, XBlockWithChildrenFragmentsMixin):
return fragment return fragment
@property
def has_missing_dependency(self):
"""
Returns True if the student needs to complete another step before being able to complete
the current one, and False otherwise
"""
return self.enforce_dependency and (not self.completed) and (self.next_step != self.url_name)
@property
def next_step_url(self):
"""
Returns the URL of the next step's page
"""
return '/jump_to_id/{}'.format(self.next_step)
@XBlock.json_handler @XBlock.json_handler
def submit(self, submissions, suffix=''): def submit(self, submissions, suffix=''):
log.info(u'Received submissions: {}'.format(submissions)) log.info(u'Received submissions: {}'.format(submissions))
...@@ -87,12 +114,19 @@ class MentoringBlock(XBlock, XBlockWithChildrenFragmentsMixin): ...@@ -87,12 +114,19 @@ class MentoringBlock(XBlock, XBlockWithChildrenFragmentsMixin):
child.save() child.save()
completed = completed and child_result['completed'] completed = completed and child_result['completed']
self.completed = bool(completed) if completed:
if self.completed:
message = self.completed_message message = self.completed_message
else: else:
message = '' message = ''
if self.has_missing_dependency:
completed = False
message = 'You need to complete all previous steps before being able to complete '+\
'the current one.'
elif completed and self.next_step == self.url_name:
self.next_step = self.followed_by
self.completed = bool(completed)
return { return {
'submitResults': submit_results, 'submitResults': submit_results,
'completed': self.completed, 'completed': self.completed,
......
.messages { .mentoring .messages {
margin-top: 10px; margin-top: 10px;
} }
.mentoring .warning {
border: 1px solid;
margin: 10px 0px;
padding:15px 10px;
-moz-border-radius:.5em;
-webkit-border-radius:.5em;
border-radius:.5em;
color: #9F6000;
background-color: #FEEFB3;
}
<div class="mentoring"> <div class="mentoring">
{% if missing_dependency_url %}
<div class="warning">
You need to complete <a href="{{ missing_dependency_url }}">the following step</a> before
attempting this step.
</div>
{% endif %}
{% for name, c in named_children %} {% for name, c in named_children %}
{{c.body_html|safe}} {{c.body_html|safe}}
{% endfor %} {% endfor %}
......
Subproject commit 83c5f4eef7b995e3720b80f67c70eaf634966298 Subproject commit 4b9773a832c06d91da2b2446bdf2682be28de3bc
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