Commit ad8ece51 by Don Mitchell

Split get_block uses the passed in id rather than constructed

on returned block so that branch/version awareness is inherited.
LMS-11263
parent e4aaf497
...@@ -95,10 +95,12 @@ def path_to_location(modulestore, usage_key): ...@@ -95,10 +95,12 @@ def path_to_location(modulestore, usage_key):
category = path[path_index].block_type category = path[path_index].block_type
if category == 'sequential' or category == 'videosequence': if category == 'sequential' or category == 'videosequence':
section_desc = modulestore.get_item(path[path_index]) section_desc = modulestore.get_item(path[path_index])
child_locs = [c.location.block_id for c in section_desc.get_children()] # this calls get_children rather than just children b/c old mongo includes private children
# in children but not in get_children
child_locs = [c.location for c in section_desc.get_children()]
# positions are 1-indexed, and should be strings to be consistent with # positions are 1-indexed, and should be strings to be consistent with
# url parsing. # url parsing.
position_list.append(str(child_locs.index(path[path_index + 1].block_id) + 1)) position_list.append(str(child_locs.index(path[path_index + 1]) + 1))
position = "_".join(position_list) position = "_".join(position_list)
return (course_id, chapter, section, position) return (course_id, chapter, section, position)
...@@ -53,15 +53,18 @@ class CachingDescriptorSystem(MakoDescriptorSystem): ...@@ -53,15 +53,18 @@ class CachingDescriptorSystem(MakoDescriptorSystem):
self.default_class = default_class self.default_class = default_class
self.local_modules = {} self.local_modules = {}
def _load_item(self, block_id, course_entry_override=None, **kwargs): def _load_item(self, usage_key, course_entry_override=None, **kwargs):
if isinstance(block_id, BlockUsageLocator): # usage_key is either a UsageKey or just the block_id. if a usage_key,
if isinstance(block_id.block_id, LocalId): if isinstance(usage_key, BlockUsageLocator):
if isinstance(usage_key.block_id, LocalId):
try: try:
return self.local_modules[block_id] return self.local_modules[usage_key]
except KeyError: except KeyError:
raise ItemNotFoundError raise ItemNotFoundError
else: else:
block_id = block_id.block_id block_id = usage_key.block_id
else:
block_id = usage_key
json_data = self.module_data.get(block_id) json_data = self.module_data.get(block_id)
if json_data is None: if json_data is None:
...@@ -77,7 +80,12 @@ class CachingDescriptorSystem(MakoDescriptorSystem): ...@@ -77,7 +80,12 @@ class CachingDescriptorSystem(MakoDescriptorSystem):
raise ItemNotFoundError(block_id) raise ItemNotFoundError(block_id)
class_ = self.load_block_type(json_data.get('category')) class_ = self.load_block_type(json_data.get('category'))
return self.xblock_from_json(class_, block_id, json_data, course_entry_override, **kwargs) new_item = self.xblock_from_json(class_, block_id, json_data, course_entry_override, **kwargs)
if isinstance(usage_key, BlockUsageLocator):
# trust the passed in key to know the caller's expectations of which fields are filled in.
# particularly useful for strip_keys so may go away when we're version aware
new_item.location = usage_key
return new_item
# xblock's runtime does not always pass enough contextual information to figure out # xblock's runtime does not always pass enough contextual information to figure out
# which named container (course x branch) or which parent is requesting an item. Because split allows # which named container (course x branch) or which parent is requesting an item. Because split allows
...@@ -107,14 +115,15 @@ class CachingDescriptorSystem(MakoDescriptorSystem): ...@@ -107,14 +115,15 @@ class CachingDescriptorSystem(MakoDescriptorSystem):
if block_id is None: if block_id is None:
block_id = LocalId() block_id = LocalId()
block_course_key = CourseLocator(
version_guid=course_entry_override['structure']['_id'],
org=course_entry_override.get('org'),
course=course_entry_override.get('course'),
run=course_entry_override.get('run'),
branch=course_entry_override.get('branch'),
)
block_locator = BlockUsageLocator( block_locator = BlockUsageLocator(
CourseLocator( block_course_key,
version_guid=course_entry_override['structure']['_id'],
org=course_entry_override.get('org'),
course=course_entry_override.get('course'),
run=course_entry_override.get('run'),
branch=course_entry_override.get('branch'),
),
block_type=json_data.get('category'), block_type=json_data.get('category'),
block_id=block_id, block_id=block_id,
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment