diff --git a/lms/djangoapps/grades/course_grade.py b/lms/djangoapps/grades/course_grade.py index f5639873a809..1642e7c69759 100644 --- a/lms/djangoapps/grades/course_grade.py +++ b/lms/djangoapps/grades/course_grade.py @@ -242,7 +242,7 @@ def _get_chapter_grade_info(self, chapter, course_structure): chapter_subsection_grades = self._get_subsection_grades(course_structure, chapter.location) return { 'display_name': block_metadata_utils.display_name_with_default(chapter), - 'url_name': block_metadata_utils.url_name_for_block(chapter), + 'url_name': chapter.usage_key.block_id, 'sections': chapter_subsection_grades, } diff --git a/lms/djangoapps/grades/subsection_grade.py b/lms/djangoapps/grades/subsection_grade.py index b0c98497b823..d87c98fba2fe 100644 --- a/lms/djangoapps/grades/subsection_grade.py +++ b/lms/djangoapps/grades/subsection_grade.py @@ -25,7 +25,7 @@ class SubsectionGradeBase(metaclass=ABCMeta): def __init__(self, subsection): self.location = subsection.location self.display_name = block_metadata_utils.display_name_with_default(subsection) - self.url_name = block_metadata_utils.url_name_for_block(subsection) + self.url_name = subsection.usage_key.block_id self.due = block_metadata_utils.get_datetime_field(subsection, 'due', None) self.end = getattr(subsection, 'end', None) diff --git a/openedx/core/djangoapps/content/course_overviews/models.py b/openedx/core/djangoapps/content/course_overviews/models.py index c5b453f82e6c..728f8d4398b6 100644 --- a/openedx/core/djangoapps/content/course_overviews/models.py +++ b/openedx/core/djangoapps/content/course_overviews/models.py @@ -478,9 +478,9 @@ def clean_id(self, padding_char='='): return course_metadata_utils.clean_course_key(self.location.course_key, padding_char) @property - def location(self): + def usage_key(self): """ - Returns the UsageKey of this course. + Returns the UsageKey of the root block of this course. UsageKeyField has a strange behavior where it fails to parse the "run" of a course out of the serialized form of a Mongo Draft UsageKey. This @@ -491,6 +491,13 @@ def location(self): self._location = self._location.map_into_course(self.id) return self._location + @property + def location(self): + """ + The old name for `usage_key`. This method is analogous to `XModuleMixin.location`. + """ + return self.usage_key + @property def number(self): """ @@ -506,9 +513,9 @@ def number(self): @property def url_name(self): """ - Returns this course's URL name. + The old name for `block_id`. This method is analogous to `XModuleMixin.url_name`. """ - return block_metadata_utils.url_name_for_block(self) + return self.usage_key.block_id @property def display_name_with_default(self): diff --git a/xmodule/block_metadata_utils.py b/xmodule/block_metadata_utils.py index 329c53f8c536..7ab0545480a0 100644 --- a/xmodule/block_metadata_utils.py +++ b/xmodule/block_metadata_utils.py @@ -15,17 +15,6 @@ logger = getLogger(__name__) # pylint: disable=invalid-name -def url_name_for_block(block): - """ - Given a block, returns the block's URL name. - - Arguments: - block (XModuleMixin|CourseOverview|BlockStructureBlockData): - Block that is being accessed - """ - return block.location.block_id - - def display_name_with_default(block): """ Calculates the display name for a block. @@ -50,7 +39,7 @@ def display_name_with_default(block): """ return ( block.display_name if block.display_name is not None - else url_name_for_block(block).replace('_', ' ') + else block.usage_key.block_id.replace('_', ' ') ) diff --git a/xmodule/tests/test_course_metadata_utils.py b/xmodule/tests/test_course_metadata_utils.py index ab38490112e2..28d18739cb75 100644 --- a/xmodule/tests/test_course_metadata_utils.py +++ b/xmodule/tests/test_course_metadata_utils.py @@ -12,7 +12,6 @@ from xmodule.block_metadata_utils import ( display_name_with_default, display_name_with_default_escaped, - url_name_for_block ) from xmodule.course_metadata_utils import ( DEFAULT_START_DATE, @@ -125,9 +124,6 @@ def noop_gettext(text): # lint-amnesty, pylint: disable=unused-variable "course_MNXXK4TTMUWXMMJ2KVXGS5TFOJZWS5DZLAVUGUZNGIYDGK2ZGIYDSNQ~" ), ]), - FunctionTest(url_name_for_block, [ - TestScenario((self.html_course,), self.html_course.location.block_id), - ]), FunctionTest(display_name_with_default_escaped, [ # Test course with a display name that contains characters that need escaping. TestScenario((self.html_course,), "Intro to html"), diff --git a/xmodule/x_module.py b/xmodule/x_module.py index 4ed1a03b619d..5f42a0d10463 100644 --- a/xmodule/x_module.py +++ b/xmodule/x_module.py @@ -310,15 +310,15 @@ def system(self): @property def course_id(self): - return self.location.course_key + return self.context_key @property def category(self): - return self.scope_ids.block_type + return self.usage_key.block_type @property def location(self): - return self.scope_ids.usage_id + return self.usage_key @location.setter def location(self, value): @@ -330,7 +330,7 @@ def location(self, value): @property def url_name(self): - return block_metadata_utils.url_name_for_block(self) + return self.usage_key.block_id @property def display_name_with_default(self):