Remove usages of deprecated SlashSeparatedCourseKey.
This commit is contained in:
@@ -14,7 +14,6 @@ from contracts import contract, new_contract
|
||||
from opaque_keys import InvalidKeyError
|
||||
from opaque_keys.edx.keys import CourseKey, AssetKey
|
||||
from opaque_keys.edx.locator import LibraryLocator
|
||||
from opaque_keys.edx.locations import SlashSeparatedCourseKey
|
||||
from xmodule.assetstore import AssetMetadata
|
||||
|
||||
from . import ModuleStoreWriteBase, ModuleStoreEnum, XMODULE_FIELDS_WITH_USAGE_KEYS
|
||||
@@ -161,11 +160,8 @@ class MixedModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase):
|
||||
try:
|
||||
self.mappings[CourseKey.from_string(course_id)] = store_name
|
||||
except InvalidKeyError:
|
||||
try:
|
||||
self.mappings[SlashSeparatedCourseKey.from_deprecated_string(course_id)] = store_name
|
||||
except InvalidKeyError:
|
||||
log.exception("Invalid MixedModuleStore configuration. Unable to parse course_id %r", course_id)
|
||||
continue
|
||||
log.exception("Invalid MixedModuleStore configuration. Unable to parse course_id %r", course_id)
|
||||
continue
|
||||
|
||||
for store_settings in stores:
|
||||
key = store_settings['NAME']
|
||||
|
||||
@@ -26,7 +26,7 @@ from contracts import contract, new_contract
|
||||
from fs.osfs import OSFS
|
||||
from mongodb_proxy import autoretry_read
|
||||
from opaque_keys.edx.keys import UsageKey, CourseKey, AssetKey
|
||||
from opaque_keys.edx.locations import Location, BlockUsageLocator, SlashSeparatedCourseKey
|
||||
from opaque_keys.edx.locations import Location, BlockUsageLocator
|
||||
from opaque_keys.edx.locator import CourseLocator, LibraryLocator
|
||||
from path import Path as path
|
||||
from pytz import UTC
|
||||
@@ -1021,7 +1021,9 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
|
||||
courses_summaries = []
|
||||
for course in course_records:
|
||||
if not (course['_id']['org'] == 'edx' and course['_id']['course'] == 'templates'):
|
||||
locator = SlashSeparatedCourseKey(course['_id']['org'], course['_id']['course'], course['_id']['name'])
|
||||
locator = CourseKey.from_string('/'.join(
|
||||
[course['_id']['org'], course['_id']['course'], course['_id']['name']]
|
||||
))
|
||||
course_summary = extract_course_summary(course)
|
||||
courses_summaries.append(
|
||||
CourseSummary(locator, **course_summary)
|
||||
@@ -1045,7 +1047,9 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
|
||||
base_list = sum(
|
||||
[
|
||||
self._load_items(
|
||||
SlashSeparatedCourseKey(course['_id']['org'], course['_id']['course'], course['_id']['name']),
|
||||
CourseKey.from_string('/'.join(
|
||||
[course['_id']['org'], course['_id']['course'], course['_id']['name']]
|
||||
)),
|
||||
[course]
|
||||
)
|
||||
for course
|
||||
@@ -1136,7 +1140,9 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
|
||||
course_query = {'_id': location.to_deprecated_son()}
|
||||
course = self.collection.find_one(course_query, projection={'_id': True})
|
||||
if course:
|
||||
return SlashSeparatedCourseKey(course['_id']['org'], course['_id']['course'], course['_id']['name'])
|
||||
return CourseKey.from_string('/'.join([
|
||||
course['_id']['org'], course['_id']['course'], course['_id']['name']]
|
||||
))
|
||||
else:
|
||||
return None
|
||||
|
||||
@@ -1289,7 +1295,7 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
|
||||
Raises:
|
||||
InvalidLocationError: If a course with the same org, course, and run already exists
|
||||
"""
|
||||
course_id = SlashSeparatedCourseKey(org, course, run)
|
||||
course_id = CourseKey.from_string('/'.join([org, course, run]))
|
||||
|
||||
# Check if a course with this org/course has been defined before (case-insensitive)
|
||||
course_search_location = SON([
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Custom field types for mongoengine
|
||||
"""
|
||||
import mongoengine
|
||||
from opaque_keys.edx.locations import SlashSeparatedCourseKey, Location
|
||||
from opaque_keys.edx.locations import Location
|
||||
from types import NoneType
|
||||
from opaque_keys.edx.keys import CourseKey, UsageKey
|
||||
|
||||
@@ -36,7 +36,7 @@ class CourseKeyField(mongoengine.StringField):
|
||||
if course_key == '':
|
||||
return None
|
||||
if isinstance(course_key, basestring):
|
||||
return SlashSeparatedCourseKey.from_deprecated_string(course_key)
|
||||
return CourseKey.from_string(course_key)
|
||||
else:
|
||||
return course_key
|
||||
|
||||
|
||||
@@ -26,7 +26,8 @@ from xmodule.x_module import (
|
||||
from xmodule.modulestore.xml_exporter import DEFAULT_CONTENT_FIELDS
|
||||
from xmodule.modulestore import ModuleStoreEnum, ModuleStoreReadBase, LIBRARY_ROOT, COURSE_ROOT
|
||||
from xmodule.tabs import CourseTabList
|
||||
from opaque_keys.edx.locations import SlashSeparatedCourseKey, Location
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
from opaque_keys.edx.locations import Location
|
||||
from opaque_keys.edx.locator import CourseLocator, LibraryLocator, BlockUsageLocator
|
||||
|
||||
from xblock.field_data import DictFieldData
|
||||
@@ -357,7 +358,7 @@ class XMLModuleStore(ModuleStoreReadBase):
|
||||
self.errored_courses = {} # course_dir -> errorlog, for dirs that failed to load
|
||||
|
||||
if course_ids is not None:
|
||||
course_ids = [SlashSeparatedCourseKey.from_deprecated_string(course_id) for course_id in course_ids]
|
||||
course_ids = [CourseKey.from_string(course_id) for course_id in course_ids]
|
||||
|
||||
self.load_error_modules = load_error_modules
|
||||
|
||||
@@ -629,9 +630,9 @@ class XMLModuleStore(ModuleStoreReadBase):
|
||||
if not url_name:
|
||||
raise ValueError("Can't load a course without a 'url_name' "
|
||||
"(or 'name') set. Set url_name.")
|
||||
# Have to use SlashSeparatedCourseKey here because it makes sure the same format is
|
||||
# Have to use older key format here because it makes sure the same format is
|
||||
# always used, preventing duplicate keys.
|
||||
return SlashSeparatedCourseKey(org, course, url_name)
|
||||
return CourseKey.from_string('/'.join([org, course, url_name]))
|
||||
|
||||
def load_extra_content(self, system, course_descriptor, category, base_dir, course_dir, url_name):
|
||||
self._load_extra_content(system, course_descriptor, category, base_dir, course_dir)
|
||||
|
||||
@@ -17,21 +17,18 @@ import unittest
|
||||
|
||||
from contextlib import contextmanager, nested
|
||||
from functools import wraps
|
||||
from lazy import lazy
|
||||
from mock import Mock, patch
|
||||
from operator import attrgetter
|
||||
from mock import Mock
|
||||
from path import Path as path
|
||||
|
||||
from opaque_keys.edx.locations import SlashSeparatedCourseKey
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
from xblock.field_data import DictFieldData
|
||||
from xblock.fields import ScopeIds, Scope, Reference, ReferenceList, ReferenceValueDict
|
||||
from xblock.fields import ScopeIds, Reference, ReferenceList, ReferenceValueDict
|
||||
from xmodule.assetstore import AssetMetadata
|
||||
from xmodule.error_module import ErrorDescriptor
|
||||
from xmodule.mako_module import MakoDescriptorSystem
|
||||
from xmodule.modulestore import ModuleStoreEnum
|
||||
from xmodule.modulestore.draft_and_published import DIRECT_ONLY_CATEGORIES, ModuleStoreDraftAndPublished
|
||||
from xmodule.modulestore.inheritance import InheritanceMixin, own_metadata
|
||||
from xmodule.modulestore.mongo.draft import DraftModuleStore
|
||||
from xmodule.modulestore.draft_and_published import ModuleStoreDraftAndPublished
|
||||
from xmodule.modulestore.inheritance import InheritanceMixin
|
||||
from xmodule.modulestore.xml import CourseLocationManager
|
||||
from xmodule.x_module import ModuleSystem, XModuleDescriptor, XModuleMixin
|
||||
|
||||
@@ -86,7 +83,7 @@ class TestModuleSystem(ModuleSystem): # pylint: disable=abstract-method
|
||||
return rt_repr
|
||||
|
||||
|
||||
def get_test_system(course_id=SlashSeparatedCourseKey('org', 'course', 'run')):
|
||||
def get_test_system(course_id=CourseKey.from_string('/'.join(['org', 'course', 'run']))):
|
||||
"""
|
||||
Construct a test ModuleSystem instance.
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ from mock import Mock, patch
|
||||
from xblock.field_data import DictFieldData
|
||||
from xblock.fields import ScopeIds
|
||||
from xmodule.error_module import NonStaffErrorDescriptor
|
||||
from opaque_keys.edx.locations import SlashSeparatedCourseKey, Location
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
from opaque_keys.edx.locations import Location
|
||||
from xmodule.modulestore.xml import ImportSystem, XMLModuleStore, CourseLocationManager
|
||||
from xmodule.conditional_module import ConditionalDescriptor
|
||||
from xmodule.tests import DATA_DIR, get_test_system, get_test_descriptor_system
|
||||
@@ -29,7 +30,7 @@ class DummySystem(ImportSystem):
|
||||
|
||||
super(DummySystem, self).__init__(
|
||||
xmlstore=xmlstore,
|
||||
course_id=SlashSeparatedCourseKey(ORG, COURSE, 'test_run'),
|
||||
course_id=CourseKey.from_string('/'.join([ORG, COURSE, 'test_run'])),
|
||||
course_dir='test_dir',
|
||||
error_tracker=Mock(),
|
||||
load_error_modules=load_error_modules,
|
||||
|
||||
@@ -8,7 +8,8 @@ from path import Path as path
|
||||
|
||||
from xmodule.contentstore.content import StaticContent, StaticContentStream
|
||||
from xmodule.contentstore.content import ContentStore
|
||||
from opaque_keys.edx.locations import SlashSeparatedCourseKey, AssetLocation
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
from opaque_keys.edx.locations import AssetLocation
|
||||
from xmodule.static_content import _write_js, _list_descriptors
|
||||
|
||||
SAMPLE_STRING = """
|
||||
@@ -158,7 +159,7 @@ class ContentTest(unittest.TestCase):
|
||||
# We had a bug that __ got converted into a single _. Make sure that substitution of INVALID_CHARS (like space)
|
||||
# still happen.
|
||||
asset_location = StaticContent.compute_location(
|
||||
SlashSeparatedCourseKey('mitX', '400', 'ignore'), 'subs__1eo_jXvZnE .srt.sjson'
|
||||
CourseKey.from_string('mitX/400/ignore'), 'subs__1eo_jXvZnE .srt.sjson'
|
||||
)
|
||||
self.assertEqual(
|
||||
AssetLocation(u'mitX', u'400', u'ignore', u'asset', u'subs__1eo_jXvZnE_.srt.sjson', None),
|
||||
|
||||
@@ -12,7 +12,7 @@ from xblock.runtime import KvsFieldData, DictKeyValueStore
|
||||
|
||||
import xmodule.course_module
|
||||
from xmodule.modulestore.xml import ImportSystem, XMLModuleStore
|
||||
from opaque_keys.edx.locations import SlashSeparatedCourseKey
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
|
||||
|
||||
ORG = 'test_org'
|
||||
@@ -39,7 +39,7 @@ class DummySystem(ImportSystem):
|
||||
|
||||
xmlstore = XMLModuleStore("data_dir", source_dirs=[],
|
||||
load_error_modules=load_error_modules)
|
||||
course_id = SlashSeparatedCourseKey(ORG, COURSE, 'test_run')
|
||||
course_id = CourseKey.from_string('/'.join([ORG, COURSE, 'test_run']))
|
||||
course_dir = "test_dir"
|
||||
error_tracker = Mock()
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ from xmodule.fields import Date
|
||||
from xmodule.tests import DATA_DIR
|
||||
from xmodule.modulestore.inheritance import InheritanceMixin
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
from opaque_keys.edx.locations import SlashSeparatedCourseKey
|
||||
|
||||
from xblock.core import XBlock
|
||||
from xblock.fields import Scope, String, Integer
|
||||
@@ -40,7 +39,7 @@ class DummySystem(ImportSystem):
|
||||
xmlstore = LibraryXMLModuleStore("data_dir", source_dirs=[], load_error_modules=load_error_modules)
|
||||
else:
|
||||
xmlstore = XMLModuleStore("data_dir", source_dirs=[], load_error_modules=load_error_modules)
|
||||
course_id = SlashSeparatedCourseKey(ORG, COURSE, 'test_run')
|
||||
course_id = CourseKey.from_string('/'.join([ORG, COURSE, 'test_run']))
|
||||
course_dir = "test_dir"
|
||||
error_tracker = Mock()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user