Spaces:
Sleeping
Sleeping
File size: 1,384 Bytes
79f5a9b f092a9b 79f5a9b f092a9b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | from flask import Flask, render_template, request, send_file, Response, jsonify
import json
import io
import os
app = Flask(__name__)
app.secret_key = "checklist_pro_secret_key"
@app.route('/')
def index():
return render_template('builder.html')
@app.route('/download', methods=['POST'])
def download():
try:
data = request.json
if not data:
return jsonify({"error": "No data provided"}), 400
# Ensure basic fields exist
data.setdefault('title', 'Checklist')
data.setdefault('description', '')
data.setdefault('author', '')
data.setdefault('theme', 'indigo')
data.setdefault('groups', [])
html_content = render_template(
'export_template.html',
checklist_data=data
)
# Create a file-like object
buffer = io.BytesIO()
buffer.write(html_content.encode('utf-8'))
buffer.seek(0)
return send_file(
buffer,
as_attachment=True,
download_name='checklist.html',
mimetype='text/html'
)
except Exception as e:
print(f"Error generating checklist: {e}")
return jsonify({"error": str(e)}), 500
if __name__ == '__main__':
port = int(os.environ.get('PORT', 7860))
app.run(host='0.0.0.0', port=port, debug=True)
|