{ "info": { "author": "Dillon Bowen", "author_email": "dsbowen@wharton.upenn.edu", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "Flask-Download-Btn defines a [SQLALchemy Mixin](https://docs.sqlalchemy.org/en/13/orm/extensions/declarative/mixins.html) for creating [Bootstrap](https://getbootstrap.com/) download buttons in a [Flask](https://palletsprojects.com/p/flask/) application.\n\nIts features include:\n\n1. **Automatic enabling and disabling.** A download button is automatically disabled on click and re-enabled on download completion.\n2. **CSRF protection.** The download button checks for a CSRF authentication token to ensure the client has permission to download the requested file.\n3. **Web form handling.** Download buttons are responsive to web forms.\n4. **Pre-download operations.** Download buttons can easily perform operations before files are downloaded, making it easy to create temporary download files.\n5. **Progress bar.** Update your clients on download progress with server sent events.\n\n## Installation\n\n```\n$ pip install flask-download-btn\n```\n\n## Quickstart\n\nOur folder structure will look like:\n\n```\ntemplates/\n index.html\napp.py\n```\n\nIn `templates/index.html`, paste the following Jinja template:\n\n```html\n\n
\n \n \n \n \n \n \n {{ download_btn.script() }}\n \n \n \n {{ download_btn.btn.render() }}\n {{ download_btn.render_progress() }}\n \n\n```\n\nIn `app.py`:\n\n```python\nfrom flask_download_btn import DownloadBtnManager, DownloadBtnMixin\n\nfrom flask import Flask, render_template, session\nfrom flask_sqlalchemy import SQLAlchemy\nfrom sqlalchemy.ext.orderinglist import ordering_list\n\napp = Flask(__name__)\napp.config['SECRET_KEY'] = 'secret'\napp.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'\napp.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False\ndb = SQLAlchemy(app)\n# initialize download button manager with application and database\ndownload_btn_manager = DownloadBtnManager(app, db=db)\n\n# create download button model and register it with the manager\n@DownloadBtnManager.register\nclass DownloadBtn(DownloadBtnMixin, db.Model):\n id = db.Column(db.Integer, primary_key=True)\n\n# create the database and clear the session when the app starts\n@app.before_first_request\ndef before_first_request():\n db.create_all()\n session.clear()\n\nHELLO_WORLD_URL = 'https://test-bucket2357.s3.us-east-2.amazonaws.com/hello_world.txt'\n\n# basic use\n@app.route('/')\ndef index():\n btn = DownloadBtn()\n btn.downloads = [(HELLO_WORLD_URL, 'hello_world.txt')]\n db.session.commit()\n return render_template('index.html', download_btn=btn)\n```\n\nRun the app with:\n\n```\n$ python app.py\n```\n\nAnd navigate to