Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
def uploads(CID):
  auth       = AuthorizedUser()
  user_name  = auth.get_username()
  file = request.files['file']
  getUploads  = GetUploads(file)
  try:
    upload_path     = getUploads.get_upload_path()
    #course_path is the map of where the syllabus should be in the upload folder
    course_path     = getUploads.get_course_path(CID)
    directory_path  = upload_path + course_path
    #Make sure that the directories exist and creates it if it doesn't
    result = getUploads.check_path_exist(directory_path)
    #Now we rename the file to our create standard
    instructors_string = databaseInterface.get_course_instructors(CID)
    new_file_name   = getUploads.create_filename(CID, instructors_string)
    complete_path   = (directory_path + new_file_name).replace(" ","")
    #Save the File
    file.save(complete_path)
    if os.path.exists(complete_path):
    	#Now we need to course_path with its new file name to the database
    	database_path = (course_path+new_file_name).replace(" ","")
    	update_course_path = Courses.update(filePath=database_path).where(Courses.CID==CID)
    	update_course_path.execute()
    	#Now we need to log the changes
    	get_time = datetime.datetime.now()
    	time_stamp = get_time.strftime("%Y-%m-%d %I:%M")
    	last_modified_message = "Uploaded By {0} On {1}".format(user_name,str(time_stamp))
    	# log in our log file
    	message = "Uploads: {0} has been {1}".format(new_file_name, last_modified_message)
    	page = "/uploads/{0}".format(CID)
    	log.writer("INFO", page, message)
    	#update the database to inform the users who uploaded the file
    	update_last_modified  = Courses.update(lastModified=last_modified_message).where(Courses.CID==CID)
    	update_last_modified.execute()
    	return redirect(url_for("courses"))
    else:
 	return render_template("error.html",
                               cfg     = cfg,
                               message = "An error occured during the upload process.")  
  except Exception as e:
    app.logger.info("{0}".format(e))
    return render_template("error.html",
                          cfg                   = cfg,
                          message               = "An error occured during the upload process."
                        )