mirror of
https://github.com/fastapi-admin/fastapi-admin.git
synced 2025-08-06 18:49:47 +08:00
fix: example
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
from contextlib import asynccontextmanager
|
||||||
|
|
||||||
import redis.asyncio as redis
|
import redis.asyncio as redis
|
||||||
import uvicorn
|
import uvicorn
|
||||||
@ -46,6 +47,7 @@ async def lifespan(app: FastAPI):
|
|||||||
],
|
],
|
||||||
redis=r,
|
redis=r,
|
||||||
)
|
)
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
def create_app():
|
def create_app():
|
||||||
@ -60,9 +62,7 @@ def create_app():
|
|||||||
async def index():
|
async def index():
|
||||||
return RedirectResponse(url="/admin")
|
return RedirectResponse(url="/admin")
|
||||||
|
|
||||||
admin_app.add_exception_handler(
|
admin_app.add_exception_handler(HTTP_500_INTERNAL_SERVER_ERROR, server_error_exception)
|
||||||
HTTP_500_INTERNAL_SERVER_ERROR, server_error_exception
|
|
||||||
)
|
|
||||||
admin_app.add_exception_handler(HTTP_404_NOT_FOUND, not_found_error_exception)
|
admin_app.add_exception_handler(HTTP_404_NOT_FOUND, not_found_error_exception)
|
||||||
admin_app.add_exception_handler(HTTP_403_FORBIDDEN, forbidden_error_exception)
|
admin_app.add_exception_handler(HTTP_403_FORBIDDEN, forbidden_error_exception)
|
||||||
admin_app.add_exception_handler(HTTP_401_UNAUTHORIZED, unauthorized_error_exception)
|
admin_app.add_exception_handler(HTTP_401_UNAUTHORIZED, unauthorized_error_exception)
|
||||||
|
@ -119,7 +119,7 @@ class UsernamePasswordProvider(Provider):
|
|||||||
request: Request,
|
request: Request,
|
||||||
call_next: RequestResponseEndpoint,
|
call_next: RequestResponseEndpoint,
|
||||||
):
|
):
|
||||||
redis = request.app.redis # type:Redis
|
redis = request.app.redis # type:ignore
|
||||||
token = request.cookies.get(self.access_token)
|
token = request.cookies.get(self.access_token)
|
||||||
path = request.scope["path"]
|
path = request.scope["path"]
|
||||||
admin = None
|
admin = None
|
||||||
|
@ -15,7 +15,7 @@ class Input(Widget):
|
|||||||
template = "widgets/inputs/input.html"
|
template = "widgets/inputs/input.html"
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, help_text: Optional[str] = None, default: Any = None, null: bool = False, **context
|
self, help_text: Optional[str] = None, default: Any = None, null: bool = False, **context
|
||||||
):
|
):
|
||||||
super().__init__(null=null, help_text=help_text, **context)
|
super().__init__(null=null, help_text=help_text, **context)
|
||||||
self.default = default
|
self.default = default
|
||||||
@ -44,12 +44,12 @@ class Text(Input):
|
|||||||
input_type: Optional[str] = "text"
|
input_type: Optional[str] = "text"
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
help_text: Optional[str] = None,
|
help_text: Optional[str] = None,
|
||||||
default: Any = None,
|
default: Any = None,
|
||||||
null: bool = False,
|
null: bool = False,
|
||||||
placeholder: str = "",
|
placeholder: str = "",
|
||||||
disabled: bool = False,
|
disabled: bool = False,
|
||||||
):
|
):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
null=null,
|
null=null,
|
||||||
@ -65,11 +65,11 @@ class Select(Input):
|
|||||||
template = "widgets/inputs/select.html"
|
template = "widgets/inputs/select.html"
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
help_text: Optional[str] = None,
|
help_text: Optional[str] = None,
|
||||||
default: Any = None,
|
default: Any = None,
|
||||||
null: bool = False,
|
null: bool = False,
|
||||||
disabled: bool = False,
|
disabled: bool = False,
|
||||||
):
|
):
|
||||||
super().__init__(help_text=help_text, null=null, default=default, disabled=disabled)
|
super().__init__(help_text=help_text, null=null, default=default, disabled=disabled)
|
||||||
|
|
||||||
@ -91,12 +91,12 @@ class Select(Input):
|
|||||||
|
|
||||||
class ForeignKey(Select):
|
class ForeignKey(Select):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
model: Type[Model],
|
model: Type[Model],
|
||||||
default: Any = None,
|
default: Any = None,
|
||||||
null: bool = False,
|
null: bool = False,
|
||||||
disabled: bool = False,
|
disabled: bool = False,
|
||||||
help_text: Optional[str] = None,
|
help_text: Optional[str] = None,
|
||||||
):
|
):
|
||||||
super().__init__(help_text=help_text, default=default, null=null, disabled=disabled)
|
super().__init__(help_text=help_text, default=default, null=null, disabled=disabled)
|
||||||
self.model = model
|
self.model = model
|
||||||
@ -116,10 +116,10 @@ class ManyToMany(Select):
|
|||||||
template = "widgets/inputs/many_to_many.html"
|
template = "widgets/inputs/many_to_many.html"
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
model: Type[Model],
|
model: Type[Model],
|
||||||
disabled: bool = False,
|
disabled: bool = False,
|
||||||
help_text: Optional[str] = None,
|
help_text: Optional[str] = None,
|
||||||
):
|
):
|
||||||
super().__init__(help_text=help_text, disabled=disabled)
|
super().__init__(help_text=help_text, disabled=disabled)
|
||||||
self.model = model
|
self.model = model
|
||||||
@ -144,13 +144,13 @@ class ManyToMany(Select):
|
|||||||
|
|
||||||
class Enum(Select):
|
class Enum(Select):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
enum: Type[EnumCLS],
|
enum: Type[EnumCLS],
|
||||||
default: Any = None,
|
default: Any = None,
|
||||||
enum_type: Type = int,
|
enum_type: Type = int,
|
||||||
null: bool = False,
|
null: bool = False,
|
||||||
disabled: bool = False,
|
disabled: bool = False,
|
||||||
help_text: Optional[str] = None,
|
help_text: Optional[str] = None,
|
||||||
):
|
):
|
||||||
super().__init__(help_text=help_text, default=default, null=null, disabled=disabled)
|
super().__init__(help_text=help_text, default=default, null=null, disabled=disabled)
|
||||||
self.enum = enum
|
self.enum = enum
|
||||||
@ -174,10 +174,10 @@ class Json(Input):
|
|||||||
template = "widgets/inputs/json.html"
|
template = "widgets/inputs/json.html"
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
help_text: Optional[str] = None,
|
help_text: Optional[str] = None,
|
||||||
null: bool = False,
|
null: bool = False,
|
||||||
options: Optional[dict] = None,
|
options: Optional[dict] = None,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
options config to jsoneditor, see https://github.com/josdejong/jsoneditor
|
options config to jsoneditor, see https://github.com/josdejong/jsoneditor
|
||||||
@ -215,12 +215,12 @@ class File(Input):
|
|||||||
input_type = "file"
|
input_type = "file"
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
upload: FileUpload,
|
upload: FileUpload,
|
||||||
default: Any = None,
|
default: Any = None,
|
||||||
null: bool = False,
|
null: bool = False,
|
||||||
disabled: bool = False,
|
disabled: bool = False,
|
||||||
help_text: Optional[str] = None,
|
help_text: Optional[str] = None,
|
||||||
):
|
):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
null=null,
|
null=null,
|
||||||
@ -246,11 +246,11 @@ class Radio(Select):
|
|||||||
template = "widgets/inputs/radio.html"
|
template = "widgets/inputs/radio.html"
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
options: List[Tuple[str, Any]],
|
options: List[Tuple[str, Any]],
|
||||||
help_text: Optional[str] = None,
|
help_text: Optional[str] = None,
|
||||||
default: Any = None,
|
default: Any = None,
|
||||||
disabled: bool = False,
|
disabled: bool = False,
|
||||||
):
|
):
|
||||||
super().__init__(default=default, disabled=disabled, help_text=help_text)
|
super().__init__(default=default, disabled=disabled, help_text=help_text)
|
||||||
self.options = options
|
self.options = options
|
||||||
|
Reference in New Issue
Block a user