def imported_htmldata(request, data_file): proj = current_project(request) log_path = Path(SITE.RAW_DATA_DIR, proj.proposal, data_file) if not log_path.is_file(): return HttpResponseNotFound() return HttpResponse(read_proj_file(proj, log_path))
def htmldata(request, data_file): project = current_project(request) log_path = Path(project.project_dir, data_file) if not log_path.is_file(): return HttpResponseNotFound() return HttpResponse(read_proj_file(project, log_path))
def test_read_proj_file(self): """ test read_proj_file() on un-encrypted project """ # write test file _write_file(self.file_path) # check that plaintext file is read correctly data = read_proj_file(self.proj, self.file_path) self.assertEqual(data, DUMMY_DATA)
def download(request, log_file): project = current_project(request) log_path = Path(project.project_dir, log_file) if not log_path.is_file(): return _log_not_found_resp(log_file) return HttpResponse( read_proj_file(project, log_path), content_type="application/octet-stream", )
def test_read_proj_file(self): """ test open_proj_file() on encrypted project """ # write test file with encryption.EncryptedFile(self.project.encryption_key, self.file_path) as f: f.write(DUMMY_DATA) # check that encrypted file is decrypted correctly data = read_proj_file(self.project, self.file_path) self.assertEqual(data, DUMMY_DATA)
def binary_http_response(proj, file_path, content_type): return HttpResponse(read_proj_file(proj, file_path), content_type=content_type)
def _file_data(proj, file_path): yield read_proj_file(proj, file_path)