Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions common/lib/xmodule/xmodule/modulestore/loc_mapper_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def translate_location(self, old_style_course_id, location, published=True, add_
entry = item
break

block_id = entry['block_map'].get(self._encode_for_mongo(location.name))
block_id = entry['block_map'].get(self.encode_key_for_mongo(location.name))
if block_id is None:
if add_entry_if_missing:
block_id = self._add_to_block_map(location, location_id, entry['block_map'])
Expand Down Expand Up @@ -231,7 +231,7 @@ def translate_locator_to_location(self, locator, get_course=False):
candidate['_id']['org'],
candidate['_id']['course'],
category,
self._decode_from_mongo(old_name),
self.decode_key_from_mongo(old_name),
None)
published_locator = BlockUsageLocator(
candidate['course_id'], branch=candidate['prod_branch'], block_id=block_id
Expand Down Expand Up @@ -261,7 +261,7 @@ def _add_to_block_map(self, location, location_id, block_map):
# if 2 different category locations had same name, then they'll collide. Make the later
# mapped ones unique
block_id = self._verify_uniqueness(location.name, block_map)
encoded_location_name = self._encode_for_mongo(location.name)
encoded_location_name = self.encode_key_for_mongo(location.name)
block_map.setdefault(encoded_location_name, {})[location.category] = block_id
self.location_map.update(location_id, {'$set': {'block_map': block_map}})
return block_id
Expand Down Expand Up @@ -331,7 +331,8 @@ def _verify_uniqueness(self, name, block_map):
return self._verify_uniqueness(name, block_map)
return name

def _encode_for_mongo(self, fieldname):
@staticmethod
def encode_key_for_mongo(fieldname):
"""
Fieldnames in mongo cannot have periods nor dollar signs. So encode them.
:param fieldname: an atomic field name. Note, don't pass structured paths as it will flatten them
Expand All @@ -340,9 +341,10 @@ def _encode_for_mongo(self, fieldname):
fieldname = fieldname.replace(char, '%{:02x}'.format(ord(char)))
return fieldname

def _decode_from_mongo(self, fieldname):
@staticmethod
def decode_key_from_mongo(fieldname):
"""
The inverse of _encode_for_mongo
The inverse of encode_key_for_mongo
:param fieldname: with period and dollar escaped
"""
return urllib.unquote(fieldname)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ..exceptions import ItemNotFoundError
from .split_mongo_kvs import SplitMongoKVS
from xblock.fields import ScopeIds
from xmodule.modulestore.loc_mapper_store import LocMapperStore

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -63,7 +64,9 @@ def __init__(self, modulestore, course_entry, default_class, module_data, lazy,
# Compute inheritance
modulestore.inherit_settings(
course_entry['structure'].get('blocks', {}),
course_entry['structure'].get('blocks', {}).get(course_entry['structure'].get('root'))
course_entry['structure'].get('blocks', {}).get(
LocMapperStore.encode_key_for_mongo(course_entry['structure'].get('root'))
)
)
self.default_class = default_class
self.local_modules = {}
Expand Down
Loading