Commit 0c5ca91c by David Ormsbee

Merge pull request #1559 from MITx/dave/feature/delete_student_state

Taking Ike's delete-student-state-for-problem code and putting it in a separate PR
parents f8280490 c7920f09
...@@ -195,7 +195,7 @@ def instructor_dashboard(request, course_id): ...@@ -195,7 +195,7 @@ def instructor_dashboard(request, course_id):
track.views.server_track(request, 'dump-answer-dist-csv', {}, page='idashboard') track.views.server_track(request, 'dump-answer-dist-csv', {}, page='idashboard')
return return_csv('answer_dist_{0}.csv'.format(course_id), get_answers_distribution(request, course_id)) return return_csv('answer_dist_{0}.csv'.format(course_id), get_answers_distribution(request, course_id))
elif "Reset student's attempts" in action: elif "Reset student's attempts" in action or "Delete student state for problem" in action:
# get the form data # get the form data
unique_student_identifier = request.POST.get('unique_student_identifier', '') unique_student_identifier = request.POST.get('unique_student_identifier', '')
problem_to_reset = request.POST.get('problem_to_reset', '') problem_to_reset = request.POST.get('problem_to_reset', '')
...@@ -226,28 +226,36 @@ def instructor_dashboard(request, course_id): ...@@ -226,28 +226,36 @@ def instructor_dashboard(request, course_id):
except Exception as e: except Exception as e:
msg += "<font color='red'>Couldn't find module with that urlname. </font>" msg += "<font color='red'>Couldn't find module with that urlname. </font>"
# modify the problem's state if "Delete student state for problem" in action:
try: # delete the state
# load the state json try:
problem_state = json.loads(module_to_reset.state) module_to_reset.delete()
old_number_of_attempts = problem_state["attempts"] msg += "<font color='red'>Deleted student module state for %s!</font>" % module_state_key
problem_state["attempts"] = 0 except:
msg += "Failed to delete module state for %s/%s" % (unique_student_identifier, problem_to_reset)
# save else:
module_to_reset.state = json.dumps(problem_state) # modify the problem's state
module_to_reset.save() try:
track.views.server_track(request, # load the state json
'{instructor} reset attempts from {old_attempts} to 0 for {student} on problem {problem} in {course}'.format( problem_state = json.loads(module_to_reset.state)
old_attempts=old_number_of_attempts, old_number_of_attempts = problem_state["attempts"]
student=student_to_reset, problem_state["attempts"] = 0
problem=module_to_reset.module_state_key,
instructor=request.user, # save
course=course_id), module_to_reset.state = json.dumps(problem_state)
{}, module_to_reset.save()
page='idashboard') track.views.server_track(request,
msg += "<font color='green'>Module state successfully reset!</font>" '{instructor} reset attempts from {old_attempts} to 0 for {student} on problem {problem} in {course}'.format(
except: old_attempts=old_number_of_attempts,
msg += "<font color='red'>Couldn't reset module state. </font>" student=student_to_reset,
problem=module_to_reset.module_state_key,
instructor=request.user,
course=course_id),
{},
page='idashboard')
msg += "<font color='green'>Module state successfully reset!</font>"
except:
msg += "<font color='red'>Couldn't reset module state. </font>"
elif "Get link to student's progress page" in action: elif "Get link to student's progress page" in action:
......
...@@ -149,6 +149,12 @@ function goto( mode) ...@@ -149,6 +149,12 @@ function goto( mode)
<p><input type="text" name="unique_student_identifier"> <input type="submit" name="action" value="Get link to student's progress page"></p> <p><input type="text" name="unique_student_identifier"> <input type="submit" name="action" value="Get link to student's progress page"></p>
<p>and, if you want to reset the number of attempts for a problem, the urlname of that problem</p> <p>and, if you want to reset the number of attempts for a problem, the urlname of that problem</p>
<p> <input type="text" name="problem_to_reset"> <input type="submit" name="action" value="Reset student's attempts"> </p> <p> <input type="text" name="problem_to_reset"> <input type="submit" name="action" value="Reset student's attempts"> </p>
%if instructor_access:
<p> You may also delete the entire state of a student for a problem:
<input type="submit" name="action" value="Delete student state for problem"> </p>
%endif
%endif %endif
##----------------------------------------------------------------------------- ##-----------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment