From 2515dfb7100edf5aaeb0f1a1a1be1d034e39904e Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 11 Dec 2023 10:53:46 +0300 Subject: samples: Fix bugs in code saving samples to db * Check whether first row in file is for headings * Break infinite loop: check batch has content * Update saving of uploaded files --- qc_app/files.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'qc_app/files.py') diff --git a/qc_app/files.py b/qc_app/files.py index 6485b27..0304296 100644 --- a/qc_app/files.py +++ b/qc_app/files.py @@ -3,18 +3,16 @@ from pathlib import Path from typing import Union from werkzeug.utils import secure_filename -from flask import ( - request, - current_app as app) +from werkzeug.datastructures import FileStorage -def save_file(key: str, upload_dir: Path) -> Union[Path, bool]: +def save_file(fileobj: FileStorage, upload_dir: Path) -> Union[Path, bool]: """Save the uploaded file and return the path.""" - if not bool(request.files.get(key)): + if not bool(fileobj): return False - filename = Path(secure_filename(request.files[key].filename)) + filename = Path(secure_filename(fileobj.filename)) # type: ignore[arg-type] if not upload_dir.exists(): upload_dir.mkdir() filepath = Path(upload_dir, filename) - request.files["samples_file"].save(filepath) + fileobj.save(filepath) return filepath -- cgit v1.2.3