Skip to content

Commit

Permalink
perf: 优化ModelAdmin快速编辑
Browse files Browse the repository at this point in the history
  • Loading branch information
amisadmin committed May 15, 2022
1 parent b9334fc commit a611305
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
16 changes: 12 additions & 4 deletions fastapi_amis_admin/amis_admin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,17 @@ async def get_list_filter(self, request: Request) -> List[Union[SQLModelListFiel
return self.list_filter or list(self.schema_filter.__fields__.values())

async def get_list_column(self, request: Request, modelfield: ModelField) -> TableColumn:
quick_edit = (await self.has_update_permission(request, None, None)
and modelfield.name in self.schema_update.__fields__)
return AmisParser(modelfield).as_table_column(quick_edit=quick_edit)
column = AmisParser(modelfield).as_table_column()
if await self.has_update_permission(request, None, None) and modelfield.name in self.schema_update.__fields__:
item = await self.get_form_item(request, modelfield, action=CrudEnum.update)
if isinstance(item, BaseModel):
item = item.dict(exclude_none=True, by_alias=True, exclude={'name', 'label'})
if isinstance(item, dict):
column.quickEdit = item
column.quickEdit.update({"saveImmediately": True})
if item.get('type') == 'switch':
column.quickEdit.update({"mode": "inline"})
return column

async def get_list_columns(self, request: Request) -> List[TableColumn]:
columns = []
Expand Down Expand Up @@ -352,7 +360,7 @@ async def get_form_item_on_foreign_key(
self, request: Request,
modelfield: ModelField,
is_filter: bool = False
) -> Union[Service, SchemaNode,None]:
) -> Union[Service, SchemaNode, None]:
column = self.parser.get_column(modelfield.alias)
if column is None:
return None
Expand Down
17 changes: 4 additions & 13 deletions fastapi_amis_admin/amis_admin/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,8 @@ def as_table_column(self, quick_edit: bool = False) -> TableColumn:
column.remark = column.remark or self.remark
column.sortable = True
if quick_edit:
item = self.as_form_item()
column.quickEdit = item.dict(exclude_none=True, by_alias=True, exclude={'name', 'label'})
column.quickEdit.update(
{
"saveImmediately": True
}
)
if item.type == 'switch':
column.quickEdit.update(
{
"mode": "inline",
}
)
column.quickEdit = self.as_form_item().dict(exclude_none=True, by_alias=True, exclude={'name', 'label'})
column.quickEdit.update({"saveImmediately": True})
if column.quickEdit.get('type') == 'switch':
column.quickEdit.update({"mode": "inline"})
return column

0 comments on commit a611305

Please sign in to comment.