Commit fd20496a by David Ormsbee

Merge pull request #1280 from MITx/feature/jth/attempts_reset

Added 2 new instructor tools
parents ad68177e f7f563db
......@@ -8,6 +8,7 @@ import logging
import os
import requests
import urllib
import json
from StringIO import StringIO
......@@ -30,6 +31,7 @@ from django_comment_client.models import (Role,
from django_comment_client.utils import has_forum_access
from psychometrics import psychoanalyze
from student.models import CourseEnrollment, CourseEnrollmentAllowed
from courseware.models import StudentModule
from xmodule.course_module import CourseDescriptor
from xmodule.modulestore import Location
from xmodule.modulestore.django import modulestore
......@@ -186,6 +188,80 @@ def instructor_dashboard(request, course_id):
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))
elif "Reset student's attempts" in action:
# get the form data
unique_student_identifier=request.POST.get('unique_student_identifier','')
problem_to_reset=request.POST.get('problem_to_reset','')
if problem_to_reset[-4:]==".xml":
problem_to_reset=problem_to_reset[:-4]
# try to uniquely id student by email address or username
try:
if "@" in unique_student_identifier:
student_to_reset=User.objects.get(email=unique_student_identifier)
else:
student_to_reset=User.objects.get(username=unique_student_identifier)
msg+="Found a single student to reset. "
except:
student_to_reset=None
msg+="<font color='red'>Couldn't find student with that email or username. </font>"
if student_to_reset is not None:
# find the module in question
try:
(org, course_name, run)=course_id.split("/")
module_state_key="i4x://"+org+"/"+course_name+"/problem/"+problem_to_reset
module_to_reset=StudentModule.objects.get(student_id=student_to_reset.id,
course_id=course_id,
module_state_key=module_state_key)
msg+="Found module to reset. "
except Exception as e:
msg+="<font color='red'>Couldn't find module with that urlname. </font>"
# 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
module_to_reset.state=json.dumps(problem_state)
module_to_reset.save()
track.views.server_track(request,
'{instructor} reset attempts from {old_attempts} to 0 for {student} on problem {problem} in {course}'.format(
old_attempts=old_number_of_attempts,
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:
unique_student_identifier=request.POST.get('unique_student_identifier','')
try:
if "@" in unique_student_identifier:
student_to_reset=User.objects.get(email=unique_student_identifier)
else:
student_to_reset=User.objects.get(username=unique_student_identifier)
progress_url=reverse('student_progress',kwargs={'course_id':course_id,'student_id': student_to_reset.id})
track.views.server_track(request,
'{instructor} requested progress page for {student} in {course}'.format(
student=student_to_reset,
instructor=request.user,
course=course_id),
{},
page='idashboard')
msg+="<a href='{0}' target='_blank'> Progress page for username: {1} with email address: {2}</a>.".format(progress_url,student_to_reset.username,student_to_reset.email)
except:
msg+="<font color='red'>Couldn't find student with that username. </font>"
#----------------------------------------
# export grades to remote gradebook
......
......@@ -141,6 +141,11 @@ function goto( mode)
%endif
<H2>Student-specific grade inspection and adjustment</h2>
<p>edX email address or their username: </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> <input type="text" name="problem_to_reset"> <input type="submit" name="action" value="Reset student's attempts"> </p>
%endif
##-----------------------------------------------------------------------------
......@@ -282,6 +287,9 @@ function goto( mode)
</form>
%if msg:
<p></p><p>${msg}</p>
%endif
##-----------------------------------------------------------------------------
##-----------------------------------------------------------------------------
......@@ -334,9 +342,6 @@ function goto( mode)
##-----------------------------------------------------------------------------
## always show msg
%if msg:
<p>${msg}</p>
%endif
##-----------------------------------------------------------------------------
%if modeflag.get('Admin'):
......
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