Make course ids and usage ids opaque to LMS and Studio [partial commit]
This commit updates common/djangoapps. These keys are now objects with a limited interface, and the particular internal representation is managed by the data storage layer (the modulestore). For the LMS, there should be no outward-facing changes to the system. The keys are, for now, a change to internal representation only. For Studio, the new serialized form of the keys is used in urls, to allow for further migration in the future. Co-Author: Andy Armstrong <andya@edx.org> Co-Author: Christina Roberts <christina@edx.org> Co-Author: David Baumgold <db@edx.org> Co-Author: Diana Huang <dkh@edx.org> Co-Author: Don Mitchell <dmitchell@edx.org> Co-Author: Julia Hansbrough <julia@edx.org> Co-Author: Nimisha Asthagiri <nasthagiri@edx.org> Co-Author: Sarina Canelake <sarina@edx.org> [LMS-2370]
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
"""Generates common contexts"""
|
||||
import logging
|
||||
|
||||
from xmodule.course_module import CourseDescriptor
|
||||
from xmodule.modulestore.locations import SlashSeparatedCourseKey
|
||||
from opaque_keys import InvalidKeyError
|
||||
from util.request import COURSE_REGEX
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -9,15 +10,24 @@ log = logging.getLogger(__name__)
|
||||
|
||||
def course_context_from_url(url):
|
||||
"""
|
||||
Extracts the course_id from the given `url` and passes it on to
|
||||
Extracts the course_context from the given `url` and passes it on to
|
||||
`course_context_from_course_id()`.
|
||||
"""
|
||||
url = url or ''
|
||||
|
||||
match = COURSE_REGEX.match(url)
|
||||
course_id = ''
|
||||
course_id = None
|
||||
if match:
|
||||
course_id = match.group('course_id') or ''
|
||||
course_id_string = match.group('course_id')
|
||||
try:
|
||||
course_id = SlashSeparatedCourseKey.from_deprecated_string(course_id_string)
|
||||
except InvalidKeyError:
|
||||
log.warning(
|
||||
'unable to parse course_id "{course_id}"'.format(
|
||||
course_id=course_id_string
|
||||
),
|
||||
exc_info=True
|
||||
)
|
||||
|
||||
return course_context_from_course_id(course_id)
|
||||
|
||||
@@ -34,23 +44,12 @@ def course_context_from_course_id(course_id):
|
||||
}
|
||||
|
||||
"""
|
||||
if course_id is None:
|
||||
return {'course_id': '', 'org_id': ''}
|
||||
|
||||
course_id = course_id or ''
|
||||
context = {
|
||||
'course_id': course_id,
|
||||
'org_id': ''
|
||||
# TODO: Make this accept any CourseKey, and serialize it using .to_string
|
||||
assert(isinstance(course_id, SlashSeparatedCourseKey))
|
||||
return {
|
||||
'course_id': course_id.to_deprecated_string(),
|
||||
'org_id': course_id.org,
|
||||
}
|
||||
|
||||
if course_id:
|
||||
try:
|
||||
location = CourseDescriptor.id_to_location(course_id)
|
||||
context['org_id'] = location.org
|
||||
except ValueError:
|
||||
log.warning(
|
||||
'Unable to parse course_id "{course_id}"'.format(
|
||||
course_id=course_id
|
||||
),
|
||||
exc_info=True
|
||||
)
|
||||
|
||||
return context
|
||||
|
||||
Reference in New Issue
Block a user