Muffin-Admin – an extension to Muffin that implements admin-interfaces
Features
Support for Peewee ORM, Mongo, SQLAlchemy Core through Muffin-Rest;
Automatic filtering and sorting for items;
Requirements
python >= 3.7
Installation
Muffin-Admin should be installed using pip:
pip install muffin-admin
With SQLAlchemy Core support:
pip install muffin-admin[sqlalchemy]
With Peewee ORM support:
pip install muffin-admin[peewee]
Usage
Initialize the admin:
from muffin_admin import Plugin
admin = Plugin(**options)
Initialize admin handlers (example for Peewee ORM):
from muffin_admin import PWAdminHandler
@admin.route
class UserResource(PWAdminHandler):
"""Create Admin Resource for the User model."""
class Meta:
"""Tune the resource."""
# Peewee Model for the admin resource
model = User
# Filters
filters = 'email', 'created', 'is_active', 'role'
# Tune serialization/deserialization schemas
schema_meta = {
'load_only': ('password',),
'dump_only': ('created',),
}
# Columns to show
columns = 'id', 'email', 'is_active', 'role', 'created'
# Custom Material-UI icon
icon = 'People'
Connect admin to an Muffin application:
admin.setup(app, **options)
Authentication
Decorate an authentication function with admin.check_auth:
@admin.check_auth
async def auth(request):
"""Fake authorization method. Just checks for an auth token exists in request."""
return request.headers.get('authorization')
Register a function to return user’s information:
@admin.get_identity
async def ident(request):
"""Get current user information."""
pk = request.headers.get('authorization')
user = User.select().where(User.id == pk).first()
if user:
return {"id": user.id, "fullName": user.email}
Implement a login handler for standart react-admin auth page:
@admin.login
async def login(request):
"""Login a user."""
data = await request.data()
user = User.select().where(
User.email == data['username'], User.password == data['password']).first()
return ResponseJSON(user and user.id)
For futher reference check https://github.com/klen/muffin-admin/tree/develop/examples <examples> in the repository.
Configuration options
Name |
Default value |
Description |
prefix |
"/admin" |
Admin’s HTTP URL prefix |
title |
"Muffin Admin" |
Admin’s title |
custom_js_url |
"" |
A link to custom JS file |
custom_css_url |
"" |
A link to custom CSS file |
login_url |
None |
An HTTP URL for your custom authorization page |
logout_url |
None |
An HTTP URL for your custom logout page |
auth_storage |
"localstorage" |
Where to keep authorization information (localstorage|cookies) |
auth_storage_name |
muffin_admin_auth |
Localstorage/Cookie name for authentication info |
Bug tracker
If you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/klen/muffin-admin/issues
Contributing
Development of Muffin-Admin happens at: https://github.com/klen/muffin-admin
Contributors
klen (Kirill Klenov)
License
Licensed under a MIT license.
Metadata
Release files for muffin-admin 1.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| muffin-admin-1.1.2.tar.gz | 650.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| muffin_admin-1.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.3 MB
Release files / muffin-admin-1.1.2.tar.gz
| Download URL | muffin-admin-1.1.2.tar.gz |
|---|---|
| Size | 650.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2e8042ef1fde9594b56b140330b83165fd0e979c074f5c2c47b602fc6167e289
|
|
BLAKE2b-256 checksum How to use checksums |
a8fe60a07acd592d0ea3dc5e2a1d483a70e82a31631c56fa90c86087d502fc9e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5
|
Release files / muffin_admin-1.1.2-py3-none-any.whl
| Download URL | muffin_admin-1.1.2-py3-none-any.whl |
|---|---|
| Size | 651.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0f3930e27c1f8dc0e5f741baf9fdfcf62a1fdc24aebea7bccba36c5d2931b799
|
|
BLAKE2b-256 checksum How to use checksums |
fdeedce450fed86d3c8068446fcf937397ab63a318d4b8200fbec9c5f6b5f79c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5
|