From bd9014ab59ec0006459d55f3af8782efe88e5501 Mon Sep 17 00:00:00 2001 From: Navin Karkera Date: Fri, 17 Jan 2025 20:05:42 +0530 Subject: [PATCH] refactor: rename learning classes --- openedx/core/djangoapps/content_libraries/api.py | 1 + openedx/core/djangoapps/content_libraries/tasks.py | 14 +++++++------- .../tests/test_upstream_downstream_links.py | 3 ++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/openedx/core/djangoapps/content_libraries/api.py b/openedx/core/djangoapps/content_libraries/api.py index 0ed68c36a72..8cd98f3cdd6 100644 --- a/openedx/core/djangoapps/content_libraries/api.py +++ b/openedx/core/djangoapps/content_libraries/api.py @@ -1970,6 +1970,7 @@ def create_or_update_xblock_upstream_link(xblock, course_key: str, course_name: authoring_api.update_or_create_entity_link( lib_component, upstream_usage_key=xblock.upstream, + upstream_context_key=str(upstream_usage_key.context_key), downstream_context_key=course_key, downstream_context_title=course_name, downstream_usage_key=str(xblock.usage_key), diff --git a/openedx/core/djangoapps/content_libraries/tasks.py b/openedx/core/djangoapps/content_libraries/tasks.py index 648960051c0..ffb088f611b 100644 --- a/openedx/core/djangoapps/content_libraries/tasks.py +++ b/openedx/core/djangoapps/content_libraries/tasks.py @@ -32,8 +32,8 @@ from opaque_keys.edx.locator import BlockUsageLocator from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.lib import ensure_cms -from openedx_learning.api.authoring import get_entity_links, get_or_create_course_link_status -from openedx_learning.api.authoring_models import CourseLinksStatusChoices +from openedx_learning.api.authoring import get_entity_links, get_or_create_learning_context_link_status +from openedx_learning.api.authoring_models import LearningContextLinksStatusChoices from xmodule.capa_block import ProblemBlock from xmodule.library_content_block import ANY_CAPA_TYPE_VALUE, LegacyLibraryContentBlock from xmodule.modulestore import ModuleStoreEnum @@ -203,15 +203,15 @@ def create_or_update_upstream_links(course_key_str: str, force: bool = False, cr if not created: created = datetime.now(timezone.utc) - course_status = get_or_create_course_link_status(course_key_str, created) + course_status = get_or_create_learning_context_link_status(course_key_str, created) if course_status.status in [ - CourseLinksStatusChoices.COMPLETED, - CourseLinksStatusChoices.PROCESSING + LearningContextLinksStatusChoices.COMPLETED, + LearningContextLinksStatusChoices.PROCESSING ] and not force: return store = modulestore() course_key = CourseKey.from_string(course_key_str) - course_status.status = CourseLinksStatusChoices.PROCESSING + course_status.status = LearningContextLinksStatusChoices.PROCESSING course_status.save() try: course_name = CourseOverview.get_from_id(course_key).display_name_with_default @@ -221,7 +221,7 @@ def create_or_update_upstream_links(course_key_str: str, force: bool = False, cr xblocks = store.get_items(course_key, settings={"upstream": lambda x: x is not None}) for xblock in xblocks: api.create_or_update_xblock_upstream_link(xblock, course_key_str, course_name, created) - course_status.status = CourseLinksStatusChoices.COMPLETED + course_status.status = LearningContextLinksStatusChoices.COMPLETED course_status.save() diff --git a/openedx/core/djangoapps/content_libraries/tests/test_upstream_downstream_links.py b/openedx/core/djangoapps/content_libraries/tests/test_upstream_downstream_links.py index 3787d3cedcb..7215c8576c8 100644 --- a/openedx/core/djangoapps/content_libraries/tests/test_upstream_downstream_links.py +++ b/openedx/core/djangoapps/content_libraries/tests/test_upstream_downstream_links.py @@ -144,7 +144,8 @@ def test_create_or_update_upstream_links_task(self, mock_api): ] assert [(x[0][0].usage_key, x[0][1], x[0][2], x[0][3]) for x in mock_api.call_args_list] == expected_calls mock_api.reset_mock() - # call again with same course, it should not be processed again as its CourseLinksStatusChoices = COMPLETED + # call again with same course, it should not be processed again + # as its LearningContextLinksStatusChoices = COMPLETED create_or_update_upstream_links(str(self.course_key), force=False) mock_api.assert_not_called() # again with same course but with force=True, it should be processed now