def setMark(self, grade, entered_by): """ Set the mark of the group members """ super(GroupActivityMark_LetterGrade, self).setMark(grade) #assign mark for each member in the group group_members = GroupMember.objects.filter(group=self.group, activity=self.letter_activity, confirmed=True) for g_member in group_members: try: lgrade = LetterGrade.objects.get(activity=self.letter_activity, member=g_member.student) except LetterGrade.DoesNotExist: lgrade = LetterGrade(activity=self.letter_activity, member=g_member.student) lgrade.letter_grade = grade lgrade.flag = 'GRAD' lgrade.save(entered_by=entered_by, group=self.group)
def test_get_grade(self): """ Make sure activity.get_grade() keeps the right things hidden """ o = CourseOffering.objects.get(slug=self.course_slug) na = NumericActivity.objects.get(slug='a1') la = LetterActivity.objects.get(slug='rep') instr = Person.objects.get(userid='ggbaker') student = Member.objects.get(person__userid='0aaa0', offering=o) na.status = 'RLS' na.save(entered_by=instr) la.status = 'RLS' la.save(entered_by=instr) # no grades yet self.assertEqual(na.get_grade(student.person, 'STUD'), None) self.assertEqual(la.get_grade(student.person, 'STUD'), None) self.assertEqual(na.get_grade(student.person, 'INST'), None) self.assertEqual(la.get_grade(student.person, 'INST'), None) # grades should be visible ng = NumericGrade(activity=na, member=student, value=1, flag='GRAD', comment='Foo') ng.save(entered_by=instr) lg = LetterGrade(activity=la, member=student, letter_grade='A', flag='GRAD', comment='Foo') lg.save(entered_by=instr) self.assertEqual(na.get_grade(student.person, 'STUD').grade, 1) self.assertEqual(la.get_grade(student.person, 'STUD').grade, 'A') self.assertEqual(na.get_grade(student.person, 'INST').grade, 1) self.assertEqual(la.get_grade(student.person, 'INST').grade, 'A') # unreleased: grades visible only to staff na.status = 'URLS' na.save(entered_by=instr) la.status = 'URLS' la.save(entered_by=instr) self.assertEqual(na.get_grade(student.person, 'STUD'), None) self.assertEqual(la.get_grade(student.person, 'STUD'), None) self.assertEqual(na.get_grade(student.person, 'INST').grade, 1) self.assertEqual(la.get_grade(student.person, 'INST').grade, 'A') # student shouldn't ever see invisible grade na.status = 'INVI' na.save(entered_by=instr) la.status = 'INVI' la.save(entered_by=instr) with self.assertRaises(RuntimeError): na.get_grade(student.person, 'STUD') with self.assertRaises(RuntimeError): la.get_grade(student.person, 'STUD') self.assertEqual(na.get_grade(student.person, 'INST').grade, 1) self.assertEqual(la.get_grade(student.person, 'INST').grade, 'A') # flag==NOGR handling ng.flag = 'NOGR' ng.save(entered_by=instr) lg.flag = 'NOGR' lg.save(entered_by=instr) na.status = 'RLS' na.save(entered_by=instr) la.status = 'RLS' la.save(entered_by=instr) self.assertEqual(na.get_grade(student.person, 'STUD'), None) self.assertEqual(la.get_grade(student.person, 'STUD'), None) self.assertEqual(na.get_grade(student.person, 'INST'), None) self.assertEqual(la.get_grade(student.person, 'INST'), None)
def test_get_grade(self): """ Make sure activity.get_grade() keeps the right things hidden """ o = CourseOffering.objects.get(slug=self.course_slug) na = NumericActivity.objects.get(slug='a1') la = LetterActivity.objects.get(slug='rep') instr = Person.objects.get(userid='ggbaker') student = Member.objects.get(person__userid='0aaa0', offering=o) na.status = 'RLS' na.save(entered_by=instr) la.status = 'RLS' la.save(entered_by=instr) # no grades yet self.assertEqual(na.get_grade(student.person, 'STUD'), None) self.assertEqual(la.get_grade(student.person, 'STUD'), None) self.assertEqual(na.get_grade(student.person, 'INST'), None) self.assertEqual(la.get_grade(student.person, 'INST'), None) # grades should be visible ng = NumericGrade(activity=na, member=student, value=1, flag='GRAD', comment='Foo') ng.save(entered_by=instr) lg = LetterGrade(activity=la, member=student, letter_grade='A', flag='GRAD', comment='Foo') lg.save(entered_by=instr) self.assertEqual(na.get_grade(student.person, 'STUD').grade, 1) self.assertEqual(la.get_grade(student.person, 'STUD').grade, 'A') self.assertEqual(na.get_grade(student.person, 'INST').grade, 1) self.assertEqual(la.get_grade(student.person, 'INST').grade, 'A') # unreleased: grades visible only to staff na.status = 'URLS' na.save(entered_by=instr) la.status = 'URLS' la.save(entered_by=instr) self.assertEqual(na.get_grade(student.person, 'STUD'), None) self.assertEqual(la.get_grade(student.person, 'STUD'), None) self.assertEqual(na.get_grade(student.person, 'INST').grade, 1) self.assertEqual(la.get_grade(student.person, 'INST').grade, 'A') # student shouldn't ever see invisible grade na.status = 'INVI' na.save(entered_by=instr) la.status = 'INVI' la.save(entered_by=instr) with self.assertRaises(RuntimeError): na.get_grade(student.person, 'STUD') with self.assertRaises(RuntimeError): la.get_grade(student.person, 'STUD') self.assertEqual(na.get_grade(student.person, 'INST').grade, 1) self.assertEqual(la.get_grade(student.person, 'INST').grade, 'A') # flag==NOGR handling ng.flag = 'NOGR' ng.save(entered_by=instr) lg.flag = 'NOGR' lg.save(entered_by=instr) na.status = 'RLS' na.save(entered_by=instr) la.status = 'RLS' la.save(entered_by=instr) self.assertEqual(na.get_grade(student.person, 'STUD'), None) self.assertEqual(la.get_grade(student.person, 'STUD'), None) self.assertEqual(na.get_grade(student.person, 'INST'), None) self.assertEqual(la.get_grade(student.person, 'INST'), None)