Commit ae88d5c0 by Justin Riley

support passing student via username string

* Add _get_student_obj that fetches and returns the django user if the
  input is a string otherwise returns the original input
* Updated all ProctorModuleInfo methods that take 'student' as an arg to
  use _get_student_obj
* Changed 'student' kwarg to required arg in get_grades
parent e0b54700
...@@ -107,6 +107,11 @@ class ProctorModuleInfo(object): ...@@ -107,6 +107,11 @@ class ProctorModuleInfo(object):
self.course = self.ms.get_course(course_id) self.course = self.ms.get_course(course_id)
self.get_released_proctor_modules() self.get_released_proctor_modules()
def _get_student_obj(self, student):
if isinstance(student, basestring):
student = User.objects.get(username=student)
return student
def get_released_proctor_modules(self): def get_released_proctor_modules(self):
chapters = [] chapters = []
...@@ -147,10 +152,8 @@ class ProctorModuleInfo(object): ...@@ -147,10 +152,8 @@ class ProctorModuleInfo(object):
self.rpmods = rpmods self.rpmods = rpmods
return rpmods return rpmods
def get_grades(self, student=None, request=None): def get_grades(self, student, request=None):
if student is None: student = self._get_student_obj(student)
student = self.student
if request is None: if request is None:
request = DummyRequest() request = DummyRequest()
request.user = student request.user = student
...@@ -173,9 +176,7 @@ class ProctorModuleInfo(object): ...@@ -173,9 +176,7 @@ class ProctorModuleInfo(object):
StudentModule state for each, and see which randomized problem was StudentModule state for each, and see which randomized problem was
selected for a student (if any). selected for a student (if any).
""" """
if isinstance(student, basestring): student = self._get_student_obj(student)
student = User.objects.get(username=student)
self.student = student
smstates = OrderedDict() smstates = OrderedDict()
...@@ -241,7 +242,7 @@ class ProctorModuleInfo(object): ...@@ -241,7 +242,7 @@ class ProctorModuleInfo(object):
# get grades, match gradeset assignments with StudentModule states, and # get grades, match gradeset assignments with StudentModule states, and
# put grades there # put grades there
self.get_grades() self.get_grades(student)
for score in self.gradeset['totaled_scores']['Assessment']: for score in self.gradeset['totaled_scores']['Assessment']:
if score.section in smstates: if score.section in smstates:
smstates[score.section].score = score smstates[score.section].score = score
...@@ -262,8 +263,8 @@ class ProctorModuleInfo(object): ...@@ -262,8 +263,8 @@ class ProctorModuleInfo(object):
if not attempted and sm.score is not None and sm.score.earned: if not attempted and sm.score is not None and sm.score.earned:
attempted = True attempted = True
earned=(sm.score.earned if sm.score is not None else None) earned = (sm.score.earned if sm.score is not None else None)
possible=(sm.score.possible if sm.score is not None else None) possible = (sm.score.possible if sm.score is not None else None)
stat = dict(name=name, assignment=sm.rpmod.ra_ps.display_name, stat = dict(name=name, assignment=sm.rpmod.ra_ps.display_name,
pm_sm=sm.ps_sm.state, choice=sm.choice, pm_sm=sm.ps_sm.state, choice=sm.choice,
problem=sm.problem_name, problem=sm.problem_name,
...@@ -285,6 +286,7 @@ class ProctorModuleInfo(object): ...@@ -285,6 +286,7 @@ class ProctorModuleInfo(object):
where grade1 = points earned on assignment LS1, or '' if not attempted where grade1 = points earned on assignment LS1, or '' if not attempted
and prob1 = problem which was assigned or '' if not attempted and prob1 = problem which was assigned or '' if not attempted
""" """
student = self._get_student_obj(student)
status = self.get_student_status(student) status = self.get_student_status(student)
ret = OrderedDict() ret = OrderedDict()
ret['id'] = student.id ret['id'] = student.id
...@@ -312,6 +314,7 @@ class ProctorModuleInfo(object): ...@@ -312,6 +314,7 @@ class ProctorModuleInfo(object):
possible=assignment['possible']) possible=assignment['possible'])
def get_assignments_attempted_and_failed(self, student, do_reset=False): def get_assignments_attempted_and_failed(self, student, do_reset=False):
student = self._get_student_obj(student)
status = self.get_student_status(student) status = self.get_student_status(student)
failed = [self._get_od_for_assignment(student, a) failed = [self._get_od_for_assignment(student, a)
for a in status['assignments'] if a['attempted'] and for a in status['assignments'] if a['attempted'] and
......
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