def delete(CID): page = r"/" + request.url.split("/")[-1] auth = AuthorizedUser() user_name = auth.get_username() # if auth.user_level() == 'admin': try: #need to add app/ in the front to tell the os where to start looking #file_path = 'app/'+databaseInterface.get_course_file_path(CID) file_path = '/var/www/html/Syllus-flask/' + databaseInterface.get_course_file_path( CID) #Remove file from server os.remove(file_path) app.logger.info("File removed: {0}".format(file_path)) #Remove the file from the database delete_filePath = Courses.update(filePath=None).where( Courses.CID == CID) delete_filePath.execute() flash("Syllabus has been deleted") #RECORD THE CHANGE get_time = datetime.datetime.now() time_stamp = get_time.strftime("%Y-%m-%d %H:%M") last_modified_message = "Deleted By {} On {}".format( user_name, str(time_stamp)) message = "Uploads: {0} has been {1}".format(file_path, last_modified_message) log.writer('INFO', page, message) update_last_modified = Courses.update( lastModified=last_modified_message).where(Courses.CID == CID) update_last_modified.execute() return redirect(redirect_url()) except Exception, e: app.logger.info("{0} attempting to delete a syllabus.".format(str(e))) message = "An error occured during the delete process of the file." return render_template("error.html", cfg=cfg, message=message)
def deleteDeadline(): page = r"/" + request.url.split("/")[-1] authorizedUser = AuthorizedUser() if authorizedUser.isAdmin: data = request.form deadline = Deadline.get(Deadline.id == int(data['id'])) deadline.delete_instance() message = "Deadline: {0} has been deleted".format(deadline.description) log.writer("INFO", page, message) flash("Your Deadline has been deleted") return redirect(redirect_url()) else: abort(403)
def addSemester(): page = "/" + request.url.split("/")[-1] authorizedUser = AuthorizedUser() if authorizedUser.isAdmin: data = request.form #Class from logic folder system = GetSystemManagement() logList = system.add_semester(data) print logList #TODO: figure out how to log log.writer(logList[0], page, logList[1]) flash(logList[1]) return redirect(redirect_url()) else: abort(403)
def editAdmin(): username = authUser(request.environ) authorizedUser = AuthorizedUser() if authorizedUser.isAdmin: data = request.form key = 'admin[]' result = checkData(data, key) user = result[0] if user is not None: user.isAdmin = not user.isAdmin #Flip the boolean value user.save() #TODO: LOG HERE flash(result[1]) return redirect(redirect_url('systemManagement')) else: abort(403)
def deadlineEdit(): # we need the page for logging purpuses page = "/" + request.url.split("/")[-1] authorizedUser = AuthorizedUser() if authorizedUser.isAdmin: data = request.form deadline = Deadline.get(Deadline.id == data['id']) deadline.description = data['deadlineDescription'] deadline.save() message = "Deadline: has been edited to {0}".format( deadline.description) log.writer("INFO", page, message) flash("Your Deadline has been edited") return redirect(redirect_url()) else: abort(403)
def deadlineCreate(): # we need the page for loggin purposes page = "/" + request.url.split("/")[-1] # we need the user to know if they are is admin authorizedUser = AuthorizedUser() if authorizedUser.isAdmin: # data contains # deadlineDescription data = request.form date = datetime.datetime.strptime(data['deadlineDate'], "%m/%d/%Y").date() deadline = Deadline.create(description=data['deadlineDescription'], date=date) deadline.save() # log the messages message = "Deadline: {0} has been added".format(deadline.description) log.writer("INFO", page, message) flash("Your Deadline has been created") return redirect(redirect_url()) else: abort(403)
def editProgram(): authorizedUser = AuthorizedUser() if authorizedUser.isAdmin: # we need the page for loggin purposes page = "/" + request.url.split("/")[-1] data = request.form newChairs = request.form.getlist('professors[]') pid = data['PID'] # TODO: the loop is repeated a lot we should be able to take it out currentChairs = Users.select().where(Users.PID == pid) for currentChair in currentChairs: #IF A USER'S NAME IS NOT PART OF THE NEWCHAIR LIST THEN DELETE THEM if currentChair.username not in newChairs: message = "USER: {0} has been removed as a program chair for pid: {1}".format( currentChair.username, pid) log.writer("INFO", page, message) currentChair.PID = None currentChair.save() else: #HOWEVER IF THEY ARE PART OF THE LIST, DELETE THEM FROM THE LIST newChairs.remove(currentChair.username) #LOOK THROUGH THE NEW CHAIR LIST for user_name in newChairs: #ADD THE USERNAMES TO THE PROGRAM CHAIR LIST newChair = Users.get(Users.username == user_name) print newChair.username newChair.PID = pid newChair.save() message = "USER: {0} has been added as a program chair for pid: {1}".format( user_name, pid) log.writer("INFO", page, message) flash("Program succesfully changed") return redirect(redirect_url()) else: abort(403)
def editDivision(): authorizedUser = AuthorizedUser() if authorizedUser.isAdmin: # we need the page for logging purposes page = "/" + request.url.split("/")[-1] data = request.form newChairs = request.form.getlist('professors[]') did = data['DID'] #SELECT ALL OF THE CURRENT CHAIRS OF THE DIVISION currentChairs = Users.select().where(Users.DID == did) for currentChair in currentChairs: # we want to delete chairs that are not in the new list if currentChair.username not in newChairs: message = "USER: {0} has been removed as a Division chair for did: {1}".format( currentChair.username, did) log.writer("INFO", page, message) currentChair.DID = None currentChair.save() # we dont want to duplicate chairs else: newChairs.remove(currentChair.username) for user_name in newChairs: #ADD THE USERNAMES TO THE Division CHAIR LIST newChair = Users.get(Users.username == user_name) newChair.DID = did newChair.save() message = "USER: {0} has been added as a Division chair for did: {1}".format( user_name, did) log.writer("INFO", page, message) flash("Division succesfully changed") return redirect(redirect_url()) else: abort(403)