From c41d53b5895720b580d26a28cb827a3e469b7ab7 Mon Sep 17 00:00:00 2001 From: Brian Peterson Date: Thu, 29 Aug 2019 13:24:39 -0600 Subject: [PATCH] Update readme again --- README.md | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a073964..ac75cb4 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ My little bundling of flask-admin and flask-security. Drawn heavily from the fla ```sh # Update setup.py version number + python setup.py sdist twine upload dist/flask_secure_admin-x.x.x.tar.gz # use the last version created ``` @@ -16,11 +17,12 @@ twine upload dist/flask_secure_admin-x.x.x.tar.gz # use the last version created Run the following from a virtual environment: - pip install flask-secure-admin # Or use pipenv + pipenv install flask-secure-admin # Or use pip Add the following python to your project: ```python +from sqlsoup import SQLSoup from flask_secure_admin import SecureAdminBlueprint app.db = SQLSoup(os.environ['DATABASE_URI']) app.register_blueprint(SecureAdminBlueprint( @@ -28,13 +30,13 @@ app.register_blueprint(SecureAdminBlueprint( url_prefix='secure-admin')) ``` -Add sqlsoup models to your admin view by passing a list of their names +Add sqlsoup models to your admin view by passing a list of their names as a third argument to `SecureAdminBlueprint`, and a list of view options -for customization of these model views as a fourth argument: +for customization of these model views as a fourth argument. For example: ```python app.register_blueprint(SecureAdminBlueprint( name='Your Project Name', - url_prefix='secure-admin' + url_prefix='secure-admin', models=['videos', 'captions', 'languages'], view_options=[ dict( @@ -46,15 +48,30 @@ app.register_blueprint(SecureAdminBlueprint( See https://flask-admin.readthedocs.io/en/latest/api/mod_contrib_sqla/#flask_admin.contrib.sqla.ModelView and its parent class, https://flask-admin.readthedocs.io/en/latest/api/mod_model/#flask_admin.model.BaseModelView, -for a list of all configuration options. +for a list of all configuration options. + +### Database Setup Last, run this to create necessary database tables in your database (PostgreSQL): - // Turns into, for example: psql yourdatabase < /Users/you/.local/share/virtualenvs/env-aP3G_9r-/lib/python3.7/site-packages/flask_secure_admin/create.sql + # Turns into, for example: psql yourdatabase < /Users/you/.local/share/virtualenvs/env-aP3G_9r-/lib/python3.7/site-packages/flask_secure_admin/create.sql psql yourdatabase < $(dirname $(which pip))/../lib/$(python --version | sed 's/..$//' | sed 's/ //' | awk '{print tolower($0)}')/site-packages/flask_secure_admin/create.sql; This will create the tables: users, roles, & users_roles, so if you have any of those, this won't work. In that case, you're probably best off making sure you have each of the fields required on users and roles. See the create.sql file for reference. -At this point, you're set! Run your app, there should now be a protected '/admin' route. +This project is only setup to work automagically with a postgres database / the `psql` command available. See `SecureAdminBlueprint.bootstrap_database()` in `flask_secure_admin/base.py`. However, you can emulate what it does quickly by just running the following from a python shell, assuming the aforementioned `Flask` app setup: + +```python +from yourapp import app +from flask_secure_admin.utils import create_initial_admin_user +create_initial_admin_user(app) +``` + +At this point, you're set! Run your app, there should now be a protected '/admin' route with a page shown for as many database tables as you have specified. + + +### Future Plans + +I'd love to get this to work with Flask-SQLAlchemy / SQLAlchemy, but I don't have the time right now. Contributions are welcome!