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.8
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.
Custom Actions
from muffin_admin import PWAdminHandler
@admin.route
class UserResource(PWAdminHandler):
# ...
@PWAdminHandler.action('users/disable', view='list')
async def disable_users(self, request, resource=None):
ids = request.query.getall('ids')
# ...
@PWAdminHandler.action('users/{id}/admin', view='show')
async def mark_admin(self, request, resource=None):
# ...
Configuration options
Name |
Default value |
Description |
prefix |
"/admin" |
Admin’s HTTP URL prefix |
title |
"Muffin Admin" |
Admin’s title |
main_js_url |
"{prefix}/main.js" |
A link to main JS file |
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 login page |
logout_url |
None |
An HTTP URL for your custom logout page |
menu_sort |
True |
Sort menu items |
auth_storage |
"localstorage" |
Where to keep authorization information (localstorage|cookies) |
auth_storage_name |
muffin_admin_auth |
Localstorage/Cookie name for authentication info |
app_bar_links |
[{'url': '/', 'icon': 'Home', 'title': 'Home'}] |
Appbar links |
mutation_mode |
"optimistic" |
React-Admin edit mutation mode (pessimistic|optimistic|undoable) |
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.45.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| muffin_admin-1.45.7.tar.gz | 1.0 MB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| muffin_admin-1.45.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 2.1 MB
Release files / muffin_admin-1.45.7.tar.gz
| Download URL | muffin_admin-1.45.7.tar.gz |
|---|---|
| Size | 1.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
41fe450f43fa80e858415f3de33d70d357114c443d8e04d2928b8ecda27d55ee
|
|
BLAKE2b-256 checksum How to use checksums |
e0421e4ed1e6d1fedb6c7f9aac8127f73bdd9d52207dc2e2b315383a8cb0f0e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.10.12 Linux/5.15.0-1042-azure
|
Release files / muffin_admin-1.45.7-py3-none-any.whl
| Download URL | muffin_admin-1.45.7-py3-none-any.whl |
|---|---|
| Size | 1.0 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
350d256f67602d5a24c3d51da8954d43146b547dee2d00183c7ec42f33c85f92
|
|
BLAKE2b-256 checksum How to use checksums |
2c7242c7a6fa11fc1a6a06d6a8b7e9f5168fb6e7e4113be32678f1d652a80a3a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.10.12 Linux/5.15.0-1042-azure
|
Security for muffin-admin 1.45.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.