Adds multiple file download/delete option. Fixes css-filename.

This commit is contained in:
Michael Beck
2025-02-05 18:40:43 +01:00
parent 4eaff5a9b1
commit 0faacef2e9
4 changed files with 242 additions and 42 deletions

35
app.py
View File

@@ -203,33 +203,44 @@ def results():
def download_results():
data_files = glob.glob("data/*.csv")
log_files = glob.glob("log/*.log")
def get_file_info(file_path):
return {
"name": file_path,
"name_display": os.path.basename(file_path),
"last_modified": os.path.getmtime(file_path),
"created": os.path.getctime(file_path),
"size": get_size(file_path)
}
data_files_info = [get_file_info(file) for file in data_files]
log_files_info = [get_file_info(file) for file in log_files]
files = {"data": data_files_info, "log": log_files_info}
return render_template('download_results.html', files=files)
@app.route('/delete_file', methods=['POST'])
def delete_file():
file_path = request.form.get('file_path')
@app.route('/delete_files', methods=['POST'])
def delete_files():
file_paths = request.form.getlist('file_paths')
if not file_path or not os.path.isfile(file_path):
return jsonify({"error": "File not found"}), 404
if not file_paths:
return jsonify({"error": "No files specified"}), 400
try:
os.remove(file_path)
return jsonify({"success": True}), 200
except Exception as e:
return jsonify({"error": str(e)}), 500
errors = []
for file_path in file_paths:
if not os.path.isfile(file_path):
errors.append({"file": file_path, "error": "File not found"})
continue
try:
os.remove(file_path)
except Exception as e:
errors.append({"file": file_path, "error": str(e)})
if errors:
return jsonify({"errors": errors}), 207 # Multi-Status response
return jsonify({"success": True}), 200
@app.template_filter('datetimeformat')
def datetimeformat(value):