def apply_formula(self, grades, formula, lecture_students, grading, varsForExam, error_msgs): if formula: parser = Parser() try: parser.parseString(formula) for ls in lecture_students: d = {} for exam in grading.exams: result = grades[ls.student_id]['exams'][ exam.id]['points'] if result == '': result = None d[varsForExam[exam.id]] = result result = parser.calculate(d) grades[ls.student_id][ 'calc'] = result if result != None else '' if 'fill' in self.request.GET: grades[ls.student_id][ 'gradestr'] = result if result != None else '' except Exception as err: error_msgs.append(str(err)) if 'fill' in self.request.GET: self.request.session.flash( 'Achtung, die Noten sind noch nicht abgespeichert!', queue='errors') return grades, error_msgs
def __call__(self): grading = self.request.context.grading formula = self.request.GET.get('formula', None) if formula: grading.formula = formula self.db.commit() else: formula = grading.formula exam_id = self.request.GET.get('students', None) if exam_id: exam = self.request.db.query(models.Exam).get(exam_id) else: exam=None student_id = self.request.GET.get('student', None) lecture_students = grading.lecture.lecture_students_for_tutorials([])\ .options(sqlalchemy.orm.joinedload(models.LectureStudent.student)) if student_id: lecture_students = lecture_students.filter(models.LectureStudent.student_id == student_id) if exam: lecture_students = lecture_students\ .join(models.ExerciseStudent, models.LectureStudent.student_id==models.ExerciseStudent.student_id)\ .join(models.Exercise)\ .join(models.Exam)\ .filter(models.Exam.id==exam_id) lecture_students = lecture_students.all() gradesQuery = grading.student_grades.filter(models.StudentGrade.student_id.in_([ls.student_id for ls in lecture_students])) grades = utils.autovivify() exam_ids = [e.id for e in grading.exams] examvars = dict([['$%i' % i, e.id] for i,e in enumerate(grading.exams)]) varsForExam = dict([[examvars[var], var] for var in examvars ]) for ls in lecture_students: grades[ls.student_id]['grade'] = '' grades[ls.student_id]['gradestr'] = '' grades[ls.student_id]['invalid'] = None grades[ls.student_id]['exams'] = dict([[i, {'points': '', 'admission': None, 'registration': None, 'medical_certificate': None}] for i in exam_ids]) grades[ls.student_id]['calc'] = '' for grade in gradesQuery: grades[grade.student_id]['grade'] = grade grades[grade.student_id]['gradestr'] = grade.grade #for ls in lecture_students: # if not grades[ls.student_id]['grade']: # studentGrade = models.StudentGrade() # studentGrade.student = ls.student # studentGrade.grading = grading # grades[ls.student_id]['grade'] = studentGrade # self.db.add(studentGrade) if self.request.method == 'POST': for ls in lecture_students: param = 'grade-%u' % (ls.student_id) if param in self.request.POST: value = self.request.POST[param] if not grades[ls.student_id]['grade']: studentGrade = models.StudentGrade() studentGrade.student = ls.student studentGrade.grading = grading grades[ls.student_id]['grade'] = studentGrade self.db.add(studentGrade) if not value: grades[ls.student_id]['grade'].grade = None grades[ls.student_id]['gradestr'] = '' else: value = value.replace(',','.') try: value = float(value) grades[ls.student_id]['grade'].grade = value grades[ls.student_id]['gradestr'] = value except: error_msgs.append('Could not convert "%s" (%s)'%(value, ls.student.name())) if self.db.new or self.db.dirty or self.db.deleted: self.db.commit() for exam in grading.exams: results = exam.getResults(students = lecture_students) for result in results: grades[result.student_id]['exams'][exam.id]['points'] = result.points if exam.admission!=None or exam.registration!=None or exam.medical_certificate!=None: student_ids = [ls.student_id for ls in lecture_students] admissions = exam.exam_admissions for a in admissions: if a.student_id in student_ids: if exam.admission!=None: grades[a.student_id]['exams'][exam.id]['admission'] = a.admission if exam.registration!=None: grades[a.student_id]['exams'][exam.id]['registration'] = a.registration if exam.medical_certificate!=None: grades[a.student_id]['exams'][exam.id]['medical_certificate'] = a.medical_certificate error_msgs = [] if formula: parser = Parser() try: parser.parseString(formula) for ls in lecture_students: #print(student) d = {} for exam in grading.exams: result = grades[ls.student_id]['exams'][exam.id]['points'] if result == '': result = None d[varsForExam[exam.id]] = result result = parser.calculate(d) grades[ls.student_id]['calc'] = result if result != None else '' if 'fill' in self.request.GET: grades[ls.student_id]['gradestr'] = result if result != None else '' except Exception as err: error_msgs.append(str(err)) if 'fill' in self.request.GET: self.request.session.flash('Achtung, die Noten sind noch nicht abgespeichert!', queue='errors') #self.request.javascript.append('prototype.js') self.request.javascript.append('jquery/jquery.min.js') self.request.javascript.append('jquery/jquery.fancybox.min.js') #grades = {key: value for key,value in grades.items()} return {'grading': grading, 'error_msg': '\n'.join(error_msgs), 'formula': formula, 'exam_id': exam_id, 'tutorial_ids': '', 'grades': grades, 'examvars': examvars, 'varsForExam': varsForExam, 'lecture_students': lecture_students}
def setUp(self): self.parser = Parser()
class ContextTests(unittest.TestCase): def setUp(self): self.parser = Parser() def test_parser_add(self): self.parser.parseString('1+2') self.assertEqual(self.parser.calculate({}), 3) self.parser.parseString('$0+$1') self.assertEqual(self.parser.calculate({'$0': 1, '$1': 2}), 3) #Addition should handle None=0 self.assertEqual(self.parser.calculate({'$0': 1, '$1': None}), 1) #Unless everything is None self.assertEqual(self.parser.calculate({'$0': None, '$1': None}), None) def test_parser_mul(self): self.parser.parseString('2*3') self.assertEqual(self.parser.calculate({}), 6) self.parser.parseString('$0*$1') self.assertEqual(self.parser.calculate({'$0': 2, '$1': 3}), 6) #Addition should handle None=0 self.assertEqual(self.parser.calculate({'$0': 1, '$1': None}), None) #Unless everything is None self.assertEqual(self.parser.calculate({'$0': None, '$1': None}), None) def test_parser_cases(self): self.parser.parseString('cases($0, 0, 1, 1)') self.assertEqual(self.parser.calculate({'$0': 0}), 0) self.assertEqual(self.parser.calculate({'$0': d(0.5)}), 0) self.assertEqual(self.parser.calculate({'$0': 1}), 1) self.assertEqual(self.parser.calculate({'$0': d(1.5)}), 1) self.assertEqual(self.parser.calculate({'$0': None}), None) self.parser.parseString('cases($0,5,14,4,19,3,24.5,2,29,1)') self.assertEqual(self.parser.calculate({'$0': 21}), 3) def test_parser_cases1(self): self.parser.parseString('cases1($0, 2, 4, 6, 8)') self.assertEqual(self.parser.calculate({'$0': 0}), 5) self.assertEqual(self.parser.calculate({'$0': d(1.5)}), 5) self.assertEqual(self.parser.calculate({'$0': 2}), 4) self.assertEqual(self.parser.calculate({'$0': 4}), 3) self.assertEqual(self.parser.calculate({'$0': 6}), 2) self.assertEqual(self.parser.calculate({'$0': 8}), 1) self.assertEqual(self.parser.calculate({'$0': None}), None) def test_parser_cases3(self): self.parser.parseString('cases3($0,30,34,38,42,46,50,54,58,62,66)') self.assertEqual(self.parser.calculate({'$0': 0}), 5) self.assertEqual(self.parser.calculate({'$0': 7}), 5) def test_parser_cases333(self): self.parser.parseString('cases333($0,30,34,38,42,46,50,54,58,62,66)') self.assertEqual(self.parser.calculate({'$0': 0}), 5) self.assertEqual(self.parser.calculate({'$0': 7}), 5) self.assertAlmostEqual(self.parser.calculate({'$0': 34}), d(11.0/3)) def test_parser_min(self): self.parser.parseString('min($0)') self.assertEqual(self.parser.calculate({'$0': 0}), 0) self.assertEqual(self.parser.calculate({'$0': 1}), 1) self.assertEqual(self.parser.calculate({'$0': None}), None) self.parser.parseString('min($0, $1)') self.assertEqual(self.parser.calculate({'$0': 0, '$1': 1}), 0) self.assertEqual(self.parser.calculate({'$0': 1, '$1': 0}), 0) self.assertEqual(self.parser.calculate({'$0': None, '$1': 1}), 1) self.assertEqual(self.parser.calculate({'$0': None, '$1': None}), None) def test_parser_round3down(self): self.parser.parseString('round3down($0)') self.assertEqual(self.parser.calculate({'$0': 5}), 5) self.assertEqual(self.parser.calculate({'$0': d(4.1)}), 5) self.assertEqual(self.parser.calculate({'$0': d(4.0)}), 4) self.assertEqual(self.parser.calculate({'$0': d(1.32)}), 1) self.assertEqual(self.parser.calculate({'$0': d(1.33)}), 1) self.assertEqual(self.parser.calculate({'$0': d(1.34)}), d(1.3)) self.assertEqual(self.parser.calculate({'$0': None}), None) #0.3 to next step for step in [1.0, 2.0, 3.0]: self.assertEqual(self.parser.calculate({'$0': d(step)}), d(step)) self.assertEqual(self.parser.calculate({'$0': d(step+0.1)}), d(step)) self.assertEqual(self.parser.calculate({'$0': d(step+0.32)}), d(step)) #0.3 to next step for step in [1.3, 2.3, 3.3]: self.assertAlmostEqual(self.parser.calculate({'$0': d(step)}), d(step-0.3)) self.assertAlmostEqual(self.parser.calculate({'$0': d(step+0.033)}), d(step-0.3)) self.assertEqual(self.parser.calculate({'$0': d(step+0.034)}), d(step)) self.assertEqual(self.parser.calculate({'$0': d(step+0.365)}), d(step)) #0.4 to next step for step in [1.7, 2.7, 3.7]: self.assertEqual(self.parser.calculate({'$0': d(step)}), d(step)) self.assertEqual(self.parser.calculate({'$0': d(step-0.03)}), d(step)) self.assertAlmostEqual(self.parser.calculate({'$0': d(step-0.04)}), d(step-0.4)) self.assertEqual(self.parser.calculate({'$0': d(step+0.1)}), d(step)) self.assertEqual(self.parser.calculate({'$0': d(step+0.29)}), d(step)) def test_parser_schmidtsche_weltformel(self): for weltformel in ['cases3(-1*$0-2*$1,-36,-35,-32,-29,-26,-23,-20,-17,-14,-11)', 'round3down(($0+2*$1)/9)']: self.parser.parseString(weltformel) #Trivialitäten sind auch wichtig self.assertEqual(self.parser.calculate({'$0': d(15), '$1': d(15)}), 5) self.assertEqual(self.parser.calculate({'$0': d(12), '$1': d(12)}), 4) self.assertEqual(self.parser.calculate({'$0': d(11), '$1': d(11)}), d(3.7)) self.assertEqual(self.parser.calculate({'$0': d(10), '$1': d(10)}), d(3.3)) self.assertEqual(self.parser.calculate({'$0': d(9), '$1': d(9)}), 3) self.assertEqual(self.parser.calculate({'$0': d(8), '$1': d(8)}), d(2.7)) self.assertEqual(self.parser.calculate({'$0': d(7), '$1': d(7)}), d(2.3)) self.assertEqual(self.parser.calculate({'$0': d(6), '$1': d(6)}), d(2.0)) self.assertEqual(self.parser.calculate({'$0': d(5), '$1': d(5)}), d(1.7)) self.assertEqual(self.parser.calculate({'$0': d(4), '$1': d(4)}), d(1.3)) self.assertEqual(self.parser.calculate({'$0': d(3), '$1': d(3)}), d(1.0)) #MC 5 AT 4: gewichtetes Mittel: 1/3 * (5 + 2*4)= 4 1/3: nicht bestanden 5 self.assertEqual(self.parser.calculate({'$0': d(5*3), '$1': d(4*3)}), 5) #MC 2,0 AT 5: gewichtetes Mittel 4 bestanden mit Note 4 self.assertEqual(self.parser.calculate({'$0': d(2*3), '$1': d(5*3)}), 4) #MC 1, AT 3 gewichtetes Mittel 2 1/3 = bestanden mit Note 2,3 self.assertEqual(self.parser.calculate({'$0': d(1*3), '$1': d(3*3)}), d(2.3)) #MC 2, AT 3 gewichtetes Mittel 2 2/3 = bestanden mit Note 2,7 self.assertEqual(self.parser.calculate({'$0': d(2*3), '$1': d(3*3)}), d(2.7)) #MC 3 1/3, AT 3: gewichtetes Mittel 3,1... gerundet auf Gesamtnote 3.0 self.assertEqual(self.parser.calculate({'$0': d(10), '$1': d(3*3)}), 3) #MC 3, AT 3 1/3: gewichtetes Mittel 3,2... gerundet auf Gesamtnote 3.0 self.assertEqual(self.parser.calculate({'$0': d(3*3), '$1': d(10)}), 3) #MC 2, AT 2 2/3: gewichtetes Mittel 2,4... gerundet auf Gesamtnote 2,3 self.assertEqual(self.parser.calculate({'$0': d(2*3), '$1': d(8)}), d(2.3)) #MC 1 1/3, AT 1: gewichtetes Mittel 1,1... gerundet auf Gesamtnote 1,0 self.assertEqual(self.parser.calculate({'$0': d(4), '$1': d(1*3)}), 1)
class ContextTests(unittest.TestCase): def setUp(self): self.parser = Parser() def test_parser_add(self): self.parser.parseString("1+2") self.assertEqual(self.parser.calculate({}), 3) self.parser.parseString("$0+$1") self.assertEqual(self.parser.calculate({"$0": 1, "$1": 2}), 3) # Addition should handle None=0 self.assertEqual(self.parser.calculate({"$0": 1, "$1": None}), 1) # Unless everything is None self.assertEqual(self.parser.calculate({"$0": None, "$1": None}), None) def test_parser_mul(self): self.parser.parseString("2*3") self.assertEqual(self.parser.calculate({}), 6) self.parser.parseString("$0*$1") self.assertEqual(self.parser.calculate({"$0": 2, "$1": 3}), 6) # Addition should handle None=0 self.assertEqual(self.parser.calculate({"$0": 1, "$1": None}), None) # Unless everything is None self.assertEqual(self.parser.calculate({"$0": None, "$1": None}), None) def test_parser_cases(self): self.parser.parseString("cases($0, 0, 1, 1)") self.assertEqual(self.parser.calculate({"$0": 0}), 0) self.assertEqual(self.parser.calculate({"$0": d(0.5)}), 0) self.assertEqual(self.parser.calculate({"$0": 1}), 1) self.assertEqual(self.parser.calculate({"$0": d(1.5)}), 1) self.assertEqual(self.parser.calculate({"$0": None}), None) self.parser.parseString("cases($0,5,14,4,19,3,24.5,2,29,1)") self.assertEqual(self.parser.calculate({"$0": 21}), 3) def test_parser_cases1(self): self.parser.parseString("cases1($0, 2, 4, 6, 8)") self.assertEqual(self.parser.calculate({"$0": 0}), 5) self.assertEqual(self.parser.calculate({"$0": d(1.5)}), 5) self.assertEqual(self.parser.calculate({"$0": 2}), 4) self.assertEqual(self.parser.calculate({"$0": 4}), 3) self.assertEqual(self.parser.calculate({"$0": 6}), 2) self.assertEqual(self.parser.calculate({"$0": 8}), 1) self.assertEqual(self.parser.calculate({"$0": None}), None) def test_parser_cases3(self): self.parser.parseString("cases3($0,30,34,38,42,46,50,54,58,62,66)") self.assertEqual(self.parser.calculate({"$0": 0}), 5) self.assertEqual(self.parser.calculate({"$0": 7}), 5) def test_parser_cases333(self): self.parser.parseString("cases333($0,30,34,38,42,46,50,54,58,62,66)") self.assertEqual(self.parser.calculate({"$0": 0}), 5) self.assertEqual(self.parser.calculate({"$0": 7}), 5) self.assertAlmostEqual(self.parser.calculate({"$0": 34}), d(11.0 / 3)) def test_parser_min(self): self.parser.parseString("min($0)") self.assertEqual(self.parser.calculate({"$0": 0}), 0) self.assertEqual(self.parser.calculate({"$0": 1}), 1) self.assertEqual(self.parser.calculate({"$0": None}), None) self.parser.parseString("min($0, $1)") self.assertEqual(self.parser.calculate({"$0": 0, "$1": 1}), 0) self.assertEqual(self.parser.calculate({"$0": 1, "$1": 0}), 0) self.assertEqual(self.parser.calculate({"$0": None, "$1": 1}), 1) self.assertEqual(self.parser.calculate({"$0": None, "$1": None}), None) def test_parser_round3down(self): self.parser.parseString("round3down($0)") self.assertEqual(self.parser.calculate({"$0": 5}), 5) self.assertEqual(self.parser.calculate({"$0": d(4.1)}), 5) self.assertEqual(self.parser.calculate({"$0": d(4.0)}), 4) self.assertEqual(self.parser.calculate({"$0": d(1.32)}), 1) self.assertEqual(self.parser.calculate({"$0": d(1.33)}), 1) self.assertEqual(self.parser.calculate({"$0": d(1.34)}), d(1.3)) self.assertEqual(self.parser.calculate({"$0": None}), None) # 0.3 to next step for step in [1.0, 2.0, 3.0]: self.assertEqual(self.parser.calculate({"$0": d(step)}), d(step)) self.assertEqual(self.parser.calculate({"$0": d(step + 0.1)}), d(step)) self.assertEqual(self.parser.calculate({"$0": d(step + 0.32)}), d(step)) # 0.3 to next step for step in [1.3, 2.3, 3.3]: self.assertAlmostEqual(self.parser.calculate({"$0": d(step)}), d(step - 0.3)) self.assertAlmostEqual(self.parser.calculate({"$0": d(step + 0.033)}), d(step - 0.3)) self.assertEqual(self.parser.calculate({"$0": d(step + 0.034)}), d(step)) self.assertEqual(self.parser.calculate({"$0": d(step + 0.365)}), d(step)) # 0.4 to next step for step in [1.7, 2.7, 3.7]: self.assertEqual(self.parser.calculate({"$0": d(step)}), d(step)) self.assertEqual(self.parser.calculate({"$0": d(step - 0.03)}), d(step)) self.assertAlmostEqual(self.parser.calculate({"$0": d(step - 0.04)}), d(step - 0.4)) self.assertEqual(self.parser.calculate({"$0": d(step + 0.1)}), d(step)) self.assertEqual(self.parser.calculate({"$0": d(step + 0.29)}), d(step)) def test_parser_schmidtsche_weltformel(self): for weltformel in ["cases3(-1*$0-2*$1,-36,-35,-32,-29,-26,-23,-20,-17,-14,-11)", "round3down(($0+2*$1)/9)"]: self.parser.parseString(weltformel) # Trivialitäten sind auch wichtig self.assertEqual(self.parser.calculate({"$0": d(15), "$1": d(15)}), 5) self.assertEqual(self.parser.calculate({"$0": d(12), "$1": d(12)}), 4) self.assertEqual(self.parser.calculate({"$0": d(11), "$1": d(11)}), d(3.7)) self.assertEqual(self.parser.calculate({"$0": d(10), "$1": d(10)}), d(3.3)) self.assertEqual(self.parser.calculate({"$0": d(9), "$1": d(9)}), 3) self.assertEqual(self.parser.calculate({"$0": d(8), "$1": d(8)}), d(2.7)) self.assertEqual(self.parser.calculate({"$0": d(7), "$1": d(7)}), d(2.3)) self.assertEqual(self.parser.calculate({"$0": d(6), "$1": d(6)}), d(2.0)) self.assertEqual(self.parser.calculate({"$0": d(5), "$1": d(5)}), d(1.7)) self.assertEqual(self.parser.calculate({"$0": d(4), "$1": d(4)}), d(1.3)) self.assertEqual(self.parser.calculate({"$0": d(3), "$1": d(3)}), d(1.0)) # MC 5 AT 4: gewichtetes Mittel: 1/3 * (5 + 2*4)= 4 1/3: nicht bestanden 5 self.assertEqual(self.parser.calculate({"$0": d(5 * 3), "$1": d(4 * 3)}), 5) # MC 2,0 AT 5: gewichtetes Mittel 4 bestanden mit Note 4 self.assertEqual(self.parser.calculate({"$0": d(2 * 3), "$1": d(5 * 3)}), 4) # MC 1, AT 3 gewichtetes Mittel 2 1/3 = bestanden mit Note 2,3 self.assertEqual(self.parser.calculate({"$0": d(1 * 3), "$1": d(3 * 3)}), d(2.3)) # MC 2, AT 3 gewichtetes Mittel 2 2/3 = bestanden mit Note 2,7 self.assertEqual(self.parser.calculate({"$0": d(2 * 3), "$1": d(3 * 3)}), d(2.7)) # MC 3 1/3, AT 3: gewichtetes Mittel 3,1... gerundet auf Gesamtnote 3.0 self.assertEqual(self.parser.calculate({"$0": d(10), "$1": d(3 * 3)}), 3) # MC 3, AT 3 1/3: gewichtetes Mittel 3,2... gerundet auf Gesamtnote 3.0 self.assertEqual(self.parser.calculate({"$0": d(3 * 3), "$1": d(10)}), 3) # MC 2, AT 2 2/3: gewichtetes Mittel 2,4... gerundet auf Gesamtnote 2,3 self.assertEqual(self.parser.calculate({"$0": d(2 * 3), "$1": d(8)}), d(2.3)) # MC 1 1/3, AT 1: gewichtetes Mittel 1,1... gerundet auf Gesamtnote 1,0 self.assertEqual(self.parser.calculate({"$0": d(4), "$1": d(1 * 3)}), 1)
def __call__(self): grading = self.request.context.grading formula = self.request.GET.get('formula', None) if formula: grading.formula = formula self.db.commit() else: formula = grading.formula exam_id = self.request.GET.get('students', None) if exam_id: exam = self.request.db.query(models.Exam).get(exam_id) else: exam = None student_id = self.request.GET.get('student', None) lecture_students = grading.lecture.lecture_students_for_tutorials([])\ .options(sqlalchemy.orm.joinedload(models.LectureStudent.student)) if student_id: lecture_students = lecture_students.filter( models.LectureStudent.student_id == student_id) if exam: lecture_students = lecture_students\ .join(models.ExerciseStudent, models.LectureStudent.student_id==models.ExerciseStudent.student_id)\ .join(models.Exercise)\ .join(models.Exam)\ .filter(models.Exam.id==exam_id) lecture_students = lecture_students.all() gradesQuery = grading.student_grades.filter( models.StudentGrade.student_id.in_( [ls.student_id for ls in lecture_students])) grades = utils.autovivify() exam_ids = [e.id for e in grading.exams] examvars = dict([['$%i' % i, e.id] for i, e in enumerate(grading.exams)]) varsForExam = dict([[examvars[var], var] for var in examvars]) for ls in lecture_students: grades[ls.student_id]['grade'] = '' grades[ls.student_id]['gradestr'] = '' grades[ls.student_id]['invalid'] = None grades[ls.student_id]['exams'] = dict([[ i, { 'points': '', 'admission': None, 'registration': None, 'medical_certificate': None } ] for i in exam_ids]) grades[ls.student_id]['calc'] = '' for grade in gradesQuery: grades[grade.student_id]['grade'] = grade grades[grade.student_id]['gradestr'] = grade.grade #for ls in lecture_students: # if not grades[ls.student_id]['grade']: # studentGrade = models.StudentGrade() # studentGrade.student = ls.student # studentGrade.grading = grading # grades[ls.student_id]['grade'] = studentGrade # self.db.add(studentGrade) if self.request.method == 'POST': for ls in lecture_students: param = 'grade-%u' % (ls.student_id) if param in self.request.POST: value = self.request.POST[param] if not grades[ls.student_id]['grade']: studentGrade = models.StudentGrade() studentGrade.student = ls.student studentGrade.grading = grading grades[ls.student_id]['grade'] = studentGrade self.db.add(studentGrade) if not value: grades[ls.student_id]['grade'].grade = None grades[ls.student_id]['gradestr'] = '' else: value = value.replace(',', '.') try: value = float(value) grades[ls.student_id]['grade'].grade = value grades[ls.student_id]['gradestr'] = value except: error_msgs.append('Could not convert "%s" (%s)' % (value, ls.student.name())) if self.db.new or self.db.dirty or self.db.deleted: self.db.commit() for exam in grading.exams: results = exam.getResults(students=lecture_students) for result in results: grades[result.student_id]['exams'][ exam.id]['points'] = result.points if exam.admission != None or exam.registration != None or exam.medical_certificate != None: student_ids = [ls.student_id for ls in lecture_students] admissions = exam.exam_admissions for a in admissions: if a.student_id in student_ids: if exam.admission != None: grades[a.student_id]['exams'][ exam.id]['admission'] = a.admission if exam.registration != None: grades[a.student_id]['exams'][ exam.id]['registration'] = a.registration if exam.medical_certificate != None: grades[a.student_id]['exams'][exam.id][ 'medical_certificate'] = a.medical_certificate error_msgs = [] if formula: parser = Parser() try: parser.parseString(formula) for ls in lecture_students: #print(student) d = {} for exam in grading.exams: result = grades[ls.student_id]['exams'][ exam.id]['points'] if result == '': result = None d[varsForExam[exam.id]] = result result = parser.calculate(d) grades[ls.student_id][ 'calc'] = result if result != None else '' if 'fill' in self.request.GET: grades[ls.student_id][ 'gradestr'] = result if result != None else '' except Exception as err: error_msgs.append(str(err)) if 'fill' in self.request.GET: self.request.session.flash( 'Achtung, die Noten sind noch nicht abgespeichert!', queue='errors') #self.request.javascript.append('prototype.js') self.request.javascript.append('jquery/jquery.min.js') self.request.javascript.append('jquery/jquery.fancybox.min.js') #grades = {key: value for key,value in grades.items()} return { 'grading': grading, 'error_msg': '\n'.join(error_msgs), 'formula': formula, 'exam_id': exam_id, 'tutorial_ids': '', 'grades': grades, 'examvars': examvars, 'varsForExam': varsForExam, 'lecture_students': lecture_students }