def studentAPI(): username = request.form.get('username') password = request.form.get('password') user = User(username) # check if user actually exists # take the user supplied password, hash it, and compare it to the hashed password in database if check_password_hash(user.password, password): if user.isStudent(): sID = user.getId() classIDs = Backend.getStudentClasses(sID) classes = [] for cID in classIDs: classes.append( { "Name": Backend.getClassName(cID), "Time": Backend.getClassTimes(cID), "Location": Backend.getClassLocations(cID), "ClassID": cID, "Teacher": Backend.getName(Backend.getClassTeacher(cID)), "FinalGrade": Backend.getFinalGrade(cID, sID) } ) output = { "Name": Backend.getName(sID), "Classes": classes } return json.dumps(output)
def classHomepageTeacher(): cID = int(request.args.get("classID")) if Backend.checkTeacherHasClass(current_user.id, cID): assignments = [] for assignmentID in Backend.getClassAssignments(cID): assignments.append( Backend.getAssignmentInfo(assignmentID) ) students = [] grades= [] for studentID in Backend.getStudentsForClass(cID): grade = Backend.getFinalGrade(cID, studentID) students.append( { "StudentID":studentID, "StudentName": Backend.getName(studentID), "StudentGrade": grade if grade != -1 else "-" } ) if grade > -1: grades.append(grade) pageData = { "ClassID" : cID, "Name" : Backend.getClassName(cID), "Time" : Backend.getClassTimes(cID), "Location" : Backend.getClassLocations(cID), "Assignments" : assignments, "Announcements": Backend.getAnnouncementsForClass(cID), "Students": students } n = len(grades) if n > 1: pageData["Mean"] = str("%.3f" % mean(grades)) pageData["SD"] = str("%.3f" % stdev(grades)) pageData["Median"] = median(grades) else: pageData["Mean"] = "-" pageData["SD"] = "-" pageData["Median"] = "-" return render_template('classHomepageTeacher.html', pageData=pageData) else: return '', 403
def teacherHomepage(): classIDs = Backend.getTeacherClasses(current_user.id) classes = [] for cID in classIDs: classes.append( { "Name" : Backend.getClassName(cID), "Time" : Backend.getClassTimes(cID), "Location" : Backend.getClassLocations(cID), "ClassID" : cID } ) pageData = { "Classes" : classes } if current_user.attempts >= 3: pageData["attempts"] = current_user.attempts db.db.Logins.update({"ID": current_user.id}, {"$set": {"attempts": 0}}) return render_template('teacherHomepage.html', pageData=pageData)
def classHomepageStudent(): cID = int(request.args.get("classID")) if Backend.checkStudentHasClass(current_user.id, cID): assignments = [] for assignmentID in Backend.getClassAssignments(cID): assignments.append( Backend.getAssignmentInfo(assignmentID) ) pageData = { "ClassID" : cID, "Name" : Backend.getClassName(cID), "Time" : Backend.getClassTimes(cID), "Location" : Backend.getClassLocations(cID), "Assignments" : assignments, "Announcements": Backend.getAnnouncementsForClass(cID), "CurrentFinalGrade": Backend.getFinalGrade(cID, current_user.id) } return render_template('classHomepageStudent.html', pageData=pageData) else: return '', 403
def studentHomepage(): pageData = { } classIDs = Backend.getStudentClasses(current_user.id) classes = [] for cID in classIDs: classes.append( { "Name": Backend.getClassName(cID), "Time": Backend.getClassTimes(cID), "Location": Backend.getClassLocations(cID), "ClassID": cID, "Teacher": Backend.getName(Backend.getClassTeacher(cID)), "FinalGrade": Backend.getFinalGrade(cID, current_user.id) } ) pageData["Classes"] = classes if current_user.attempts >= 3: pageData["attempts"] = current_user.attempts db.db.Logins.update({"ID": current_user.id}, {"$set": {"attempts": 0}}) return render_template('studentHomepage.html', pageData=pageData)