def submitGrades(): inputs = [None, None, None, None, None] for i in flask.request.form: print(i) try: inputs[0] = flask.request.form['classID'] studentIDs = flask.request.form.getlist('studentID') studentGrades = flask.request.form.getlist('grade') print(studentIDs) print(studentGrades) inputs[4] = flask.request.form['weight'] gradesList = [] for i in range(len(studentIDs)): toAppend = [None, None] #[userID, grade] try: toAppend[1] = int(studentGrades[i]) except: continue toAppend[0] = studentIDs[i] gradesList.append(toAppend) inputs[1] = gradesList inputs[2] = flask.request.form['assignment'] inputs[3] = int(flask.request.form['maxGrade']) except: flask.session.pop('_flashes', None) flask.flash("Invalid input(s).") return flask.redirect(flask.request.referrer) if 'userid' not in flask.session: return flask.redirect('/') if not db.isTeacher(flask.session['userid'], inputs[0]): return "User is not the teacher of this class." db.changeGrades(inputs[0], inputs[1], inputs[2], inputs[3], inputs[4]) flask.session.pop('_flashes', None) flask.flash("Grades Updated.") return flask.redirect('/class/' + str(inputs[0]))
def processMakePost(classID): if 'userid' not in flask.session: return flask.redirect('/') if not db.isTeacher(flask.session['userid'], classID): flask.flash("User is not the teacher of this class.") return flask.redirect(flask.request.referrer) postTitle = flask.request.form['postTitle'] postbody = flask.request.form['postbody'] postbody = postbody.replace('<br>', ' ') #Replace new lines with a space postbody = postbody.replace( '<div>', ' ') #Same as above, used for compatability among browsers postbody = postbody.replace('</div>', '') duedate = None dueCheck = False duetime = None submittable = flask.request.form.get('submittable') due = None if 'setDueDate' in flask.request.form: dueCheck = True if dueCheck: #Will insert a due date if the checkbox is checked duedate = flask.request.form['duedate'] duetime = flask.request.form['duetime'] due = duedate + " " + duetime if submittable == None: submittable = 0 else: submittable = 1 postID = db.makePost(classID, due, postbody, submittable, postTitle) #starttime = str(db.get_start_time(postID)) if dueCheck: event = { 'summary': postTitle, 'description': flask.request.form['postbody'], 'start': { 'date': str(datetime.date.today()), #'dateTime': '2019-01-10T09:00:00-07:00', 'timeZone': 'America/New_York', }, 'end': { 'date': duedate, #'dateTime': '2019-01-19T17:00:00-07:00', 'timeZone': 'America/New_York', } #'start.date': str(datetime.date.today()), #'end.date': str(duedate), } #json_event = json.loads(event) calID = db.getCalendarID(classID) credentials = google.oauth2.credentials.Credentials( **flask.session['credentials']) service = googleapiclient.discovery.build(API_SERVICE_NAME, API_VERSION, credentials=credentials) created_event = service.events().insert(calendarId=calID, body=event).execute() eventID = created_event['id'] db.addEvent(eventID, postID) return flask.redirect('/class/' + classID)
def makePost(classID): if 'userid' not in flask.session: return flask.redirect('/') if not db.isTeacher(flask.session['userid'], classID): # block students accessing teacher pages flask.flash("User is not the teacher of this class.") return flask.redirect(flask.request.referrer) date = str(datetime.date.today()) return flask.render_template("makepost.html", date=date, classID=classID)
def assignments(classID): if 'userid' not in flask.session: return flask.redirect('/') if not db.isTeacher(flask.session['userid'], classID): flask.flash("User is not the teacher of this class.") return flask.redirect(flask.request.referrer) assignmentList = db.getAssignments(classID) print(assignmentList) return flask.render_template('assignments.html', assignmentList=assignmentList)
def editClass(classID): if 'userid' not in flask.session: return flask.redirect('/') if not db.isTeacher(flask.session['userid'], classID): flask.flash("User is not the teacher of this class.") return flask.redirect(flask.request.referrer) classname = flask.request.form['classname'] desc = flask.request.form['desc'] db.editClass(classID, classname, desc) flask.session.pop('_flashes', None) flask.flash("Class updated") return flask.redirect('/class/' + str(classID))
def deleteClass(classID): if 'userid' not in flask.session: return flask.redirect('/') if not db.isTeacher(flask.session['userid'], classID): flask.flash("User is not the teacher of this class.") return flask.redirect(flask.request.referrer) calID = db.getCalendarID(classID) credentials = google.oauth2.credentials.Credentials( **flask.session['credentials']) service = googleapiclient.discovery.build(API_SERVICE_NAME, API_VERSION, credentials=credentials) service.calendars().delete(calendarId=calID).execute() db.deleteClass(classID) return flask.redirect('/login')
def userGrades(classID, userID): if 'userid' not in flask.session: return flask.redirect('/') if flask.session['userid'] != userID: if not db.isTeacher(flask.session['userid'], classID): return flask.redirect('/class/' + str(classID)) avg, weightavgs = db.calculateAverage(userID, classID) name = db.getUserName(userID) grades = db.getUserGrades(classID, userID) isTeacher = (db.getTeacher(classID) == flask.session["userid"]) return flask.render_template('usergrades.html', avg=avg, weightavgs=weightavgs, name=name, grades=grades, classID=classID, isTeacher=isTeacher)
def gradebook(classid, assignment): if 'userid' not in flask.session: return flask.redirect('/') classInfo = db.getClassInfo(classid) if not db.isTeacher(flask.session['userid'], classid): flask.flash("User is not the teacher of this class.") return flask.redirect(flask.request.referrer) classRoster = db.getRoster(classid) maxGrade, gradeDict = db.getAssignmentGrades(classid, assignment) print(gradeDict) return flask.render_template("gradebook.html", className=classInfo[0], assignment=assignment, roster=classRoster, gradeDict=gradeDict, getName=db.getUserName, classID=classid, maxGrade=maxGrade, weights=classInfo[3])
def classpage(classid): if 'userid' not in flask.session: return flask.redirect('/') if db.isTeacher(flask.session['userid'], classid): emails = db.getUnAdded(classid) if emails != None: for i in emails: print(i[0]) rule = { 'scope': { 'type': 'user', 'value': i[0], }, 'role': 'reader' } calID = db.getCalendarID(classid) credentials = google.oauth2.credentials.Credentials( **flask.session['credentials']) service = googleapiclient.discovery.build( API_SERVICE_NAME, API_VERSION, credentials=credentials) created_rule = service.acl().insert(calendarId=calID, body=rule).execute() else: print("not a teacher") calID = db.getCalendarID(classid) classInfo = db.getClassInfo(classid) classRoster = db.getRoster(classid) isTeacher = (db.getTeacher(classid) == flask.session["userid"]) posts = db.getPosts(classid) return flask.render_template("class.html", className=classInfo[0], teacherName=db.getUserName(classInfo[1]), inviteCode=classInfo[2], weights=classInfo[3], classRoster=classRoster, getName=db.getUserName, isTeacher=isTeacher, classID=classid, posts=posts[::-1], getPostFiles=db.getPostFiles, desc=classInfo[4], calendarID=calID)