Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

original_names for get_zip #474

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions app/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,16 +528,22 @@ 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()

# write files
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:
os_file.write(db_file.read())
final_name = original_name if (original_name and original_names) else db_file.filename
# 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()
Expand Down
Loading