Skip to content
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
20 changes: 10 additions & 10 deletions cms/djangoapps/contentstore/api/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,44 +43,44 @@ def initialize_course(cls, course):
cls.store.update_item(course, cls.staff.id)

cls.section = BlockFactory.create(
parent_location=course.location,
parent_location=course.usage_key,
category="chapter",
)
cls.subsection1 = BlockFactory.create(
parent_location=cls.section.location,
parent_location=cls.section.usage_key,
category="sequential",
)
unit1 = BlockFactory.create(
parent_location=cls.subsection1.location,
parent_location=cls.subsection1.usage_key,
category="vertical",
)
BlockFactory.create(
parent_location=unit1.location,
parent_location=unit1.usage_key,
category="video",
)
BlockFactory.create(
parent_location=unit1.location,
parent_location=unit1.usage_key,
category="problem",
)

cls.subsection2 = BlockFactory.create(
parent_location=cls.section.location,
parent_location=cls.section.usage_key,
category="sequential",
)
unit2 = BlockFactory.create(
parent_location=cls.subsection2.location,
parent_location=cls.subsection2.usage_key,
category="vertical",
)
unit3 = BlockFactory.create(
parent_location=cls.subsection2.location,
parent_location=cls.subsection2.usage_key,
category="vertical",
)
BlockFactory.create(
parent_location=unit3.location,
parent_location=unit3.usage_key,
category="video",
)
BlockFactory.create(
parent_location=unit3.location,
parent_location=unit3.usage_key,
category="video",
)

Expand Down
18 changes: 9 additions & 9 deletions cms/djangoapps/contentstore/api/tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ def initialize_course(cls, course):
)

section = BlockFactory.create(
parent_location=course.location,
parent_location=course.usage_key,
category="chapter",
)
BlockFactory.create(
parent_location=section.location,
parent_location=section.usage_key,
category="sequential",
)

