Spaces:
Paused
Paused
Commit ·
fcc6ca2
1
Parent(s): 5ad571f
fix download
Browse filesFiles changed (2)
- app.py+14-1
- templates/data.html+11-20
6 unmodified lines789101112137 unmodified lines212223242526217 unmodified lines2442452462472482496 unmodified linessend_file,Response,render_template_string,redirect)import pandas as pdimport plotly.graph_objects as gofrom sqlalchemy import create_engine7 unmodified linesget_lst_topdepartment,get_wfrankwise_count,get_topfive_badgetitle)import sqlite3import timeimport json217 unmodified linesrequest_info['tbl_selected'] = request.form.getlist('tbl_selected')return redirect(url_for('data'))# if __name__ == '__main__':# app.run(debug=True)6 unmodified lines78910111213147 unmodified lines22232425262728217 unmodified lines2462472482492502512522532542552562572582592602612626 unmodified linessend_file,Response,render_template_string,redirect,send_file)import pandas as pdimport plotly.graph_objects as gofrom sqlalchemy import create_engine7 unmodified linesget_lst_topdepartment,get_wfrankwise_count,get_topfive_badgetitle)import osimport sqlite3import timeimport json217 unmodified linesrequest_info['tbl_selected'] = request.form.getlist('tbl_selected')return redirect(url_for('data'))@app.route('/download/<table_name>', methods=['GET'])def download_csv(table_name):# Assuming you have a mapping or logic to get the CSV file path from the table namecsv_file_path = os.path.join('referencefiles', f"{table_name}.csv")if os.path.exists(csv_file_path):return send_file(csv_file_path, as_attachment=True)else:return "File not found", 404# if __name__ == '__main__':# app.run(debug=True)
92 unmodified lines9394959697989910010110210310410510610710810911011111211311411511611711811912092 unmodified lines// Function to handle the table data downloadfunction downloadTableData() {const selectedTable = $('#table-dropdown').val();if (selectedTable) {const fileName = `referencefiles/${selectedTable}.csv`;fetch(fileName).then(response => response.blob()).then(blob => {const url = window.URL.createObjectURL(blob);const a = document.createElement('a');a.style.display = 'none';a.href = url;a.download = `${selectedTable}.csv`;document.body.appendChild(a);a.click();window.URL.revokeObjectURL(url);}).catch(error => console.error('Error downloading the file:', error));} else {alert('Please select a table to download.');}}// ... rest of the existing code ...</script><script>var req_tables = {{ req_tables | safe }};92 unmodified lines9394959697989910010110210310410510610710810911011192 unmodified lines// Function to handle the table data downloadfunction downloadTableData() {// Get the selected table name from the dropdownconst selectedTableIndex = $('#table-dropdown').val();// Map the selected index back to the table nameconst tableName = $("#table-dropdown option:selected").text().toLowerCase(); // Assuming the table name is stored in lowercase as CSV filename// Build the URL for the download endpointconst downloadUrl = `/download/${tableName}`;// Redirect the browser to the download URL to trigger the downloadwindow.location.href = downloadUrl;}</script><script>var req_tables = {{ req_tables | safe }};
app.py+14-1
templates/data.html+11-20