Example #1
0
def get_path(filename, problem_location):
    shared.ensure_directory_exists(ANSWERS_DISTRIBUTION_REPORTS_DIRECTORY,
                                   problem_location.org, problem_location.course)
    path = shared.get_safe_file_path(ANSWERS_DISTRIBUTION_REPORTS_DIRECTORY,
                                     problem_location.org, problem_location.course,
                                     filename)
    return path
Example #2
0
def get_path(filename, problem_location):
    shared.ensure_directory_exists(ANSWERS_DISTRIBUTION_REPORTS_DIRECTORY,
                                   problem_location.org,
                                   problem_location.course)
    path = shared.get_safe_file_path(ANSWERS_DISTRIBUTION_REPORTS_DIRECTORY,
                                     problem_location.org,
                                     problem_location.course, filename)
    return path
Example #3
0
def write_csv(header_row, data_rows, filename, course_id):
    """write a CSV file from the contents of a datatable."""
    shared.ensure_directory_exists(utils.ANSWERS_DISTRIBUTION_REPORTS_DIRECTORY,
                                   course_id.org, course_id.course)


    path = shared.get_safe_file_path(utils.ANSWERS_DISTRIBUTION_REPORTS_DIRECTORY,
                                course_id.org, course_id.course,
                                filename)
    ## need to encode the unico path in order to open the file in prod env
    path = path.encode('utf-8')

    with open(path, "wb") as ofile:
        writer = csv.writer(ofile, quoting=csv.QUOTE_ALL)
        writer.writerow(header_row)
        for datarow in data_rows:
            encoded_row = [cleanup_newlines(unicode(s).encode('utf-8'))
                           for s in datarow]
            writer.writerow(encoded_row)
Example #4
0
 def test_get_safe_path(self):
     _path = shared.get_safe_file_path("dir1", "dir2", "myfile")
     self.assertTrue(os.path.isdir(settings.SHARED_ROOT + "/dir1/dir2"))