Commit 869ad9aa by Bill Filler

Merge branch 'bfiller/gated-content-block' into bfiller/gated-content-combined

parents 67e98b72 ce919e8b
...@@ -298,6 +298,8 @@ class SequenceModule(SequenceFields, ProctoringFields, XModule): ...@@ -298,6 +298,8 @@ class SequenceModule(SequenceFields, ProctoringFields, XModule):
else: else:
# check if prerequiste has been met # check if prerequiste has been met
prereq_met, prereq_meta_info = self._compute_is_prereq_met(True) prereq_met, prereq_meta_info = self._compute_is_prereq_met(True)
if prereq_met and not self._is_gate_fulfilled():
banner_text = _('This section is a prerequiste. You must complete this section in order to unlock additional content.')
fragment = Fragment() fragment = Fragment()
params = { params = {
...@@ -323,6 +325,23 @@ class SequenceModule(SequenceFields, ProctoringFields, XModule): ...@@ -323,6 +325,23 @@ class SequenceModule(SequenceFields, ProctoringFields, XModule):
return fragment return fragment
def _is_gate_fulfilled(self):
"""
Determines if this section is a prereq and has any unfulfilled milestones.
Returns:
True if section has no unfufilled milestones or is not a prerequiste.
False otherwise
"""
gating_service = self.runtime.service(self, 'gating')
if gating_service:
fulfilled = gating_service.is_gate_fulfilled(
self.course_id, self.location, self.runtime.user_id
)
return fulfilled
return True
def _is_prereq_required(self): def _is_prereq_required(self):
""" """
Checks whether a prerequiste is required for this Section Checks whether a prerequiste is required for this Section
......
...@@ -306,6 +306,34 @@ def get_gated_content(course, user): ...@@ -306,6 +306,34 @@ def get_gated_content(course, user):
] ]
def is_gate_fulfilled(course_key, gating_content_key, user_id):
"""
Determines if a prerequiste section specified by gating_content_key
has any unfulfilled milestones.
Arguments:
course_key (CourseUsageLocator): Course locator
gating_content_key (BlockUsageLocator): The locator for the section content
user_id: The id of the user
Returns:
Returns True if section has no unfufilled milestones or is not a prerequiste.
Returns False otherwise
"""
gating_milestone = get_gating_milestone(course_key, gating_content_key, "fulfills")
if not gating_milestone:
return True
unfulfilled_milestones = [
m['content_id'] for m in milestones_helpers.get_course_content_milestones(
course_key,
None,
'requires',
user_id
) if m['namespace'] == gating_milestone['namespace']
]
return not unfulfilled_milestones
def compute_is_prereq_met(content_id, user_id, recalc_on_unmet=False): def compute_is_prereq_met(content_id, user_id, recalc_on_unmet=False):
""" """
Returns true if the prequiste has been met for a given milestone. Returns true if the prequiste has been met for a given milestone.
...@@ -329,6 +357,7 @@ def compute_is_prereq_met(content_id, user_id, recalc_on_unmet=False): ...@@ -329,6 +357,7 @@ def compute_is_prereq_met(content_id, user_id, recalc_on_unmet=False):
'requires', 'requires',
user_id user_id
) )
prereq_met = not unfulfilled_milestones prereq_met = not unfulfilled_milestones
prereq_meta_info = {'url': None, 'display_name': None} prereq_meta_info = {'url': None, 'display_name': None}
......
...@@ -37,3 +37,19 @@ class GatingService(object): ...@@ -37,3 +37,19 @@ class GatingService(object):
dict or None: The gating milestone dict or None dict or None: The gating milestone dict or None
""" """
return gating_api.get_gating_milestone(course_key, content_key, relationship) return gating_api.get_gating_milestone(course_key, content_key, relationship)
def is_gate_fulfilled(self, course_key, gating_content_key, user_id):
"""
Determines if a prerequiste section specified by gating_content_key
has any unfulfilled milestones.
Arguments:
course_key (CourseUsageLocator): Course locator
gating_content_key (BlockUsageLocator): The locator for the section content
user_id: The id of the user
Returns:
Returns True if section has no unfufilled milestones or is not a prerequiste.
Returns False otherwise
"""
return gating_api.is_gate_fulfilled(course_key, gating_content_key, user_id)
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