From 1dc9a75ff009a8d81565e1936cf9a61ef8fd0d4e Mon Sep 17 00:00:00 2001 From: Marina Date: Tue, 14 Nov 2023 16:43:55 +0300 Subject: [PATCH 1/2] add ?original_names param --- app/server.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/server.py b/app/server.py index 1bfe9127..b09db749 100644 --- a/app/server.py +++ b/app/server.py @@ -528,6 +528,8 @@ def get_zip(): if not current_user.is_admin: abort(403) + original_names = request.args.get('original_names', False) == 'true' + # create tmp folder dirpath = tempfile.TemporaryDirectory() @@ -535,8 +537,10 @@ def get_zip(): checks_list, _ = db_methods.get_checks(**get_query(request)) for check in checks_list: db_file = db_methods.find_pdf_by_file_id(check['_id']) + original_name = db_methods.get_check(check['_id']).filename #get a filename from every check if db_file is not None: - with open(f"{dirpath.name}/{db_file.filename}", 'wb') as os_file: + final_name = original_name if (original_name and original_names) else db_file.filename + with open(f"{dirpath.name}/{final_name}", 'wb') as os_file: os_file.write(db_file.read()) # add csv From 24f8d2cab94376f5b38a3b4cd557e76506b65baf Mon Sep 17 00:00:00 2001 From: Marina Date: Tue, 14 Nov 2023 19:06:39 +0300 Subject: [PATCH 2/2] add if to avoid overwriting --- app/server.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/server.py b/app/server.py index b09db749..3626f536 100644 --- a/app/server.py +++ b/app/server.py @@ -540,8 +540,10 @@ def get_zip(): original_name = db_methods.get_check(check['_id']).filename #get a filename from every check if db_file is not None: final_name = original_name if (original_name and original_names) else db_file.filename - with open(f"{dirpath.name}/{final_name}", 'wb') as os_file: - os_file.write(db_file.read()) + # to avoid overwriting files with one name and different content: now we save only last version of pres (from last check) + if not os.path.exists(f'{dirpath.name}/{final_name}'): + with open(f"{dirpath.name}/{final_name}", 'wb') as os_file: + os_file.write(db_file.read()) # add csv response = get_stats()