From 702e14a28adbaea76b370d70baf948e6ea31fb2b Mon Sep 17 00:00:00 2001 From: Pooja Kulkarni Date: Wed, 4 Jan 2023 14:04:13 -0500 Subject: [PATCH] refactor: rename descriptor -> block within remaining lms Co-authored-by: Agrendalath --- lms/djangoapps/course_api/blocks/api.py | 2 +- lms/djangoapps/discussion/rest_api/api.py | 2 +- lms/djangoapps/grades/context.py | 2 +- .../grades/rest_api/v1/gradebook_views.py | 4 ++-- lms/djangoapps/grades/tests/utils.py | 2 +- lms/djangoapps/instructor/tasks.py | 16 ++++++++-------- lms/djangoapps/lms_xblock/runtime.py | 2 +- lms/djangoapps/survey/tests/test_utils.py | 2 +- lms/djangoapps/survey/utils.py | 14 +++++++------- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lms/djangoapps/course_api/blocks/api.py b/lms/djangoapps/course_api/blocks/api.py index 156fa3ed6e..a79e9759e1 100644 --- a/lms/djangoapps/course_api/blocks/api.py +++ b/lms/djangoapps/course_api/blocks/api.py @@ -159,7 +159,7 @@ def get_block_metadata(block, includes=()): Get metadata about the specified XBlock. Args: - block (XModuleDescriptor): block object + block (XBlock): block object includes (list|set): list or set of metadata keys to include. Valid keys are: index_dictionary: a dictionary of data used to add this XBlock's content to a search index. diff --git a/lms/djangoapps/discussion/rest_api/api.py b/lms/djangoapps/discussion/rest_api/api.py index f480fb31fe..128d362658 100644 --- a/lms/djangoapps/discussion/rest_api/api.py +++ b/lms/djangoapps/discussion/rest_api/api.py @@ -166,7 +166,7 @@ class DiscussionEntity(Enum): def _get_course(course_key: CourseKey, user: User, check_tab: bool = True) -> CourseBlock: """ - Get the course descriptor, raising CourseNotFoundError if the course is not found or + Get the course block, raising CourseNotFoundError if the course is not found or the user cannot access forums for the course, and DiscussionDisabledError if the discussion tab is disabled for the course. diff --git a/lms/djangoapps/grades/context.py b/lms/djangoapps/grades/context.py index 210fddb73b..54a7e8f93f 100644 --- a/lms/djangoapps/grades/context.py +++ b/lms/djangoapps/grades/context.py @@ -50,7 +50,7 @@ def grading_context(course, course_structure): all_graded_blocks - This contains a list of all blocks that can affect grading a student. This is used to efficiently fetch all the xmodule state for a FieldDataCache without walking - the descriptor tree again. + the block tree again. """ count_all_graded_blocks = 0 diff --git a/lms/djangoapps/grades/rest_api/v1/gradebook_views.py b/lms/djangoapps/grades/rest_api/v1/gradebook_views.py index 6feedbf241..26df7ce258 100644 --- a/lms/djangoapps/grades/rest_api/v1/gradebook_views.py +++ b/lms/djangoapps/grades/rest_api/v1/gradebook_views.py @@ -442,7 +442,7 @@ class GradebookView(GradeViewMixin, PaginatedAPIView): returns a list of grade data broken down by subsection. Args: - course: A Course Descriptor object + course: A CourseBlock object graded_subsections: A list of graded subsection objects in the given course. course_grade: A CourseGrade object. """ @@ -494,7 +494,7 @@ class GradebookView(GradeViewMixin, PaginatedAPIView): Args: user: A User object. - course: A Course Descriptor object. + course: A CourseBlock object. graded_subsections: A list of graded subsections in the given course. course_grade: A CourseGrade object. """ diff --git a/lms/djangoapps/grades/tests/utils.py b/lms/djangoapps/grades/tests/utils.py index dffe80c3dd..9111820379 100644 --- a/lms/djangoapps/grades/tests/utils.py +++ b/lms/djangoapps/grades/tests/utils.py @@ -73,7 +73,7 @@ def answer_problem(course, request, problem, score=1, max_value=1): user = request.user grade_dict = {'value': score, 'max_value': max_value, 'user_id': user.id} - field_data_cache = FieldDataCache.cache_for_descriptor_descendents( + field_data_cache = FieldDataCache.cache_for_block_descendents( course.id, user, course, diff --git a/lms/djangoapps/instructor/tasks.py b/lms/djangoapps/instructor/tasks.py index 11f3deafd9..ac3bda13a8 100644 --- a/lms/djangoapps/instructor/tasks.py +++ b/lms/djangoapps/instructor/tasks.py @@ -45,7 +45,7 @@ def update_exam_completion_task(user_identifier: str, content_id: str, completio try: user = get_user_by_username_or_email(user_identifier) block_key = UsageKey.from_string(content_id) - root_descriptor = modulestore().get_item(block_key) + root_block = modulestore().get_item(block_key) except ObjectDoesNotExist: err_msg = err_msg_prefix + 'User does not exist!' except InvalidKeyError: @@ -66,13 +66,13 @@ def update_exam_completion_task(user_identifier: str, content_id: str, completio request = get_request_or_stub() request.user = user - # Now evil modulestore magic to inflate our descriptor with user state and + # Now evil modulestore magic to inflate our block with user state and # permissions checks. - field_data_cache = FieldDataCache.cache_for_descriptor_descendents( - root_descriptor.scope_ids.usage_id.context_key, user, root_descriptor, read_only=True, + field_data_cache = FieldDataCache.cache_for_block_descendents( + root_block.scope_ids.usage_id.context_key, user, root_block, read_only=True, ) root_block = get_block_for_descriptor( - user, request, root_descriptor, field_data_cache, root_descriptor.scope_ids.usage_id.context_key, + user, request, root_block, field_data_cache, root_block.scope_ids.usage_id.context_key, ) if not root_block: err_msg = err_msg_prefix + 'Block unable to be created from descriptor!' @@ -89,11 +89,11 @@ def update_exam_completion_task(user_identifier: str, content_id: str, completio elif mode == XBlockCompletionMode.AGGREGATOR: # I know this looks weird, but at the time of writing at least, there isn't a good # single way to get the children assigned for a partcular user. Some blocks define the - # child descriptors method, but others don't and with blocks like Randomized Content + # child blocks method, but others don't and with blocks like Randomized Content # (Library Content), the get_children method returns all children and not just assigned # children. So this is our way around situations like that. See also Split Test Block - # for another use case where user state has to be taken into account via get_child_descriptors - block_children = ((hasattr(block, 'get_child_descriptors') and block.get_child_descriptors()) + # for another use case where user state has to be taken into account via get_child_blocks + block_children = ((hasattr(block, 'get_child_blocks') and block.get_child_blocks()) or (hasattr(block, 'get_children') and block.get_children()) or []) for child in block_children: diff --git a/lms/djangoapps/lms_xblock/runtime.py b/lms/djangoapps/lms_xblock/runtime.py index c786271876..c902bf8c35 100644 --- a/lms/djangoapps/lms_xblock/runtime.py +++ b/lms/djangoapps/lms_xblock/runtime.py @@ -28,7 +28,7 @@ def handler_url(block, handler_name, suffix='', query='', thirdparty=False): # Be sure this is really a handler. # # We're checking the .__class__ instead of the block itself to avoid - # auto-proxying from Descriptor -> Module, in case descriptors want + # auto-proxying from Descriptor -> XBlock, in case descriptors want # to ask for handler URLs without a student context. func = getattr(block.__class__, handler_name, None) if not func: diff --git a/lms/djangoapps/survey/tests/test_utils.py b/lms/djangoapps/survey/tests/test_utils.py index 2764380b56..f02efe0934 100644 --- a/lms/djangoapps/survey/tests/test_utils.py +++ b/lms/djangoapps/survey/tests/test_utils.py @@ -64,7 +64,7 @@ class SurveyModelsTests(ModuleStoreTestCase): def test_is_survey_required_for_course(self): """ Assert the a requried course survey is when both the flags is set and a survey name - is set on the course descriptor + is set on the course block """ assert is_survey_required_for_course(self.course) diff --git a/lms/djangoapps/survey/utils.py b/lms/djangoapps/survey/utils.py index 2f3d2f1483..42f8a41bf4 100644 --- a/lms/djangoapps/survey/utils.py +++ b/lms/djangoapps/survey/utils.py @@ -21,20 +21,20 @@ class SurveyRequiredAccessError(AccessError): super().__init__(error_code, developer_message, user_message) -def is_survey_required_for_course(course_descriptor): +def is_survey_required_for_course(course_block): """ Returns whether a Survey is required for this course """ # Check to see that the survey is required in the CourseBlock. - if not getattr(course_descriptor, 'course_survey_required', False): + if not getattr(course_block, 'course_survey_required', False): return SurveyRequiredAccessError() # Check that the specified Survey for the course exists. - return SurveyForm.get(course_descriptor.course_survey_name, throw_if_not_found=False) + return SurveyForm.get(course_block.course_survey_name, throw_if_not_found=False) -def check_survey_required_and_unanswered(user, course_descriptor): +def check_survey_required_and_unanswered(user, course_block): """ Checks whether a user is required to answer the survey and has yet to do so. @@ -42,7 +42,7 @@ def check_survey_required_and_unanswered(user, course_descriptor): AccessResponse: Either ACCESS_GRANTED or SurveyRequiredAccessError. """ - if not is_survey_required_for_course(course_descriptor): + if not is_survey_required_for_course(course_block): return ACCESS_GRANTED # anonymous users do not need to answer the survey @@ -50,12 +50,12 @@ def check_survey_required_and_unanswered(user, course_descriptor): return ACCESS_GRANTED # course staff do not need to answer survey - has_staff_access = has_access(user, 'staff', course_descriptor) + has_staff_access = has_access(user, 'staff', course_block) if has_staff_access: return ACCESS_GRANTED # survey is required and it exists, let's see if user has answered the survey - survey = SurveyForm.get(course_descriptor.course_survey_name) + survey = SurveyForm.get(course_block.course_survey_name) answered_survey = SurveyAnswer.do_survey_answers_exist(survey, user) if answered_survey: return ACCESS_GRANTED