refactor: rename descriptor -> block within remaining lms

Co-authored-by: Agrendalath <piotr@surowiec.it>
This commit is contained in:
Pooja Kulkarni
2023-01-04 14:04:13 -05:00
committed by Agrendalath
parent c452fb3204
commit 702e14a28a
9 changed files with 23 additions and 23 deletions

View File

@@ -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.

View File

@@ -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.

View File

@@ -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

View File

@@ -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.
"""

View File

@@ -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,

View File

@@ -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:

View File

@@ -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:

View File

@@ -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)

View File

@@ -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