diff --git a/lms/djangoapps/instructor/views.py b/lms/djangoapps/instructor/views.py index b2f81639c9..d356687000 100644 --- a/lms/djangoapps/instructor/views.py +++ b/lms/djangoapps/instructor/views.py @@ -310,7 +310,9 @@ def instructor_dashboard(request, course_id): "Delete student state for module" in action or "Rescore student's problem submission" in action): # get the form data - unique_student_identifier = request.POST.get('unique_student_identifier', '') + unique_student_identifier = request.POST.get( + 'unique_student_identifier', '' + ) problem_urlname = request.POST.get('problem_for_student', '') module_state_key = get_module_url(problem_urlname) # try to uniquely id student by email address or username @@ -320,23 +322,42 @@ def instructor_dashboard(request, course_id): if student is not None: # find the module in question try: - student_module = StudentModule.objects.get(student_id=student.id, - course_id=course_id, - module_state_key=module_state_key) + student_module = StudentModule.objects.get( + student_id=student.id, + course_id=course_id, + module_state_key=module_state_key + ) msg += "Found module. " - except StudentModule.DoesNotExist: - msg += "Couldn't find module with that urlname. " + except StudentModule.DoesNotExist as err: + error_msg = "Couldn't find module with that urlname: {0}. ".format( + problem_urlname + ) + msg += "" + error_msg + "({0}) ".format(err) + "" + log.debug(error_msg) if student_module is not None: if "Delete student state for module" in action: # delete the state try: student_module.delete() - msg += "Deleted student module state for %s!" % module_state_key - event = {"problem": problem_url, "student": unique_student_identifier, "course": course_id} - track.views.server_track(request, "delete-student-module-state", event, page="idashboard") - except: - msg += "Failed to delete module state for %s/%s" % (unique_student_identifier, problem_urlname) + msg += "Deleted student module state for {0}!".format(module_state_key) + event = { + "problem": problem_url, + "student": unique_student_identifier, + "course": course_id + } + track.views.server_track( + request, + "delete-student-module-state", + event, + page="idashboard" + ) + except Exception as err: + error_msg = "Failed to delete module state for {0}/{1}. ".format( + unique_student_identifier, problem_urlname + ) + msg += "" + error_msg + "({0}) ".format(err) + "" + log.exception(error_msg) elif "Reset student's attempts" in action: # modify the problem's state try: @@ -344,19 +365,24 @@ def instructor_dashboard(request, course_id): problem_state = json.loads(student_module.state) old_number_of_attempts = problem_state["attempts"] problem_state["attempts"] = 0 - # save student_module.state = json.dumps(problem_state) student_module.save() - event = {"old_attempts": old_number_of_attempts, - "student": student, - "problem": student_module.module_state_key, - "instructor": request.user, - "course": course_id} + event = { + "old_attempts": old_number_of_attempts, + "student": unicode(student), + "problem": student_module.module_state_key, + "instructor": unicode(request.user), + "course": course_id + } track.views.server_track(request, "reset-student-attempts", event, page="idashboard") msg += "Module state successfully reset!" - except: - msg += "Couldn't reset module state. " + except Exception as err: + error_msg = "Couldn't reset module state for {0}/{1}. ".format( + unique_student_identifier, problem_urlname + ) + msg += "" + error_msg + "({0}) ".format(err) + "" + log.exception(error_msg) else: # "Rescore student's problem submission" case try: @@ -365,9 +391,14 @@ def instructor_dashboard(request, course_id): msg += 'Failed to create a background task for rescoring "{0}" for student {1}.'.format(module_state_key, unique_student_identifier) else: track.views.server_track(request, "rescore-student-submission", {"problem": module_state_key, "student": unique_student_identifier, "course": course_id}, page="idashboard") - except Exception as e: - log.exception("Encountered exception from rescore: {0}") - msg += 'Failed to create a background task for rescoring "{0}": {1}.'.format(module_state_key, e.message) + except Exception as err: + msg += 'Failed to create a background task for rescoring "{0}": {1}.'.format( + module_state_key, err.message + ) + log.exception("Encountered exception from rescore: student '{0}' problem '{1}'".format( + unique_student_identifier, module_state_key + ) + ) elif "Get link to student's progress page" in action: unique_student_identifier = request.POST.get('unique_student_identifier', '')