mirror of
https://github.com/fastapi-admin/fastapi-admin.git
synced 2026-03-13 10:32:25 +08:00
update menu struct
This commit is contained in:
@@ -28,7 +28,7 @@ async def test_bulk(bulk_in: BulkIn, model=Depends(get_model)):
|
||||
return ret.dict()
|
||||
|
||||
|
||||
@admin_app.get("/home", )
|
||||
@admin_app.get("/home",)
|
||||
async def home():
|
||||
return {"html": templates.get_template("home.html").render()}
|
||||
|
||||
|
||||
@@ -100,30 +100,45 @@ class AdminApp(FastAPI):
|
||||
|
||||
menus = [
|
||||
Menu(name="Home", url="/", icon="fa fa-home"),
|
||||
Menu(name="Content", title=True),
|
||||
*self._build_content_menus(),
|
||||
Menu(name="External", title=True),
|
||||
Menu(name="Content", children=self._build_content_menus()),
|
||||
Menu(
|
||||
name="Github",
|
||||
url="https://github.com/long2ice/fastapi-admin",
|
||||
icon="fa fa-github",
|
||||
external=True,
|
||||
name="External",
|
||||
children=[
|
||||
Menu(
|
||||
name="Github",
|
||||
url="https://github.com/long2ice/fastapi-admin",
|
||||
icon="fa fa-github",
|
||||
external=True,
|
||||
),
|
||||
],
|
||||
),
|
||||
]
|
||||
if permission:
|
||||
permission_menus = [
|
||||
Menu(name="Auth", title=True),
|
||||
Menu(
|
||||
name="User", url="/rest/User", icon="fa fa-user", search_fields=("username",),
|
||||
name="Auth",
|
||||
children=[
|
||||
Menu(
|
||||
name="User",
|
||||
url="/rest/User",
|
||||
icon="fa fa-user",
|
||||
search_fields=("username",),
|
||||
),
|
||||
Menu(
|
||||
name="Role",
|
||||
url="/rest/Role",
|
||||
icon="fa fa-group",
|
||||
actions={"delete": False},
|
||||
),
|
||||
Menu(
|
||||
name="Permission",
|
||||
url="/rest/Permission",
|
||||
icon="fa fa-user-plus",
|
||||
actions={"delete": False},
|
||||
),
|
||||
Menu(name="Logout", url="/logout", icon="fa fa-lock",),
|
||||
],
|
||||
),
|
||||
Menu(name="Role", url="/rest/Role", icon="fa fa-group", actions={"delete": False}),
|
||||
Menu(
|
||||
name="Permission",
|
||||
url="/rest/Permission",
|
||||
icon="fa fa-user-plus",
|
||||
actions={"delete": False},
|
||||
),
|
||||
Menu(name="Logout", url="/logout", icon="fa fa-lock",),
|
||||
]
|
||||
menus += permission_menus
|
||||
return menus
|
||||
@@ -171,7 +186,7 @@ class AdminApp(FastAPI):
|
||||
raise Exception("No Permission Model Founded.")
|
||||
|
||||
for model, _ in get_all_models():
|
||||
for action in enums.PermissionAction:
|
||||
for action in enums.PermissionAction.choices():
|
||||
label = f"{enums.PermissionAction.choices().get(action)} {model}"
|
||||
defaults = dict(label=label, model=model, action=action,)
|
||||
await permission_model.get_or_create(**defaults,)
|
||||
|
||||
@@ -5,8 +5,6 @@ from pydantic import BaseModel, HttpUrl
|
||||
|
||||
class Menu(BaseModel):
|
||||
name: str
|
||||
# whether is it a title or a model resource.
|
||||
title: Optional[bool]
|
||||
# must be format with /rest/<Model> if it's a model resource.
|
||||
url: Optional[str]
|
||||
icon: Optional[str]
|
||||
@@ -27,7 +25,7 @@ class Menu(BaseModel):
|
||||
# define field type,like select,radiolist,text,date
|
||||
fields_type: Dict = {}
|
||||
# define field attr,like cols which in bootstrap table
|
||||
attrs: Dict[str, Dict] = {}
|
||||
attrs: Dict[str, Dict] = {"created_at": {"label": "CreatedAt"}}
|
||||
# active table export
|
||||
export: bool = True
|
||||
actions: Optional[Dict]
|
||||
@@ -49,7 +47,6 @@ class Site(BaseModel):
|
||||
theme_switcher: bool = False
|
||||
theme: Optional[str]
|
||||
url: Optional[HttpUrl]
|
||||
grid_style: int = 1
|
||||
# custom css
|
||||
css: Optional[List[HttpUrl]]
|
||||
# menu define
|
||||
|
||||
Reference in New Issue
Block a user