Taking Ike's delete-student-state-for-problem code and putting it in a separate PR so it's not bundled with more debated features.

This commit is contained in:
David Ormsbee
2013-02-27 11:42:06 -05:00
parent f828049043
commit c7920f09ad
2 changed files with 36 additions and 22 deletions

View File

@@ -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):
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)
else:
# modify the problem's state
try:
# load the state json
problem_state = json.loads(module_to_reset.state)
old_number_of_attempts = problem_state["attempts"]
problem_state["attempts"] = 0
# save # save
module_to_reset.state = json.dumps(problem_state) module_to_reset.state = json.dumps(problem_state)
module_to_reset.save() module_to_reset.save()
track.views.server_track(request, track.views.server_track(request,
'{instructor} reset attempts from {old_attempts} to 0 for {student} on problem {problem} in {course}'.format( '{instructor} reset attempts from {old_attempts} to 0 for {student} on problem {problem} in {course}'.format(
old_attempts=old_number_of_attempts, old_attempts=old_number_of_attempts,
student=student_to_reset, student=student_to_reset,
problem=module_to_reset.module_state_key, problem=module_to_reset.module_state_key,
instructor=request.user, instructor=request.user,
course=course_id), course=course_id),
{}, {},
page='idashboard') page='idashboard')
msg += "<font color='green'>Module state successfully reset!</font>" msg += "<font color='green'>Module state successfully reset!</font>"
except: except:
msg += "<font color='red'>Couldn't reset module state. </font>" 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:

View File

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