muffin-admin


Namemuffin-admin JSON
Version 2.3.12 PyPI version JSON
download
home_pagehttps://github.com/klen/muffin-admin
SummaryAdmin interface for Muffin Framework
upload_time2024-03-04 09:34:36
maintainer
docs_urlNone
authorKirill Klenov
requires_python>=3.8,<4.0
licenseMIT
keywords admin api muffin asgi asyncio trio
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            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.8

.. _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": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "admin,api,muffin,asgi,asyncio,trio",
    "author": "Kirill Klenov",
    "author_email": "horneds@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/4a/61/af3e265c14d98b14d9718b413645efaeafc34913c7860d1417121b088e01/muffin_admin-2.3.12.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.8\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": "2.3.12",
    "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": "f81e08730cca99a94fecf6bb6a33f9883d82cf8b285410624552bb2a664d4857",
                "md5": "3e3c3a2b8431a1425db261411c575cae",
                "sha256": "877e508243168699ade01a4d12ab9d1f4a90499e6ed0b6a9a14397665a7820da"
            },
            "downloads": -1,
            "filename": "muffin_admin-2.3.12-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3e3c3a2b8431a1425db261411c575cae",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 1029839,
            "upload_time": "2024-03-04T09:34:32",
            "upload_time_iso_8601": "2024-03-04T09:34:32.986865Z",
            "url": "https://files.pythonhosted.org/packages/f8/1e/08730cca99a94fecf6bb6a33f9883d82cf8b285410624552bb2a664d4857/muffin_admin-2.3.12-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4a61af3e265c14d98b14d9718b413645efaeafc34913c7860d1417121b088e01",
                "md5": "94c58a6de130bbe154a3fb0c6924661a",
                "sha256": "cfe83ecff48dacf28408e8eaa3322ab59d5b88d69935eaabbbcced8d44a9b4db"
            },
            "downloads": -1,
            "filename": "muffin_admin-2.3.12.tar.gz",
            "has_sig": false,
            "md5_digest": "94c58a6de130bbe154a3fb0c6924661a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 1024751,
            "upload_time": "2024-03-04T09:34:36",
            "upload_time_iso_8601": "2024-03-04T09:34:36.624543Z",
            "url": "https://files.pythonhosted.org/packages/4a/61/af3e265c14d98b14d9718b413645efaeafc34913c7860d1417121b088e01/muffin_admin-2.3.12.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-04 09:34:36",
    "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"
}
        
Elapsed time: 0.22793s