Admin Panel for DB with Gino ORM and Sanic (inspired by Flask-Admin)
Project description
gino_admin
Admin Panel for PostgreSQL DB with Gino ORM and Sanic
How to install
pip install gino_admin
Usage example
Full example placed in ‘examples’ folder:
examples/
How to use
Create in your project ‘admin.py’ file and use add_admin_panel from from gino_admin import add_admin_panel
Example:
from from gino_admin import add_admin_panel
add_admin_panel(
app, db, [User, Place, City, GiftCard], custom_hash_method=custom_hash_method
)
Where:
‘app’ - your Sanic application ‘db’ : from gino.ext.sanic import Gino; db = Gino() and [User, Place, City, GiftCard] - list of models that you want to add in Admin Panel to maintain
custom_hash_method - optional parameter to define you own hash method to encrypt all ‘_hash’ columns of your Models. In admin panel _hash fields will be displayed without ‘_hash’ prefix and fields values will be hidden like ‘**’
Or you can use admin as a standalone App, when you need to define Sanic Application first (check ‘example’ folder)
Version 0.0.6 Updates:
Clean up template, hide row controls under menu.
Added ‘Copy’ option to DB row.
Now errors showed correct in table view pages in process of Delete, Copy, CSV Upload
Added possible to work without auth (for Debug purposes). Set env variable ‘ADMIN_AUTH_DISABLE=True’
Template updated
Added export Table’s Data to CSV
First version of SQL-query execution (run any query and get answer from PostgreSQL)
Fixed error display on csv upload
Version 0.0.5 Updates
Upload from CSV: fixed upload from _hash fields - now in step of upload called hash function (same as in edit, or add per item)
Fixed errors relative to datetime fields edit, added datetime_str_formats field to Config object, that allows to add custom datetime str formats. They used in step of convert str from DB to datetime object.
Now ‘_hash’ fields values in table showed as ‘*******’
Fixed errors relative to int id’s. Now they works correct in edit and delete.
Update Menu template. Now if there is more when 4 models - they will be available under Dropdown menu.
Version 0.0.4 Updates:
Upload from CSV - works, added example to examples/ files. You can upload data from ‘.csv’ tables.
Edit per row - now exist button ‘edit’.
Fixed delete for ALL rows of the model
Fixed delete per element.
Now works full ‘CRUD’.
Fixed auth, now it sets ‘cookie’ and compare user-agent (for multiple users per login)
Authentication
To disable authorisation:
Set environment variable ‘ADMIN_AUTH_DISABLE=1’
os.environ['ADMIN_AUTH_DISABLE'] = '1'
or from shell:
export ADMIN_AUTH_DISABLE=1
To define admin user & password:
check example/ folder to get code snippets
app = Sanic()
app.config["ADMIN_USER"] = "admin"
app.config["ADMIN_PASSWORD"] = "1234"
Limitations
For correct work of Admin Panel all models MUST contain unique ‘id’ field. ‘id’ used to identify row (one element) for Edit & Delete operations.
so if you define model, for example, User:
class User(db.Model):
__tablename__ = "users"
id = db.Column(db.String(), unique=True, primary_key=True)
id also can be Integer/BigInteger:
class User(db.Model):
__tablename__ = "users"
id = db.Column(db.BigInteger(), unique=True, primary_key=True)
Supported operations
One user auth
Create item by one for the Model
Delete all rows
Delete one item
Copy existed element (data table row)
Edit existed data
Upload data from csv
TODO:
Select multiple for delete/copy
Deepcopy element (recursive copy all rows/objects that depend on chosen as ForeignKey)
Edit multiple
Multiple users
Set up data presets (drop table for some data state, defined from csv)
Filters in columns
Actions history
Contributions
Contributions and feature requests are very welcome!
If you have time and want to fix: Please open issues with that you want to add or write to me in Telegram: @xnuinside or mail: xnuinside@gmail.com
Developer guide
Project use pre-commit hooks, so you need setup them
Just run:
pre-commit install
to install git hooks in your .git/ directory.
Screens:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for gino_admin-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f213516d2c8179234fceeaa06d478ac033f442798d3c77194851d3d186fdcfd |
|
MD5 | 0cbdb4bb6f0c8efd81ddd9426036b3bd |
|
BLAKE2b-256 | c021d3ba03f02c3710955fbc1b8dcc9ea00971317d7fdc357fc87a2306a87658 |