diff --git a/README.md b/README.md index 6c4d0f4..aa8d0b7 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,10 @@ Looking for old version? See branch [v1](https://github.com/fastapi-admin/fastap > pip install fastapi-admin ``` +## Requirements + +- [Redis](https://redis.io) + ## Online Demo You can check a online demo [here](https://fastapi-admin.long2ice.cn). diff --git a/docs/en/docs/reference/index.md b/docs/en/docs/extension/index.md similarity index 100% rename from docs/en/docs/reference/index.md rename to docs/en/docs/extension/index.md diff --git a/docs/en/docs/getting_started/installation.md b/docs/en/docs/getting_started/installation.md index 09908a7..c03cd06 100644 --- a/docs/en/docs/getting_started/installation.md +++ b/docs/en/docs/getting_started/installation.md @@ -20,7 +20,7 @@ Or you can install from source with latest code. Add the following line. -```shell +``` -e https://github.com/fastapi-admin/fastapi-admin.git@develop#egg=fastapi-admin ``` diff --git a/docs/en/docs/getting_started/quickstart.md b/docs/en/docs/getting_started/quickstart.md index acb9843..6de0890 100644 --- a/docs/en/docs/getting_started/quickstart.md +++ b/docs/en/docs/getting_started/quickstart.md @@ -1 +1,46 @@ # Quickstart + +`FastAPI-Admin` is easy to mount your `FastAPI` app, just need a few configs. + +## Mount Admin App + +First, you need mount the app from `FastAPI-Admin` as a sub application of `FastAPI`. + +```python +from fastapi_admin.app import app as admin_app +from fastapi import FastAPI + +app = FastAPI() +app.mount("/admin", admin_app) + +``` + +## Configure Admin App + +There are some configs to configure the admin app, and you need to configure it on startup of `FastAPI`. + +```python +from fastapi_admin.app import app as admin_app +from fastapi_admin.providers.login import UsernamePasswordProvider + +login_provider = UsernamePasswordProvider(user_model=User, enable_captcha=True) + + +@app.on_event("startup") +async def startup(): + redis = await aioredis.create_redis_pool("redis://localhost", encoding="utf8") + admin_app.configure( + logo_url="https://preview.tabler.io/static/logo-white.svg", + login_logo_url="https://preview.tabler.io/static/logo.svg", + template_folders=[os.path.join(BASE_DIR, "templates")], + login_provider=login_provider, + maintenance=False, + redis=redis, + ) +``` + +The full list of configs can be found in + +## Define And Register Resource + +## Start App diff --git a/docs/en/docs/pro/index.md b/docs/en/docs/pro/index.md index 9202b8f..d001b25 100644 --- a/docs/en/docs/pro/index.md +++ b/docs/en/docs/pro/index.md @@ -1,6 +1,8 @@ # Content -## Login Captcha and failed IP limitation +## Login Captcha + +## Failed Login IP Limitation ## Additional File Upload Providers diff --git a/docs/en/docs/reference/configuration.md b/docs/en/docs/reference/configuration.md new file mode 100644 index 0000000..a025a48 --- /dev/null +++ b/docs/en/docs/reference/configuration.md @@ -0,0 +1 @@ +# Configuration diff --git a/docs/en/docs/reference/file_upload.md b/docs/en/docs/reference/file_upload.md new file mode 100644 index 0000000..10e3470 --- /dev/null +++ b/docs/en/docs/reference/file_upload.md @@ -0,0 +1 @@ +# File Upload diff --git a/docs/en/docs/reference/middleware.md b/docs/en/docs/reference/middleware.md new file mode 100644 index 0000000..4dd1086 --- /dev/null +++ b/docs/en/docs/reference/middleware.md @@ -0,0 +1 @@ +# Middleware diff --git a/docs/en/docs/reference/resource.md b/docs/en/docs/reference/resource.md new file mode 100644 index 0000000..81dcb9f --- /dev/null +++ b/docs/en/docs/reference/resource.md @@ -0,0 +1 @@ +# Resource diff --git a/docs/en/docs/reference/widget/display.md b/docs/en/docs/reference/widget/display.md new file mode 100644 index 0000000..e69de29 diff --git a/docs/en/docs/reference/widget/filter.md b/docs/en/docs/reference/widget/filter.md new file mode 100644 index 0000000..e69de29 diff --git a/docs/en/docs/reference/widget/input.md b/docs/en/docs/reference/widget/input.md new file mode 100644 index 0000000..e69de29 diff --git a/docs/en/mkdocs.yml b/docs/en/mkdocs.yml index dd9bd6b..361c235 100644 --- a/docs/en/mkdocs.yml +++ b/docs/en/mkdocs.yml @@ -5,8 +5,8 @@ site_description: A fast admin dashboard based on FastAPI and TortoiseORM with t repo_name: fastapi-admin/fastapi-admin site_author: long2ice theme: - logo: https://fastapi.tiangolo.com/img/icon-white.svg - favicon: https://fastapi.tiangolo.com/img/favicon.png + logo: https://raw.githubusercontent.com/fastapi-admin/fastapi-admin/dev/images/icon-white.svg + favicon: https://raw.githubusercontent.com/fastapi-admin/fastapi-admin/dev/images/favicon.png name: material language: en icon: @@ -40,7 +40,16 @@ nav: - getting_started/installation.md - getting_started/quickstart.md - Reference: - - reference/index.md + - reference/configuration.md + - reference/resource.md + - Widget: + - reference/widget/filter.md + - reference/widget/display.md + - reference/widget/input.md + - reference/file_upload.md + - reference/middleware.md + - Extension: + - extension/index.md - Pro Version For Sponsor: - pro/index.md - pro/sponsor.md @@ -61,4 +70,4 @@ plugins: - git-revision-date-localized: type: datetime - markdownextradata -dev_addr: 0.0.0.0:7999 +dev_addr: 127.0.0.1:7999 diff --git a/examples/main.py b/examples/main.py index 2449e2b..a261d67 100644 --- a/examples/main.py +++ b/examples/main.py @@ -6,9 +6,14 @@ from starlette.middleware.cors import CORSMiddleware from starlette.staticfiles import StaticFiles from tortoise.contrib.fastapi import register_tortoise -from examples import providers, settings +from examples import settings from examples.constants import BASE_DIR +from examples.models import User from fastapi_admin.app import app as admin_app +from fastapi_admin.providers.login import UsernamePasswordProvider +import aioredis + +login_provider = UsernamePasswordProvider(user_model=User, enable_captcha=True) def create_app(): @@ -18,11 +23,19 @@ def create_app(): StaticFiles(directory=os.path.join(BASE_DIR, "static")), name="static", ) - admin_app.configure( - logo_url="https://preview.tabler.io/static/logo-white.svg", - template_folders=[os.path.join(BASE_DIR, "templates")], - login_provider=providers.Login, - ) + + @app.on_event("startup") + async def startup(): + redis = await aioredis.create_redis_pool("redis://localhost", encoding="utf8") + admin_app.configure( + logo_url="https://preview.tabler.io/static/logo-white.svg", + login_logo_url="https://preview.tabler.io/static/logo.svg", + template_folders=[os.path.join(BASE_DIR, "templates")], + login_provider=login_provider, + maintenance=False, + redis=redis, + ) + app.mount("/admin", admin_app) app.add_middleware( CORSMiddleware, diff --git a/examples/providers.py b/examples/providers.py deleted file mode 100644 index 22963ba..0000000 --- a/examples/providers.py +++ /dev/null @@ -1,6 +0,0 @@ -from examples.models import User -from fastapi_admin.providers.login import UsernamePasswordProvider - - -class Login(UsernamePasswordProvider): - model = User diff --git a/poetry.lock b/poetry.lock index 3ae9fb9..894a4d3 100644 --- a/poetry.lock +++ b/poetry.lock @@ -6,6 +6,18 @@ category = "main" optional = false python-versions = "*" +[[package]] +name = "aioredis" +version = "1.3.1" +description = "asyncio (PEP 3156) Redis support" +category = "main" +optional = false +python-versions = "*" + +[package.dependencies] +async-timeout = "*" +hiredis = "*" + [[package]] name = "aiosqlite" version = "0.16.1" @@ -46,6 +58,14 @@ lazy-object-proxy = ">=1.4.0" typed-ast = {version = ">=1.4.0,<1.5", markers = "implementation_name == \"cpython\" and python_version < \"3.8\""} wrapt = ">=1.11,<1.13" +[[package]] +name = "async-timeout" +version = "3.0.1" +description = "Timeout context manager for asyncio programs" +category = "main" +optional = false +python-versions = ">=3.5.3" + [[package]] name = "asyncmy" version = "0.1.5" @@ -237,6 +257,14 @@ category = "main" optional = false python-versions = ">=3.6" +[[package]] +name = "hiredis" +version = "2.0.0" +description = "Python wrapper for hiredis" +category = "main" +optional = false +python-versions = ">=3.6" + [[package]] name = "importlib-metadata" version = "4.0.1" @@ -868,19 +896,20 @@ python-versions = ">=3.6" docs = ["sphinx", "jaraco.packaging (>=8.2)", "rst.linker (>=1.9)"] testing = ["pytest (>=4.6)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pytest-cov", "pytest-enabler", "jaraco.itertools", "func-timeout", "pytest-black (>=0.3.7)", "pytest-mypy"] -[extras] -accel = [] - [metadata] lock-version = "1.1" python-versions = "^3.7" -content-hash = "1e6c6d920b7f669cf7fa1b92f2428e44d3148bbe29dc2b4d2aa1bdbcea571ce3" +content-hash = "3f9c88790071d1b81d5befdb3c20a47ca70a111be58492dae51ffca81b5283e1" [metadata.files] aiofiles = [ {file = "aiofiles-0.6.0-py3-none-any.whl", hash = "sha256:bd3019af67f83b739f8e4053c6c0512a7f545b9a8d91aaeab55e6e0f9d123c27"}, {file = "aiofiles-0.6.0.tar.gz", hash = "sha256:e0281b157d3d5d59d803e3f4557dcc9a3dff28a4dd4829a9ff478adae50ca092"}, ] +aioredis = [ + {file = "aioredis-1.3.1-py3-none-any.whl", hash = "sha256:b61808d7e97b7cd5a92ed574937a079c9387fdadd22bfbfa7ad2fd319ecc26e3"}, + {file = "aioredis-1.3.1.tar.gz", hash = "sha256:15f8af30b044c771aee6787e5ec24694c048184c7b9e54c3b60c750a4b93273a"}, +] aiosqlite = [ {file = "aiosqlite-0.16.1-py3-none-any.whl", hash = "sha256:1df802815bb1e08a26c06d5ea9df589bcb8eec56e5f3378103b0f9b223c6703c"}, {file = "aiosqlite-0.16.1.tar.gz", hash = "sha256:2e915463164efa65b60fd1901aceca829b6090082f03082618afca6fb9c8fdf7"}, @@ -897,6 +926,10 @@ astroid = [ {file = "astroid-2.5.6-py3-none-any.whl", hash = "sha256:4db03ab5fc3340cf619dbc25e42c2cc3755154ce6009469766d7143d1fc2ee4e"}, {file = "astroid-2.5.6.tar.gz", hash = "sha256:8a398dfce302c13f14bab13e2b14fe385d32b73f4e4853b9bdfb64598baa1975"}, ] +async-timeout = [ + {file = "async-timeout-3.0.1.tar.gz", hash = "sha256:0c3c816a028d47f659d6ff5c745cb2acf1f966da1fe5c19c77a70282b25f4c5f"}, + {file = "async_timeout-3.0.1-py3-none-any.whl", hash = "sha256:4291ca197d287d274d0b6cb5d6f8f8f82d434ed288f962539ff18cc9012f9ea3"}, +] asyncmy = [ {file = "asyncmy-0.1.5-cp39-cp39-manylinux2014_x86_64.whl", hash = "sha256:bfbf79b98277846f37a6952a8bd5bc3bc71fc416f969702d62d51d818f662b00"}, {file = "asyncmy-0.1.5.tar.gz", hash = "sha256:921738ce6cd16ef6ec91d8b887268d5afbba8f460b80b3e4fd2bf37793f3035f"}, @@ -999,6 +1032,49 @@ h11 = [ {file = "h11-0.12.0-py3-none-any.whl", hash = "sha256:36a3cb8c0a032f56e2da7084577878a035d3b61d104230d4bd49c0c6b555a9c6"}, {file = "h11-0.12.0.tar.gz", hash = "sha256:47222cb6067e4a307d535814917cd98fd0a57b6788ce715755fa2b6c28b56042"}, ] +hiredis = [ + {file = "hiredis-2.0.0-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:b4c8b0bc5841e578d5fb32a16e0c305359b987b850a06964bd5a62739d688048"}, + {file = "hiredis-2.0.0-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:0adea425b764a08270820531ec2218d0508f8ae15a448568109ffcae050fee26"}, + {file = "hiredis-2.0.0-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:3d55e36715ff06cdc0ab62f9591607c4324297b6b6ce5b58cb9928b3defe30ea"}, + {file = "hiredis-2.0.0-cp36-cp36m-manylinux2010_i686.whl", hash = "sha256:5d2a48c80cf5a338d58aae3c16872f4d452345e18350143b3bf7216d33ba7b99"}, + {file = "hiredis-2.0.0-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:240ce6dc19835971f38caf94b5738092cb1e641f8150a9ef9251b7825506cb05"}, + {file = "hiredis-2.0.0-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:5dc7a94bb11096bc4bffd41a3c4f2b958257085c01522aa81140c68b8bf1630a"}, + {file = "hiredis-2.0.0-cp36-cp36m-win32.whl", hash = "sha256:139705ce59d94eef2ceae9fd2ad58710b02aee91e7fa0ccb485665ca0ecbec63"}, + {file = "hiredis-2.0.0-cp36-cp36m-win_amd64.whl", hash = "sha256:c39c46d9e44447181cd502a35aad2bb178dbf1b1f86cf4db639d7b9614f837c6"}, + {file = "hiredis-2.0.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:adf4dd19d8875ac147bf926c727215a0faf21490b22c053db464e0bf0deb0485"}, + {file = "hiredis-2.0.0-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:0f41827028901814c709e744060843c77e78a3aca1e0d6875d2562372fcb405a"}, + {file = "hiredis-2.0.0-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:508999bec4422e646b05c95c598b64bdbef1edf0d2b715450a078ba21b385bcc"}, + {file = "hiredis-2.0.0-cp37-cp37m-manylinux2010_i686.whl", hash = "sha256:0d5109337e1db373a892fdcf78eb145ffb6bbd66bb51989ec36117b9f7f9b579"}, + {file = "hiredis-2.0.0-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:04026461eae67fdefa1949b7332e488224eac9e8f2b5c58c98b54d29af22093e"}, + {file = "hiredis-2.0.0-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:a00514362df15af041cc06e97aebabf2895e0a7c42c83c21894be12b84402d79"}, + {file = "hiredis-2.0.0-cp37-cp37m-win32.whl", hash = "sha256:09004096e953d7ebd508cded79f6b21e05dff5d7361771f59269425108e703bc"}, + {file = "hiredis-2.0.0-cp37-cp37m-win_amd64.whl", hash = "sha256:f8196f739092a78e4f6b1b2172679ed3343c39c61a3e9d722ce6fcf1dac2824a"}, + {file = "hiredis-2.0.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:294a6697dfa41a8cba4c365dd3715abc54d29a86a40ec6405d677ca853307cfb"}, + {file = "hiredis-2.0.0-cp38-cp38-manylinux1_i686.whl", hash = "sha256:3dddf681284fe16d047d3ad37415b2e9ccdc6c8986c8062dbe51ab9a358b50a5"}, + {file = "hiredis-2.0.0-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:dcef843f8de4e2ff5e35e96ec2a4abbdf403bd0f732ead127bd27e51f38ac298"}, + {file = "hiredis-2.0.0-cp38-cp38-manylinux2010_i686.whl", hash = "sha256:87c7c10d186f1743a8fd6a971ab6525d60abd5d5d200f31e073cd5e94d7e7a9d"}, + {file = "hiredis-2.0.0-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:7f0055f1809b911ab347a25d786deff5e10e9cf083c3c3fd2dd04e8612e8d9db"}, + {file = "hiredis-2.0.0-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:11d119507bb54e81f375e638225a2c057dda748f2b1deef05c2b1a5d42686048"}, + {file = "hiredis-2.0.0-cp38-cp38-win32.whl", hash = "sha256:7492af15f71f75ee93d2a618ca53fea8be85e7b625e323315169977fae752426"}, + {file = "hiredis-2.0.0-cp38-cp38-win_amd64.whl", hash = "sha256:65d653df249a2f95673976e4e9dd7ce10de61cfc6e64fa7eeaa6891a9559c581"}, + {file = "hiredis-2.0.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:ae8427a5e9062ba66fc2c62fb19a72276cf12c780e8db2b0956ea909c48acff5"}, + {file = "hiredis-2.0.0-cp39-cp39-manylinux1_i686.whl", hash = "sha256:3f5f7e3a4ab824e3de1e1700f05ad76ee465f5f11f5db61c4b297ec29e692b2e"}, + {file = "hiredis-2.0.0-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:e3447d9e074abf0e3cd85aef8131e01ab93f9f0e86654db7ac8a3f73c63706ce"}, + {file = "hiredis-2.0.0-cp39-cp39-manylinux2010_i686.whl", hash = "sha256:8b42c0dc927b8d7c0eb59f97e6e34408e53bc489f9f90e66e568f329bff3e443"}, + {file = "hiredis-2.0.0-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:b84f29971f0ad4adaee391c6364e6f780d5aae7e9226d41964b26b49376071d0"}, + {file = "hiredis-2.0.0-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:0b39ec237459922c6544d071cdcf92cbb5bc6685a30e7c6d985d8a3e3a75326e"}, + {file = "hiredis-2.0.0-cp39-cp39-win32.whl", hash = "sha256:a7928283143a401e72a4fad43ecc85b35c27ae699cf5d54d39e1e72d97460e1d"}, + {file = "hiredis-2.0.0-cp39-cp39-win_amd64.whl", hash = "sha256:a4ee8000454ad4486fb9f28b0cab7fa1cd796fc36d639882d0b34109b5b3aec9"}, + {file = "hiredis-2.0.0-pp36-pypy36_pp73-macosx_10_9_x86_64.whl", hash = "sha256:1f03d4dadd595f7a69a75709bc81902673fa31964c75f93af74feac2f134cc54"}, + {file = "hiredis-2.0.0-pp36-pypy36_pp73-manylinux1_x86_64.whl", hash = "sha256:04927a4c651a0e9ec11c68e4427d917e44ff101f761cd3b5bc76f86aaa431d27"}, + {file = "hiredis-2.0.0-pp36-pypy36_pp73-manylinux2010_x86_64.whl", hash = "sha256:a39efc3ade8c1fb27c097fd112baf09d7fd70b8cb10ef1de4da6efbe066d381d"}, + {file = "hiredis-2.0.0-pp36-pypy36_pp73-win32.whl", hash = "sha256:07bbf9bdcb82239f319b1f09e8ef4bdfaec50ed7d7ea51a56438f39193271163"}, + {file = "hiredis-2.0.0-pp37-pypy37_pp73-macosx_10_9_x86_64.whl", hash = "sha256:807b3096205c7cec861c8803a6738e33ed86c9aae76cac0e19454245a6bbbc0a"}, + {file = "hiredis-2.0.0-pp37-pypy37_pp73-manylinux1_x86_64.whl", hash = "sha256:1233e303645f468e399ec906b6b48ab7cd8391aae2d08daadbb5cad6ace4bd87"}, + {file = "hiredis-2.0.0-pp37-pypy37_pp73-manylinux2010_x86_64.whl", hash = "sha256:cb2126603091902767d96bcb74093bd8b14982f41809f85c9b96e519c7e1dc41"}, + {file = "hiredis-2.0.0-pp37-pypy37_pp73-win32.whl", hash = "sha256:f52010e0a44e3d8530437e7da38d11fb822acfb0d5b12e9cd5ba655509937ca0"}, + {file = "hiredis-2.0.0.tar.gz", hash = "sha256:81d6d8e39695f2c37954d1011c0480ef7cf444d4e3ae24bc5e89ee5de360139a"}, +] importlib-metadata = [ {file = "importlib_metadata-4.0.1-py3-none-any.whl", hash = "sha256:d7eb1dea6d6a6086f8be21784cc9e3bcfa55872b52309bc5fad53a8ea444465d"}, {file = "importlib_metadata-4.0.1.tar.gz", hash = "sha256:8c501196e49fb9df5df43833bdb1e4328f64847763ec8a50703148b73784d581"}, diff --git a/pyproject.toml b/pyproject.toml index a12eba9..61da42e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,6 +24,7 @@ jinja2 = "*" Babel = "*" python-multipart = "*" bcrypt = "*" +aioredis = "*" [tool.poetry.dev-dependencies] # test @@ -49,6 +50,3 @@ mkdocs-markdownextradata-plugin = "*" [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" - -[tool.poetry.extras] -accel = ["uvloop"]