refactor: Move get_course_by_id helper from LMS to core
This helper is used by the LMS, CMS, _and_ `openedx.core`, so let's move it to `openedx.core` to reduce import complexity. The following files no longer import from LMS: - cms/djangoapps/contentstore/management/commands/edit_course_tabs.py - lms/djangoapps/ccx/migrations/0006_set_display_name_as_override.py - openedx/core/djangoapps/ccxcon/api.py - openedx/core/djangoapps/verified_track_content/models.py - openedx/features/course_experience/plugins.py Note: The LTI XBlock has a dependency on this import path (!?); a fix can be found here [1]. - [1] https://github.com/edx/xblock-lti-consumer/pull/154
This commit is contained in:
@@ -13,8 +13,8 @@ from oauthlib.oauth2 import BackendApplicationClient
|
||||
from requests_oauthlib import OAuth2Session
|
||||
from rest_framework.status import HTTP_200_OK, HTTP_201_CREATED
|
||||
|
||||
from lms.djangoapps.courseware.courses import get_course_by_id
|
||||
from openedx.core.djangoapps.models.course_details import CourseDetails
|
||||
from openedx.core.lib.courses import get_course_by_id
|
||||
from common.djangoapps.student.models import anonymous_id_for_user
|
||||
from common.djangoapps.student.roles import CourseInstructorRole
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ from eventtracking import tracker
|
||||
|
||||
from lms.djangoapps.courseware import courses
|
||||
from openedx.core.lib.cache_utils import request_cached
|
||||
from openedx.core.lib.courses import get_course_by_id
|
||||
from common.djangoapps.student.models import get_user_by_username_or_email
|
||||
|
||||
from .models import (
|
||||
@@ -387,7 +388,7 @@ def add_cohort(course_key, name, assignment_type):
|
||||
raise ValueError(_("You cannot create two cohorts with the same name"))
|
||||
|
||||
try:
|
||||
course = courses.get_course_by_id(course_key)
|
||||
course = get_course_by_id(course_key)
|
||||
except Http404:
|
||||
raise ValueError("Invalid course_key") # lint-amnesty, pylint: disable=raise-missing-from
|
||||
|
||||
@@ -593,7 +594,7 @@ def _get_course_cohort_settings(course_key):
|
||||
try:
|
||||
course_cohort_settings = CourseCohortsSettings.objects.get(course_id=course_key)
|
||||
except CourseCohortsSettings.DoesNotExist:
|
||||
course = courses.get_course_by_id(course_key)
|
||||
course = get_course_by_id(course_key)
|
||||
course_cohort_settings = migrate_cohort_settings(course)
|
||||
return course_cohort_settings
|
||||
|
||||
@@ -608,7 +609,7 @@ def get_legacy_discussion_settings(course_key): # lint-amnesty, pylint: disable
|
||||
'always_cohort_inline_discussions': course_cohort_settings.always_cohort_inline_discussions
|
||||
}
|
||||
except CourseCohortsSettings.DoesNotExist:
|
||||
course = courses.get_course_by_id(course_key)
|
||||
course = get_course_by_id(course_key)
|
||||
return _get_cohort_settings_from_modulestore(course)
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ from lms.djangoapps.courseware.access_response import (
|
||||
CoursewareMicrofrontendDisabledAccessError,
|
||||
)
|
||||
from lms.djangoapps.courseware.context_processor import user_timezone_locale_prefs
|
||||
from lms.djangoapps.courseware.courses import check_course_access, get_course_by_id
|
||||
from lms.djangoapps.courseware.courses import check_course_access
|
||||
from lms.djangoapps.courseware.masquerade import setup_masquerade
|
||||
from lms.djangoapps.courseware.module_render import get_module_by_usage_id
|
||||
from lms.djangoapps.courseware.tabs import get_course_tab_list
|
||||
@@ -39,6 +39,7 @@ from lms.djangoapps.grades.api import CourseGradeFactory
|
||||
from lms.djangoapps.verify_student.services import IDVerificationService
|
||||
from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser
|
||||
from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin
|
||||
from openedx.core.lib.courses import get_course_by_id
|
||||
from openedx.core.djangoapps.programs.utils import ProgramProgressMeter
|
||||
from openedx.features.course_experience import DISPLAY_COURSE_SOCK_FLAG
|
||||
from openedx.features.content_type_gating.models import ContentTypeGatingConfig
|
||||
|
||||
@@ -14,7 +14,6 @@ from django.utils.translation import ugettext_lazy
|
||||
from edx_django_utils.cache import RequestCache
|
||||
from opaque_keys.edx.django.models import CourseKeyField
|
||||
|
||||
from lms.djangoapps.courseware.courses import get_course_by_id
|
||||
from openedx.core.djangoapps.course_groups.cohorts import (
|
||||
CourseCohort,
|
||||
get_course_cohorts,
|
||||
@@ -23,6 +22,7 @@ from openedx.core.djangoapps.course_groups.cohorts import (
|
||||
)
|
||||
from openedx.core.djangoapps.verified_track_content.tasks import sync_cohort_with_mode
|
||||
from openedx.core.lib.cache_utils import request_cached
|
||||
from openedx.core.lib.courses import get_course_by_id
|
||||
from common.djangoapps.student.models import CourseEnrollment
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -4,6 +4,7 @@ Common utility functions related to courses.
|
||||
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.http import Http404
|
||||
|
||||
from opaque_keys import InvalidKeyError
|
||||
from opaque_keys.edx.locator import CourseKey
|
||||
@@ -82,3 +83,19 @@ def clean_course_id(model_form, is_required=True):
|
||||
raise forms.ValidationError(msg)
|
||||
|
||||
return course_key
|
||||
|
||||
|
||||
def get_course_by_id(course_key, depth=0):
|
||||
"""
|
||||
Given a course id, return the corresponding course descriptor.
|
||||
|
||||
If such a course does not exist, raises a 404.
|
||||
|
||||
depth: The number of levels of children for the modulestore to cache. None means infinite depth
|
||||
"""
|
||||
with modulestore().bulk_operations(course_key):
|
||||
course = modulestore().get_course(course_key, depth=depth)
|
||||
if course:
|
||||
return course
|
||||
else:
|
||||
raise Http404("Course not found: {}.".format(str(course_key)))
|
||||
|
||||
@@ -8,8 +8,8 @@ This includes any locally defined CourseTools.
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from lms.djangoapps.courseware.courses import get_course_by_id
|
||||
from common.djangoapps.student.models import CourseEnrollment
|
||||
from openedx.core.lib.courses import get_course_by_id
|
||||
|
||||
from . import DISABLE_UNIFIED_COURSE_TAB_FLAG
|
||||
from .course_tools import CourseTool
|
||||
|
||||
Reference in New Issue
Block a user