From e986d360c926bff2c925e06240934d1596849610 Mon Sep 17 00:00:00 2001 From: DawoudSheraz Date: Fri, 3 Sep 2021 12:40:28 +0500 Subject: [PATCH] refactor: move course location util to common djangoapp instead of xmodule --- Makefile | 2 +- common/djangoapps/util/course.py | 10 ++++++++++ common/lib/xmodule/xmodule/contentstore/utils.py | 10 ---------- common/test/acceptance/fixtures/course.py | 2 +- lms/djangoapps/courseware/views/views.py | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 870d54579e..f5e14cf03b 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ extract_translations: ## extract localizable strings from sources push_translations: ## push source strings to Transifex for translation i18n_tool transifex push -pull_translations: requirements ## pull translations from Transifex +pull_translations: ## pull translations from Transifex git clean -fdX conf/locale i18n_tool transifex pull i18n_tool extract diff --git a/common/djangoapps/util/course.py b/common/djangoapps/util/course.py index 1a894003e0..0df1208ae3 100644 --- a/common/djangoapps/util/course.py +++ b/common/djangoapps/util/course.py @@ -7,6 +7,7 @@ import logging from urllib.parse import urlencode from django.conf import settings +from opaque_keys.edx.keys import CourseKey, UsageKey from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers @@ -70,3 +71,12 @@ def has_certificates_enabled(course): if not settings.FEATURES.get('CERTIFICATES_HTML_VIEW', False): return False return course.cert_html_view_enabled + + +def course_location_from_key(course_key: CourseKey) -> UsageKey: + """Creates a usage key for the toplevel course item, handling differences between mongo and newer keys""" + if getattr(course_key, 'deprecated', False): + block_id = course_key.run + else: + block_id = 'course' + return course_key.make_usage_key('course', block_id) diff --git a/common/lib/xmodule/xmodule/contentstore/utils.py b/common/lib/xmodule/xmodule/contentstore/utils.py index f018d2d09e..002e83969d 100644 --- a/common/lib/xmodule/xmodule/contentstore/utils.py +++ b/common/lib/xmodule/xmodule/contentstore/utils.py @@ -1,6 +1,5 @@ # lint-amnesty, pylint: disable=missing-module-docstring -from opaque_keys.edx.keys import CourseKey, UsageKey from xmodule.contentstore.content import StaticContent from .django import contentstore @@ -46,12 +45,3 @@ def restore_asset_from_trashcan(location): store.save(thumbnail_content) except Exception: # lint-amnesty, pylint: disable=broad-except pass # OK if this is left dangling - - -def course_location_from_key(course_key: CourseKey) -> UsageKey: - """Creates a usage key for the toplevel course item, handling differences between mongo and newer keys""" - if getattr(course_key, 'deprecated', False): - block_id = course_key.run - else: - block_id = 'course' - return course_key.make_usage_key('course', block_id) diff --git a/common/test/acceptance/fixtures/course.py b/common/test/acceptance/fixtures/course.py index 3aeef76ac8..bf469e8c50 100644 --- a/common/test/acceptance/fixtures/course.py +++ b/common/test/acceptance/fixtures/course.py @@ -14,7 +14,7 @@ from path import Path from common.test.acceptance.fixtures import STUDIO_BASE_URL from common.test.acceptance.fixtures.base import FixtureError, XBlockContainerFixture -from xmodule.contentstore.utils import course_location_from_key +from common.djangoapps.util.course import course_location_from_key class XBlockFixtureDesc: diff --git a/lms/djangoapps/courseware/views/views.py b/lms/djangoapps/courseware/views/views.py index 16a1d0ee1f..158bd65919 100644 --- a/lms/djangoapps/courseware/views/views.py +++ b/lms/djangoapps/courseware/views/views.py @@ -124,10 +124,10 @@ from openedx.features.course_experience.waffle import waffle as course_experienc from openedx.features.enterprise_support.api import data_sharing_consent_required from common.djangoapps.student.models import CourseEnrollment, UserTestGroup from common.djangoapps.util.cache import cache, cache_if_anonymous +from common.djangoapps.util.course import course_location_from_key from common.djangoapps.util.db import outer_atomic from common.djangoapps.util.milestones_helpers import get_prerequisite_courses_display from common.djangoapps.util.views import ensure_valid_course_key, ensure_valid_usage_key -from xmodule.contentstore.utils import course_location_from_key from xmodule.course_module import COURSE_VISIBILITY_PUBLIC, COURSE_VISIBILITY_PUBLIC_OUTLINE from xmodule.modulestore.django import modulestore from xmodule.modulestore.exceptions import ItemNotFoundError, NoPathToItem