Skip to content

Commit

Permalink
Merge pull request #474 from moevm/453_original_name_for_get_zip
Browse files Browse the repository at this point in the history
original_names for get_zip
  • Loading branch information
HadronCollider authored Feb 20, 2024
2 parents d885e21 + 24f8d2c commit 55f28d3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,16 +577,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

0 comments on commit 55f28d3

Please sign in to comment.