Expand Down Expand Up @@ -183,23 +183,23 @@ def initialize_course(cls, course):
Sets up test course structure.
"""
section = BlockFactory.create(
parent_location=course.location,
parent_location=course.usage_key,
category="chapter",
)
subsection = BlockFactory.create(
parent_location=section.location,
parent_location=section.usage_key,
category="sequential",
)
unit = BlockFactory.create(
parent_location=subsection.location,
parent_location=subsection.usage_key,
category="vertical",
)
cls.block1 = BlockFactory.create(
parent_location=unit.location,
parent_location=unit.usage_key,
category="library_content",
)
cls.block2 = BlockFactory.create(
parent_location=unit.location,
parent_location=unit.usage_key,
category="library_content",
)

Expand Down Expand Up @@ -273,8 +273,8 @@ def test_list_ready_to_update_reference_success(self, mock_block, mock_auth):

data = response.json()
self.assertListEqual(data, [
{'usage_key': str(self.block1.location)},
{'usage_key': str(self.block2.location)},
{'usage_key': str(self.block1.usage_key)},
{'usage_key': str(self.block2.usage_key)},
])
mock_auth.assert_called_once()

Expand Down
8 changes: 4 additions & 4 deletions cms/djangoapps/contentstore/api/views/course_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ def _get_subsections_and_units(cls, course, request):

for unit in visible_units:
leaf_blocks = cls._get_leaf_blocks(unit)
unit_dict[unit.location] = dict(
unit_dict[unit.usage_key] = dict(
num_leaf_blocks=len(leaf_blocks),
leaf_block_types={block.location.block_type for block in leaf_blocks},
leaf_block_types={block.usage_key.block_type for block in leaf_blocks},
)

subsection_dict[subsection.location] = unit_dict
subsection_dict[subsection.usage_key] = unit_dict
return subsection_dict

@classmethod
Expand Down Expand Up @@ -257,7 +257,7 @@ def _get_children(cls, parent): # lint-amnesty, pylint: disable=missing-functio
def _get_leaf_blocks(cls, unit): # lint-amnesty, pylint: disable=missing-function-docstring
def leaf_filter(block):
return (
block.location.block_type not in ('chapter', 'sequential', 'vertical') and
block.usage_key.block_type not in ('chapter', 'sequential', 'vertical') and
len(cls._get_children(block)) == 0
)

Expand Down
12 changes: 6 additions & 6 deletions cms/djangoapps/contentstore/api/views/course_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def _assignments_validation(self, course, request): # lint-amnesty, pylint: dis
]
assignments_with_dates_before_start = (
[
{'id': str(a.location), 'display_name': a.display_name}
{'id': str(a.usage_key), 'display_name': a.display_name}
for a in assignments_with_dates
if a.due < course.start
]
Expand All @@ -153,7 +153,7 @@ def _assignments_validation(self, course, request): # lint-amnesty, pylint: dis

assignments_with_dates_after_end = (
[
{'id': str(a.location), 'display_name': a.display_name}
{'id': str(a.usage_key), 'display_name': a.display_name}
for a in assignments_with_dates
if a.due > course.end
]
Expand All @@ -169,7 +169,7 @@ def _assignments_validation(self, course, request): # lint-amnesty, pylint: dis
]
assignments_with_dates_before_start = (
[
{'id': str(a.location), 'display_name': a.display_name}
{'id': str(a.usage_key), 'display_name': a.display_name}
for a in assignments_with_dates
if a.due < course.start
]
Expand All @@ -179,7 +179,7 @@ def _assignments_validation(self, course, request): # lint-amnesty, pylint: dis

assignments_with_dates_after_end = (
[
{'id': str(a.location), 'display_name': a.display_name}
{'id': str(a.usage_key), 'display_name': a.display_name}
for a in assignments_with_dates
if a.due > course.end
]
Expand All @@ -200,14 +200,14 @@ def _assignments_validation(self, course, request): # lint-amnesty, pylint: dis
parent_unit = modulestore().get_item(ora.parent)
parent_assignment = modulestore().get_item(parent_unit.parent)
assignments_with_ora_dates_before_start.append({
'id': str(parent_assignment.location),
'id': str(parent_assignment.usage_key),
'display_name': parent_assignment.display_name
})
if course.end and self._has_date_after_end(ora, course.end):
parent_unit = modulestore().get_item(ora.parent)
parent_assignment = modulestore().get_item(parent_unit.parent)
assignments_with_ora_dates_after_end.append({
'id': str(parent_assignment.location),
'id': str(parent_assignment.usage_key),
'display_name': parent_assignment.display_name
})

Expand Down
4 changes: 2 additions & 2 deletions cms/djangoapps/contentstore/asset_storage_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def _get_asset_usage_path(course_key, assets):
if handout and asset_key_string in handout:
usage_dict = {'display_location': '', 'url': ''}
xblock_display_name = getattr(block, 'display_name', '')
xblock_location = str(block.location)
xblock_location = str(block.usage_key)
unit = block.get_parent()
unit_location = str(block.parent)
unit_display_name = getattr(unit, 'display_name', '')
Expand All @@ -204,7 +204,7 @@ def _get_asset_usage_path(course_key, assets):
if static_path in data or asset_key_string in data:
usage_dict = {'display_location': '', 'url': ''}
xblock_display_name = getattr(block, 'display_name', '')
xblock_location = str(block.location)
xblock_location = str(block.usage_key)
unit = block.get_parent()
unit_location = str(block.parent)
unit_display_name = getattr(unit, 'display_name', '')
Expand Down
6 changes: 3 additions & 3 deletions cms/djangoapps/contentstore/core/course_optimizer_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def _update_node_tree_and_dictionary(block, link, link_state, node_tree, diction

# Traverse the path and build the tree structure
for xblock in path:
xblock_id = xblock.location
xblock_id = xblock.usage_key
updated_dictionary.setdefault(
xblock_id,
{
Expand All @@ -258,7 +258,7 @@ def _update_node_tree_and_dictionary(block, link, link_state, node_tree, diction
# Add block-level details for the last xblock in the path (URL and broken/locked links)
updated_dictionary[xblock_id].setdefault(
'url',
f'/course/{block.course_id}/editor/{block.category}/{block.location}'
f'/course/{block.course_id}/editor/{block.category}/{block.usage_key}'
)

# The link_state == True condition is maintained for backward compatibility.
Expand Down Expand Up @@ -358,7 +358,7 @@ def sort_course_sections(course_key, data):
if not course_blocks or 'LinkCheckOutput' not in data or 'sections' not in data['LinkCheckOutput']:
return data

sorted_section_ids = [section.location for section in course_blocks[0].get_children()]
sorted_section_ids = [section.usage_key for section in course_blocks[0].get_children()]
sections_map = {section['id']: section for section in data['LinkCheckOutput']['sections']}
data['LinkCheckOutput']['sections'] = [
sections_map[section_id]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ def test_update_node_tree_and_dictionary_returns_node_tree(self):
when passed a block level xblock.
"""
expected_tree = {
self.mock_section.location: {
self.mock_subsection.location: {
self.mock_unit.location: {
self.mock_block.location: {}
self.mock_section.usage_key: {
self.mock_subsection.usage_key: {
self.mock_unit.usage_key: {
self.mock_block.usage_key: {}
}
}
}
Expand All @@ -81,22 +81,22 @@ def test_update_node_tree_and_dictionary_returns_dictionary(self):
when passed a block level xblock.
"""
expected_dictionary = {
self.mock_section.location: {
self.mock_section.usage_key: {
'display_name': 'Section Name',
'category': 'chapter'
},
self.mock_subsection.location: {
self.mock_subsection.usage_key: {
'display_name': 'Subsection Name',
'category': 'sequential'
},
self.mock_unit.location: {
self.mock_unit.usage_key: {
'display_name': 'Unit Name',
'category': 'vertical'
},
self.mock_block.location: {
self.mock_block.usage_key: {
'display_name': 'Block Name',
'category': 'html',
'url': f'/course/{self.course.id}/editor/html/{self.mock_block.location}',
'url': f'/course/{self.course.id}/editor/html/{self.mock_block.usage_key}',
'locked_links': ['example_link']
}
}
Expand Down Expand Up @@ -375,12 +375,12 @@ def test_course_updates_and_custom_pages_structure(self):
# Test data that represents the broken links JSON structure
json_content = [
[
str(self.mock_block.location),
str(self.mock_block.usage_key),
"http://content-link.com",
LinkState.BROKEN,
],
[
str(self.mock_unit.location),
str(self.mock_unit.usage_key),
"http://unit-link.com",
LinkState.LOCKED,
],
Expand Down
6 changes: 3 additions & 3 deletions cms/djangoapps/contentstore/course_group_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def _get_usage_dict(course, unit, block, scheme_name=None):

unit_url = reverse_usage_url(
'container_handler',
course.location.course_key.make_usage_key(unit_for_url.location.block_type, unit_for_url.location.block_id)
course.usage_key.course_key.make_usage_key(unit_for_url.usage_key.block_type, unit_for_url.usage_key.block_id)
)

usage_dict = {'label': f"{unit.display_name} / {block.display_name}", 'url': unit_url}
Expand Down Expand Up @@ -194,7 +194,7 @@ def _get_content_experiment_usage_info(store, course, split_tests): # pylint: d
for split_test in split_tests:
unit = split_test.get_parent()
if not unit:
log.warning("Unable to find parent for split_test %s", split_test.location)
log.warning("Unable to find parent for split_test %s", split_test.usage_key)
# Make sure that this user_partition appears in the output even though it has no content
usage_info[split_test.user_partition_id] = []
continue
Expand Down Expand Up @@ -234,7 +234,7 @@ def get_partitions_usage_info(store, course):
for block, partition_id, group_id in GroupConfiguration._iterate_items_and_group_ids(course, items):
unit = block.get_parent()
if not unit:
log.warning("Unable to find parent for component %s", block.location)
log.warning("Unable to find parent for component %s", block.usage_key)
continue

usage_info[partition_id][group_id].append(GroupConfiguration._get_usage_dict(
Expand Down
10 changes: 5 additions & 5 deletions cms/djangoapps/contentstore/courseware_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def get_item_location(item):
"""
Gets the version agnostic item location
"""
return item.location.version_agnostic().replace(branch=None)
return item.usage_key.version_agnostic().replace(branch=None)

def prepare_item_index(item, skip_index=False, groups_usage_info=None):
"""
Expand Down Expand Up @@ -192,7 +192,7 @@ def prepare_item_index(item, skip_index=False, groups_usage_info=None):
for group in split_partition.groups:
group_id = str(group.id)
child_location = item.group_id_to_child.get(group_id, None)
if child_location == split_test_child.location:
if child_location == split_test_child.usage_key:
groups_usage_info.update({
str(get_item_location(split_test_child)): [group_id],
})
Expand Down Expand Up @@ -242,8 +242,8 @@ def prepare_item_index(item, skip_index=False, groups_usage_info=None):
return item_content_groups
except Exception as err: # pylint: disable=broad-except
# broad exception so that index operation does not fail on one item of many
log.warning('Could not index item: %s - %r', item.location, err)
error_list.append(_('Could not index item: {}').format(item.location))
log.warning('Could not index item: %s - %r', item.usage_key, err)
error_list.append(_('Could not index item: {}').format(item.usage_key))

try:
with modulestore.branch_setting(ModuleStoreEnum.RevisionOption.published_only):
Expand Down Expand Up @@ -617,7 +617,7 @@ def index_about_information(cls, modulestore, course):

# load data for all of the 'about' blocks for this course into a dictionary
about_dictionary = {
item.location.block_id: item.data
item.usage_key.block_id: item.data
for item in modulestore.get_items(course.id, qualifiers={"category": "about"})
}

Expand Down
4 changes: 2 additions & 2 deletions cms/djangoapps/contentstore/exams.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def register_exams(course_key):
exams_list = []
locations = []
for timed_exam in timed_exams:
location = str(timed_exam.location)
location = str(timed_exam.usage_key)
msg = (
'Found {location} as an exam in course structure.'.format(
location=location
Expand Down Expand Up @@ -84,7 +84,7 @@ def register_exams(course_key):

exams_list.append({
'course_id': str(course_key),
'content_id': str(timed_exam.location),
'content_id': str(timed_exam.usage_key),
'exam_name': timed_exam.display_name,
'time_limit_mins': timed_exam.default_time_limit_minutes,
# If the subsection has no due date, then infer a due date from the course end date. This behavior is a
Expand Down
Loading
Loading