diff --git a/openedx/features/course_experience/tests/views/test_course_home.py b/openedx/features/course_experience/tests/views/test_course_home.py index ab2abc5fef5c..732defd36f6a 100644 --- a/openedx/features/course_experience/tests/views/test_course_home.py +++ b/openedx/features/course_experience/tests/views/test_course_home.py @@ -205,7 +205,7 @@ def test_queries(self): # Fetch the view and verify the query counts # TODO: decrease query count as part of REVO-28 - with self.assertNumQueries(66, table_ignorelist=QUERY_COUNT_TABLE_IGNORELIST): + with self.assertNumQueries(70, table_ignorelist=QUERY_COUNT_TABLE_IGNORELIST): with check_mongo_calls(3): url = course_home_url(self.course) self.client.get(url) diff --git a/openedx/features/course_experience/utils.py b/openedx/features/course_experience/utils.py index 5f42d2c7e108..acf02be1c4cf 100644 --- a/openedx/features/course_experience/utils.py +++ b/openedx/features/course_experience/utils.py @@ -6,6 +6,7 @@ from opaque_keys.edx.keys import CourseKey from lms.djangoapps.badges.models import BlockEventBadgesConfiguration +from lms.djangoapps.courseware.tabs import get_course_tab_list from lms.djangoapps.course_api.blocks.api import get_blocks from lms.djangoapps.course_blocks.api import get_course_blocks from openedx.core.djangoapps.content.course_overviews.models import CourseOverview @@ -114,8 +115,10 @@ def recurse_mark_badge_progress(block): for block_event_badge_config in BlockEventBadgesConfiguration.config_for_block_event( course_id=course_key, event_type='chapter_complete' ): + # Indicate the a module has completed badge progress if configured and badges tab + # is enabled for the course. if block.get('block_id', False) == block_event_badge_config.usage_key.block_id and \ - block_event_badge_config.badge_class: + block_event_badge_config.badge_class and course_badge_tab_exists: block['badge_progress'] = True return True @@ -154,6 +157,13 @@ def recurse_mark_badge_progress(block): ) course_outline_root_block = all_blocks['blocks'].get(all_blocks['root'], None) + + # Identify if the `Badges` tab is enabled. + course_badge_tab_exists = False + for tab in get_course_tab_list(user, CourseOverview.objects.get(id=str(course_key))): + if tab.tab_id == "badges_progress": + course_badge_tab_exists = True + if course_outline_root_block: populate_children(course_outline_root_block, all_blocks['blocks']) recurse_mark_scored(course_outline_root_block)