Merge pull request #18727 from edx/ziafazal/gating-exclude-non-completable
exclude non completable blocks when calculating completion percentage
This commit is contained in:
@@ -100,6 +100,17 @@ class TestGatedContent(MilestonesTestCaseMixin, SharedModuleStoreTestCase):
|
||||
category='problem',
|
||||
display_name='gating problem 1',
|
||||
)
|
||||
# add a discussion block to the prerequisite subsection
|
||||
# this should give us ability to test gating with blocks
|
||||
# which needs to be excluded from completion tracking
|
||||
ItemFactory.create(
|
||||
parent_location=cls.seq1.location,
|
||||
category="discussion",
|
||||
discussion_id="discussion 1",
|
||||
discussion_category="discussion category",
|
||||
discussion_target="discussion target",
|
||||
)
|
||||
|
||||
cls.gated_prob2 = ItemFactory.create(
|
||||
parent_location=cls.seq2.location,
|
||||
category='problem',
|
||||
|
||||
@@ -16,6 +16,7 @@ from milestones import api as milestones_api
|
||||
from opaque_keys.edx.keys import UsageKey
|
||||
from openedx.core.lib.gating.exceptions import GatingValidationError
|
||||
from util import milestones_helpers
|
||||
from xblock.completable import XBlockCompletionMode as CompletionMode
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from xmodule.modulestore.exceptions import ItemNotFoundError
|
||||
|
||||
@@ -463,10 +464,15 @@ def get_subsection_completion_percentage(subsection_usage_key, user):
|
||||
try:
|
||||
subsection_structure = get_course_blocks(user, subsection_usage_key)
|
||||
if any(subsection_structure):
|
||||
completable_blocks = [
|
||||
block for block in subsection_structure
|
||||
if block.block_type not in ['chapter', 'sequential', 'vertical']
|
||||
]
|
||||
completable_blocks = []
|
||||
for block in subsection_structure:
|
||||
completion_mode = subsection_structure.get_xblock_field(
|
||||
block, 'completion_mode'
|
||||
)
|
||||
|
||||
if completion_mode not in (CompletionMode.AGGREGATOR, CompletionMode.EXCLUDED):
|
||||
completable_blocks.append(block)
|
||||
|
||||
if not completable_blocks:
|
||||
return 0
|
||||
subsection_completion_total = 0
|
||||
|
||||
Reference in New Issue
Block a user