Merge pull request #15814 from edx/christina/usage-key

Replace deprecated_string methods.
This commit is contained in:
Christina Roberts
2017-08-15 15:12:02 -04:00
committed by GitHub
16 changed files with 48 additions and 33 deletions

View File

@@ -8,6 +8,8 @@ import logging
from lazy import lazy
from lxml import etree
from pkg_resources import resource_string
from opaque_keys.edx.locator import BlockUsageLocator
from xblock.fields import ReferenceList, Scope, String
from xblock.fragment import Fragment
@@ -265,7 +267,11 @@ class ConditionalDescriptor(ConditionalFields, SequenceDescriptor, StudioEditabl
if not self.sources_list:
if 'sources' in self.xml_attributes and isinstance(self.xml_attributes['sources'], basestring):
self.sources_list = [
self.location.course_key.make_usage_key_from_deprecated_string(item)
# TODO: it is not clear why we are replacing the run here (which actually is a no-op
# for old-style course locators. However, this is the implementation of
# CourseLocator.make_usage_key_from_deprecated_string, which was previously
# being called in this location.
BlockUsageLocator.from_string(item).replace(run=self.location.course_key.run)
for item in ConditionalDescriptor.parse_sources(self.xml_attributes)
]

View File

@@ -837,7 +837,7 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
# first get non-draft in a round-trip
query = {
'_id': {'$in': [
course_key.make_usage_key_from_deprecated_string(item).to_deprecated_son() for item in items
UsageKey.from_string(item).map_into_course(course_key).to_deprecated_son() for item in items
]}
}
return list(self.collection.find(query))
@@ -1741,7 +1741,7 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
)
all_reachable = all_reachable.union(item.get('definition', {}).get('children', []))
item_locs -= all_reachable
return [course_key.make_usage_key_from_deprecated_string(item_loc) for item_loc in item_locs]
return [UsageKey.from_string(item_loc).map_into_course(course_key) for item_loc in item_locs]
def get_courses_for_wiki(self, wiki_slug, **kwargs):
"""

View File

@@ -9,6 +9,7 @@ and otherwise returns i4x://org/course/cat/name).
import pymongo
import logging
from opaque_keys.edx.keys import UsageKey
from opaque_keys.edx.locations import Location
from openedx.core.lib.cache_utils import memoize_in_request_cache
from xmodule.exceptions import InvalidVersionError
@@ -424,7 +425,7 @@ class DraftModuleStore(MongoModuleStore):
# collect the children's ids for future processing
next_tier = []
for child in item.get('definition', {}).get('children', []):
child_loc = Location.from_deprecated_string(child)
child_loc = Location.from_string(child)
next_tier.append(child_loc.to_deprecated_son())
# insert a new DRAFT version of the item
@@ -582,7 +583,7 @@ class DraftModuleStore(MongoModuleStore):
to_be_deleted.append(self._id_dict_to_son(current_entry['_id']))
next_tier = []
for child_loc in current_entry.get('definition', {}).get('children', []):
child_loc = course_key.make_usage_key_from_deprecated_string(child_loc)
child_loc = UsageKey.from_string(child_loc).map_into_course(course_key)
# single parent can have 2 versions: draft and published
# get draft parents only while deleting draft module
@@ -813,7 +814,7 @@ class DraftModuleStore(MongoModuleStore):
item = versions_found[0]
assert item.get('_id').get('revision') != MongoRevisionKey.draft
for child in item.get('definition', {}).get('children', []):
child_loc = Location.from_deprecated_string(child)
child_loc = Location.from_string(child)
delete_draft_only(child_loc)
delete_draft_only(location)
@@ -829,7 +830,7 @@ class DraftModuleStore(MongoModuleStore):
user_id (int) : User id
"""
for child_location in published_version.get('definition', {}).get('children', []):
item_location = original_parent_location.course_key.make_usage_key_from_deprecated_string(child_location)
item_location = UsageKey.from_string(child_location).map_into_course(original_parent_location.course_key)
try:
source_item = self.get_item(item_location)
except ItemNotFoundError:
@@ -838,7 +839,7 @@ class DraftModuleStore(MongoModuleStore):
if source_item.parent and source_item.parent.block_id != original_parent_location.block_id:
if self.update_item_parent(item_location, original_parent_location, source_item.parent, user_id):
delete_draft_only(Location.from_deprecated_string(child_location))
delete_draft_only(Location.from_string(child_location))
def _query_children_for_cache_children(self, course_key, items):
# first get non-draft in a round-trip
@@ -852,7 +853,7 @@ class DraftModuleStore(MongoModuleStore):
# now query all draft content in another round-trip
query = []
for item in items:
item_usage_key = course_key.make_usage_key_from_deprecated_string(item)
item_usage_key = UsageKey.from_string(item).map_into_course(course_key)
if item_usage_key.category not in DIRECT_ONLY_CATEGORIES:
query.append(as_draft(item_usage_key).to_deprecated_son())
if query:

View File

@@ -73,7 +73,7 @@ class UsageKeyField(mongoengine.StringField):
return None
if isinstance(location, basestring):
location = super(UsageKeyField, self).to_python(location)
return Location.from_deprecated_string(location)
return Location.from_string(location)
else:
return location

View File

@@ -829,7 +829,7 @@ def _import_course_draft(
# filtered out from the non-draft store export.
if parent_url is not None and index is not None:
course_key = descriptor.location.course_key
parent_location = course_key.make_usage_key_from_deprecated_string(parent_url)
parent_location = UsageKey.from_string(parent_url).map_into_course(course_key)
# IMPORTANT: Be sure to update the parent in the NEW namespace
parent_location = parent_location.map_into_course(target_id)

View File

@@ -10,6 +10,7 @@ from xblock.fields import ScopeIds
from xmodule.error_module import NonStaffErrorDescriptor
from opaque_keys.edx.keys import CourseKey
from opaque_keys.edx.locations import Location
from opaque_keys.edx.locator import BlockUsageLocator
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
@@ -318,9 +319,11 @@ class ConditionalModuleXmlTest(unittest.TestCase):
dummy_field_data,
dummy_scope_ids,
)
new_run = conditional.location.course_key.run
self.assertEqual(
conditional.sources_list[0],
conditional.location.course_key.make_usage_key_from_deprecated_string(conditional.xml_attributes['sources'])
# Matching what is in ConditionalDescriptor.__init__.
BlockUsageLocator.from_string(conditional.xml_attributes['sources']).replace(run=new_run)
)
def test_conditional_module_parse_sources(self):

View File

@@ -1632,7 +1632,8 @@ class XMLParsingSystem(DescriptorSystem):
"""
if isinstance(value, UsageKey):
return value
return course_key.make_usage_key_from_deprecated_string(value)
usage_key = UsageKey.from_string(value)
return usage_key.map_into_course(course_key)
def _convert_reference_fields_to_keys(self, xblock):
"""