Adds multiple file download/delete option. Fixes css-filename.
This commit is contained in:
35
app.py
35
app.py
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user