Skip to main content

Admin interface for Muffin Framework

Project description

Muffin-Admin – an extension to Muffin that implements admin-interfaces

Tests Status PYPI Version Python Versions
https://raw.github.com/klen/muffin-admin/develop/.github/muffin-admin.png

Features

Requirements

  • python >= 3.9

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.

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

muffin_admin-9.2.4.tar.gz (1.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

muffin_admin-9.2.4-py3-none-any.whl (1.1 MB view details)

Uploaded Python 3

File details

Details for the file muffin_admin-9.2.4.tar.gz.

File metadata

  • Download URL: muffin_admin-9.2.4.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.3 Linux/6.11.0-1012-azure

File hashes

Hashes for muffin_admin-9.2.4.tar.gz
Algorithm Hash digest
SHA256 460fd263a85ed484c65cb7901185a64bdf6e02692a340b72e9123a59975148a8
MD5 8b05103668a7b5561279600b73b431d2
BLAKE2b-256 f052763a3d3b5e1461b3cd118fb85e83fd85494bdd6cfd7da24de75d26049246

See more details on using hashes here.

File details

Details for the file muffin_admin-9.2.4-py3-none-any.whl.

File metadata

  • Download URL: muffin_admin-9.2.4-py3-none-any.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.3 Linux/6.11.0-1012-azure

File hashes

Hashes for muffin_admin-9.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e36aec8e62e10c433244f5133ddf58fc471a77866132a5f5da9d5236307e19e9
MD5 fb86c78f809d528d9196ea983feaf236
BLAKE2b-256 2f6e502454fa1d4ea9f79b7553482555233991b7adc3bf5a0f1b8824cbba2492

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page