Muffin-Admin
#############
.. _description:
**Muffin-Admin** -- an extension to Muffin_ that implements admin-interfaces
.. _badges:
.. image:: https://github.com/klen/muffin-admin/workflows/tests/badge.svg
:target: https://github.com/klen/muffin-admin/actions
:alt: Tests Status
.. image:: https://img.shields.io/pypi/v/muffin-admin
:target: https://pypi.org/project/muffin-admin/
:alt: PYPI Version
.. image:: https://img.shields.io/pypi/pyversions/muffin-admin
:target: https://pypi.org/project/muffin-admin/
:alt: Python Versions
----------
.. image:: https://raw.github.com/klen/muffin-admin/develop/.github/muffin-admin.png
:height: 200px
.. _features:
Features
--------
- Support for `Peewee ORM`_, Mongo_, `SQLAlchemy Core`_ through `Muffin-Rest`_;
- Automatic filtering and sorting for items;
.. _contents:
.. contents::
.. _requirements:
Requirements
=============
- python >= 3.9
.. _installation:
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:
Usage
=====
Initialize the admin:
.. code-block:: python
from muffin_admin import Plugin
admin = Plugin(**options)
Initialize admin handlers (example for `Peewee ORM`_):
.. code-block:: python
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:
.. code-block:: python
admin.setup(app, **options)
Authentication
--------------
Decorate an authentication function with ``admin.check_auth``:
.. code-block:: python
@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:
.. code-block:: python
@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:
.. code-block:: python
@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
---------------
.. code-block:: python
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)
=========================== ==================================================== ===========================
.. _bugtracker:
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:
Contributing
============
Development of Muffin-Admin happens at: https://github.com/klen/muffin-admin
Contributors
=============
* klen_ (Kirill Klenov)
.. _license:
License
========
Licensed under a `MIT license`_.
.. _links:
.. _klen: https://github.com/klen
.. _Muffin: https://github.com/klen/muffin
.. _MIT license: http://opensource.org/licenses/MIT
.. _Mongo: https://www.mongodb.com/
.. _Peewee ORM: http://docs.peewee-orm.com/en/latest/
.. _SqlAlchemy Core: https://docs.sqlalchemy.org/en/14/core/
.. _Muffin-Rest: https://github.com/klen/muffin-rest
Raw data
{
"_id": null,
"home_page": "https://github.com/klen/muffin-admin",
"name": "muffin-admin",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": "admin, api, muffin, asgi, asyncio, trio",
"author": "Kirill Klenov",
"author_email": "horneds@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/f6/60/081f4bde2356613f76bce584bcd248b142a77f37da0b33c18ea0bf562fef/muffin_admin-6.1.3.tar.gz",
"platform": null,
"description": "Muffin-Admin\n#############\n\n.. _description:\n\n**Muffin-Admin** -- an extension to Muffin_ that implements admin-interfaces\n\n.. _badges:\n\n.. image:: https://github.com/klen/muffin-admin/workflows/tests/badge.svg\n :target: https://github.com/klen/muffin-admin/actions\n :alt: Tests Status\n\n.. image:: https://img.shields.io/pypi/v/muffin-admin\n :target: https://pypi.org/project/muffin-admin/\n :alt: PYPI Version\n\n.. image:: https://img.shields.io/pypi/pyversions/muffin-admin\n :target: https://pypi.org/project/muffin-admin/\n :alt: Python Versions\n\n----------\n\n.. image:: https://raw.github.com/klen/muffin-admin/develop/.github/muffin-admin.png\n :height: 200px\n\n.. _features:\n\nFeatures\n--------\n\n- Support for `Peewee ORM`_, Mongo_, `SQLAlchemy Core`_ through `Muffin-Rest`_;\n- Automatic filtering and sorting for items;\n\n.. _contents:\n\n.. contents::\n\n.. _requirements:\n\nRequirements\n=============\n\n- python >= 3.9\n\n.. _installation:\n\nInstallation\n=============\n\n**Muffin-Admin** should be installed using pip: ::\n\n pip install muffin-admin\n\nWith `SQLAlchemy Core`_ support: ::\n\n pip install muffin-admin[sqlalchemy]\n\nWith `Peewee ORM`_ support: ::\n\n pip install muffin-admin[peewee]\n\n.. _usage:\n\nUsage\n=====\n\nInitialize the admin:\n\n.. code-block:: python\n\n from muffin_admin import Plugin\n\n admin = Plugin(**options)\n\nInitialize admin handlers (example for `Peewee ORM`_):\n\n.. code-block:: python\n\n from muffin_admin import PWAdminHandler\n\n @admin.route\n class UserResource(PWAdminHandler):\n\n \"\"\"Create Admin Resource for the User model.\"\"\"\n\n class Meta:\n\n \"\"\"Tune the resource.\"\"\"\n\n # Peewee Model for the admin resource\n model = User\n\n # Filters\n filters = 'email', 'created', 'is_active', 'role'\n\n # Tune serialization/deserialization schemas\n schema_meta = {\n 'load_only': ('password',),\n 'dump_only': ('created',),\n }\n\n # Columns to show\n columns = 'id', 'email', 'is_active', 'role', 'created'\n\n # Custom Material-UI icon\n icon = 'People'\n\nConnect admin to an Muffin_ application:\n\n.. code-block:: python\n\n admin.setup(app, **options)\n\n\nAuthentication\n--------------\n\nDecorate an authentication function with ``admin.check_auth``:\n\n.. code-block:: python\n\n @admin.check_auth\n async def auth(request):\n \"\"\"Fake authorization method. Just checks for an auth token exists in request.\"\"\"\n return request.headers.get('authorization')\n\n\nRegister a function to return user's information:\n\n.. code-block:: python\n\n @admin.get_identity\n async def ident(request):\n \"\"\"Get current user information.\"\"\"\n pk = request.headers.get('authorization')\n user = User.select().where(User.id == pk).first()\n if user:\n return {\"id\": user.id, \"fullName\": user.email}\n\nImplement a login handler for standart react-admin auth page:\n\n.. code-block:: python\n\n @admin.login\n async def login(request):\n \"\"\"Login a user.\"\"\"\n data = await request.data()\n user = User.select().where(\n User.email == data['username'], User.password == data['password']).first()\n return ResponseJSON(user and user.id)\n\n\nFor futher reference check `https://github.com/klen/muffin-admin/tree/develop/examples <examples>` in the repository.\n\nCustom Actions\n---------------\n\n.. code-block:: python\n\n from muffin_admin import PWAdminHandler\n\n @admin.route\n class UserResource(PWAdminHandler):\n\n # ...\n\n @PWAdminHandler.action('users/disable', view='list')\n async def disable_users(self, request, resource=None):\n ids = request.query.getall('ids')\n # ...\n\n @PWAdminHandler.action('users/{id}/admin', view='show')\n async def mark_admin(self, request, resource=None):\n # ...\n\n\nConfiguration options\n----------------------\n\n=========================== ==================================================== ===========================\nName Default value Description\n--------------------------- ---------------------------------------------------- ---------------------------\n**prefix** ``\"/admin\"`` Admin's HTTP URL prefix\n**title** ``\"Muffin Admin\"`` Admin's title\n**main_js_url** ``\"{prefix}/main.js\"`` A link to main JS file\n**custom_js_url** ``\"\"`` A link to custom JS file\n**custom_css_url** ``\"\"`` A link to custom CSS file\n**login_url** ``None`` An HTTP URL for your custom login page\n**logout_url** ``None`` An HTTP URL for your custom logout page\n**menu_sort** ``True`` Sort menu items\n**auth_storage** ``\"localstorage\"`` Where to keep authorization information (localstorage|cookies)\n**auth_storage_name** ``muffin_admin_auth`` Localstorage/Cookie name for authentication info\n**app_bar_links** ``[{'url': '/', 'icon': 'Home', 'title': 'Home'}]`` Appbar links\n**mutation_mode** ``\"optimistic\"`` React-Admin edit mutation mode (pessimistic|optimistic|undoable)\n=========================== ==================================================== ===========================\n\n.. _bugtracker:\n\nBug tracker\n===========\n\nIf you have any suggestions, bug reports or\nannoyances please report them to the issue tracker\nat https://github.com/klen/muffin-admin/issues\n\n.. _contributing:\n\nContributing\n============\n\nDevelopment of Muffin-Admin happens at: https://github.com/klen/muffin-admin\n\n\nContributors\n=============\n\n* klen_ (Kirill Klenov)\n\n.. _license:\n\nLicense\n========\n\nLicensed under a `MIT license`_.\n\n.. _links:\n\n.. _klen: https://github.com/klen\n.. _Muffin: https://github.com/klen/muffin\n.. _MIT license: http://opensource.org/licenses/MIT\n.. _Mongo: https://www.mongodb.com/\n.. _Peewee ORM: http://docs.peewee-orm.com/en/latest/\n.. _SqlAlchemy Core: https://docs.sqlalchemy.org/en/14/core/\n.. _Muffin-Rest: https://github.com/klen/muffin-rest\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Admin interface for Muffin Framework",
"version": "6.1.3",
"project_urls": {
"Homepage": "https://github.com/klen/muffin-admin",
"Repository": "https://github.com/klen/muffin-admin"
},
"split_keywords": [
"admin",
" api",
" muffin",
" asgi",
" asyncio",
" trio"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "464da873b7e7cf0d01b4a37f9eccdd68ef3d953790498505bc05f2ffa67623fb",
"md5": "42efa18a0a54788ab534d7e306e680ea",
"sha256": "5524c9faf28d4bebbe6a50e55e0330921d4a1f8a83a42d45b21be1ab83b413aa"
},
"downloads": -1,
"filename": "muffin_admin-6.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "42efa18a0a54788ab534d7e306e680ea",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 1045592,
"upload_time": "2024-11-15T11:22:05",
"upload_time_iso_8601": "2024-11-15T11:22:05.229003Z",
"url": "https://files.pythonhosted.org/packages/46/4d/a873b7e7cf0d01b4a37f9eccdd68ef3d953790498505bc05f2ffa67623fb/muffin_admin-6.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f660081f4bde2356613f76bce584bcd248b142a77f37da0b33c18ea0bf562fef",
"md5": "c08cafa995685735ee8d5b975726909e",
"sha256": "40e273eb45837e927e8d54f05fea0179a5fa860a65314a63c7eb9d3d87c83112"
},
"downloads": -1,
"filename": "muffin_admin-6.1.3.tar.gz",
"has_sig": false,
"md5_digest": "c08cafa995685735ee8d5b975726909e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 1041150,
"upload_time": "2024-11-15T11:22:06",
"upload_time_iso_8601": "2024-11-15T11:22:06.849846Z",
"url": "https://files.pythonhosted.org/packages/f6/60/081f4bde2356613f76bce584bcd248b142a77f37da0b33c18ea0bf562fef/muffin_admin-6.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-15 11:22:06",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "klen",
"github_project": "muffin-admin",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "muffin-admin"
}