Spaces:
Sleeping
Sleeping
| 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" | |
| def index(): | |
| return render_template('builder.html') | |
| 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) | |