diff --git a/lms/djangoapps/instructor/enrollment.py b/lms/djangoapps/instructor/enrollment.py index 775809c350c7..7335d212282f 100644 --- a/lms/djangoapps/instructor/enrollment.py +++ b/lms/djangoapps/instructor/enrollment.py @@ -18,7 +18,6 @@ from edxmako.shortcuts import render_to_string from lang_pref import LANGUAGE_KEY -from submissions import api as sub_api # installed from the edx-submissions repository from student.models import anonymous_id_for_user from openedx.core.djangoapps.user_api.models import UserPreference @@ -219,6 +218,7 @@ def reset_student_attempts(course_id, student, module_state_key, delete_module=F submissions.SubmissionError: unexpected error occurred while resetting the score in the submissions API. """ + user_id = anonymous_id_for_user(student, course_id) try: # A block may have children. Clear state on children first. block = modulestore().get_item(module_state_key) @@ -229,30 +229,30 @@ def reset_student_attempts(course_id, student, module_state_key, delete_module=F except StudentModule.DoesNotExist: # If a particular child doesn't have any state, no big deal, as long as the parent does. pass + # Allow the block to reset itself, if it has defined such a method + # We trust blocks to clean dependencies as well, so openassessment will clear out any relevant submissions + block_reset = getattr(block, "clear_state", None) + if callable(block_reset): + block_reset(user_id=user_id, course_id=course_id, item_id=module_state_key, delete=delete_module) except ItemNotFoundError: log.warning("Could not find %s in modulestore when attempting to reset attempts.", module_state_key) - # Reset the student's score in the submissions API - # Currently this is used only by open assessment (ORA 2) - # We need to do this *before* retrieving the `StudentModule` model, - # because it's possible for a score to exist even if no student module exists. - if delete_module: - sub_api.reset_score( - anonymous_id_for_user(student, course_id), - course_id.to_deprecated_string(), - module_state_key.to_deprecated_string(), + try: + module_to_reset = StudentModule.objects.get( + student_id=student.id, + course_id=course_id, + module_state_key=module_state_key ) - - module_to_reset = StudentModule.objects.get( - student_id=student.id, - course_id=course_id, - module_state_key=module_state_key - ) - - if delete_module: - module_to_reset.delete() - else: - _reset_module_attempts(module_to_reset) + if delete_module: + module_to_reset.delete() + else: + _reset_module_attempts(module_to_reset) + except StudentModule.DoesNotExist: + msg = ( + u"No record found when deleting module {module_state_key}" + u"in course {course_id} for student {student_id}." + ).format(module_state_key=module_state_key, course_id=course_id, student_id=student_id) + logger.exception(msg) def _reset_module_attempts(studentmodule): diff --git a/requirements/edx/github.txt b/requirements/edx/github.txt index 8b7ca5dad47a..6bc9a3dfe1fb 100644 --- a/requirements/edx/github.txt +++ b/requirements/edx/github.txt @@ -78,8 +78,8 @@ git+https://github.com/edx/XBlock.git@xblock-0.4.4#egg=XBlock==0.4.4 -e git+https://github.com/edx/event-tracking.git@0.2.1#egg=event-tracking==0.2.1 -e git+https://github.com/edx/django-splash.git@v0.2#egg=django-splash==0.2 -e git+https://github.com/edx/acid-block.git@e46f9cda8a03e121a00c7e347084d142d22ebfb7#egg=acid-xblock --e git+https://github.com/edx/edx-ora2.git@0.2.6#egg=ora2==0.2.6 --e git+https://github.com/edx/edx-submissions.git@0.1.3#egg=edx-submissions==0.1.3 +-e git+https://github.com/edx/edx-ora2.git@efischer/delete_state#egg=ora2 +-e git+https://github.com/edx/edx-submissions.git@efischer/soft_delete_sub#egg=edx-submissions git+https://github.com/edx/ease.git@release-2015-07-14#egg=ease==0.1.3 git+https://github.com/edx/i18n-tools.git@v0.2#egg=i18n-tools==v0.2 git+https://github.com/edx/edx-oauth2-provider.git@0.5.8#egg=edx-oauth2-provider==0.5.8