Skip to content
Open
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
2 changes: 1 addition & 1 deletion lms/djangoapps/grades/course_grade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/grades/subsection_grade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 11 additions & 4 deletions openedx/core/djangoapps/content/course_overviews/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
"""
Expand All @@ -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):
Expand Down
13 changes: 1 addition & 12 deletions xmodule/block_metadata_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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('_', ' ')
)


Expand Down
4 changes: 0 additions & 4 deletions xmodule/tests/test_course_metadata_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"),
Expand Down
8 changes: 4 additions & 4 deletions xmodule/x_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down