From af13a326be32ce8c8bc440c7ae2160113044be81 Mon Sep 17 00:00:00 2001 From: 0x29a Date: Mon, 2 Jan 2023 15:45:44 +0100 Subject: [PATCH] refactor: rename module (or item) -> block within lms/djangoapps/instructor --- lms/djangoapps/instructor/tasks.py | 8 ++-- .../instructor/tests/test_services.py | 2 +- lms/djangoapps/instructor/tests/test_tools.py | 2 +- lms/djangoapps/instructor/utils.py | 38 ------------------- lms/djangoapps/instructor/views/api.py | 4 +- lms/djangoapps/instructor/views/tools.py | 20 ++-------- 6 files changed, 12 insertions(+), 62 deletions(-) delete mode 100644 lms/djangoapps/instructor/utils.py diff --git a/lms/djangoapps/instructor/tasks.py b/lms/djangoapps/instructor/tasks.py index c007203060..11f3deafd9 100644 --- a/lms/djangoapps/instructor/tasks.py +++ b/lms/djangoapps/instructor/tasks.py @@ -71,11 +71,11 @@ def update_exam_completion_task(user_identifier: str, content_id: str, completio field_data_cache = FieldDataCache.cache_for_descriptor_descendents( root_descriptor.scope_ids.usage_id.context_key, user, root_descriptor, read_only=True, ) - root_module = get_block_for_descriptor( + root_block = get_block_for_descriptor( user, request, root_descriptor, field_data_cache, root_descriptor.scope_ids.usage_id.context_key, ) - if not root_module: - err_msg = err_msg_prefix + 'Module unable to be created from descriptor!' + if not root_block: + err_msg = err_msg_prefix + 'Block unable to be created from descriptor!' log.error(err_msg) return @@ -99,4 +99,4 @@ def update_exam_completion_task(user_identifier: str, content_id: str, completio for child in block_children: _submit_completions(child, user, completion) - _submit_completions(root_module, user, completion) + _submit_completions(root_block, user, completion) diff --git a/lms/djangoapps/instructor/tests/test_services.py b/lms/djangoapps/instructor/tests/test_services.py index 8868c2c7c4..488c0d43a6 100644 --- a/lms/djangoapps/instructor/tests/test_services.py +++ b/lms/djangoapps/instructor/tests/test_services.py @@ -240,7 +240,7 @@ class InstructorServiceTests(SharedModuleStoreTestCase): self.service.complete_student_attempt(username, str(self.course.location)) mock_logger.assert_called_once_with( self.complete_error_prefix.format(user=username, content_id=self.course.location) + - 'Module unable to be created from descriptor!' + 'Block unable to be created from descriptor!' ) def test_is_user_staff(self): diff --git a/lms/djangoapps/instructor/tests/test_tools.py b/lms/djangoapps/instructor/tests/test_tools.py index f853c2c05f..26f1ccd1f3 100644 --- a/lms/djangoapps/instructor/tests/test_tools.py +++ b/lms/djangoapps/instructor/tests/test_tools.py @@ -357,7 +357,7 @@ class TestDataDumps(ModuleStoreTestCase): extended) tools.set_due_date_extension(self.course, self.week1, self.user2, extended) - report = tools.dump_module_extensions(self.course, self.week1) + report = tools.dump_block_extensions(self.course, self.week1) assert ( report['title'] == 'Users with due date extensions for ' + self.week1.display_name) diff --git a/lms/djangoapps/instructor/utils.py b/lms/djangoapps/instructor/utils.py deleted file mode 100644 index f16f9d422c..0000000000 --- a/lms/djangoapps/instructor/utils.py +++ /dev/null @@ -1,38 +0,0 @@ -""" -Helpers for instructor app. -""" - - -from lms.djangoapps.courseware.model_data import FieldDataCache -from lms.djangoapps.courseware.block_render import get_block -from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order - - -class DummyRequest: - """Dummy request""" - - META = {} - - def __init__(self): # lint-amnesty, pylint: disable=useless-return - self.session = {} - self.user = None - return - - def get_host(self): - """Return a default host.""" - return 'edx.mit.edu' - - def is_secure(self): - """Always insecure.""" - return False - - -def get_module_for_student(student, usage_key, request=None, course=None): - """Return the module for the (student, location) using a DummyRequest.""" - if request is None: - request = DummyRequest() - request.user = student - - descriptor = modulestore().get_item(usage_key, depth=0) - field_data_cache = FieldDataCache([descriptor], usage_key.course_key, student) - return get_block(student, request, usage_key, field_data_cache, course=course) diff --git a/lms/djangoapps/instructor/views/api.py b/lms/djangoapps/instructor/views/api.py index 8388fffb4f..eb0d6aa8a5 100644 --- a/lms/djangoapps/instructor/views/api.py +++ b/lms/djangoapps/instructor/views/api.py @@ -124,7 +124,7 @@ from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_c from openedx.core.lib.courses import get_course_by_id from openedx.features.course_experience.url_helpers import get_learning_mfe_home_url from .tools import ( - dump_module_extensions, + dump_block_extensions, dump_student_extensions, find_unit, get_student_from_identifier, @@ -2915,7 +2915,7 @@ def show_unit_extensions(request, course_id): """ course = get_course_by_id(CourseKey.from_string(course_id)) unit = find_unit(course, request.POST.get('url')) - return JsonResponse(dump_module_extensions(course, unit)) + return JsonResponse(dump_block_extensions(course, unit)) @handle_dashboard_error diff --git a/lms/djangoapps/instructor/views/tools.py b/lms/djangoapps/instructor/views/tools.py index f6ad49dbc5..b660a544ef 100644 --- a/lms/djangoapps/instructor/views/tools.py +++ b/lms/djangoapps/instructor/views/tools.py @@ -11,7 +11,6 @@ from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imp from django.http import HttpResponseBadRequest from django.utils.translation import gettext as _ from edx_when import api -from opaque_keys.edx.keys import UsageKey from pytz import UTC from common.djangoapps.student.models import CourseEnrollment, get_user_by_username_or_email @@ -96,9 +95,8 @@ def parse_datetime(datestr): def find_unit(course, url): """ - Finds the unit (block, module, whatever the terminology is) with the given - url in the course tree and returns the unit. Raises DashboardError if no - unit is found. + Finds the unit/block with the given url in the course tree and returns the unit. + Raises DashboardError if no unit is found. """ def find(node, url): """ @@ -215,9 +213,9 @@ def set_due_date_extension(course, unit, student, due_date, actor=None, reason=' api.get_dates_for_course(course.id, user=student, use_cached=False) -def dump_module_extensions(course, unit): +def dump_block_extensions(course, unit): """ - Dumps data about students with due date extensions for a particular module, + Dumps data about students with due date extensions for a particular block, specified by 'url', in a particular course. """ header = [_("Username"), _("Full Name"), _("Extended Due Date")] @@ -258,13 +256,3 @@ def dump_student_extensions(course, student): "title": _("Due date extensions for {0} {1} ({2})").format( student.first_name, student.last_name, student.username), "data": data} - - -def add_block_ids(payload): - """ - rather than manually parsing block_ids from module_ids on the client, pass the block_ids explicitly in the payload - """ - if 'data' in payload: - for ele in payload['data']: - if 'module_id' in ele: - ele['block_id'] = UsageKey.from_string(ele['module_id']).block_id