Adding AttachmentPointNames
This commit is contained in:
1 parent
ae50ec7049
commit
2767fb1c8e
14 files changed
+406
-3
No files matched your search
@@ -15,6 +15,7 @@ from app.crud import part_colour as part_colour_crud
|
||||
from app.crud import part_type as part_type_crud
|
||||
from app.crud import role as role_crud
|
||||
from app.crud import scope_model as scope_model_crud
|
||||
from app.crud import attachment_point_name as apn_crud
|
||||
from app.crud import clamp_connection as clamp_connection_crud
|
||||
from app.crud import static_connection as static_connection_crud
|
||||
from app.crud import sub_part_type as sub_part_type_crud
|
||||
@@ -1491,6 +1492,114 @@ async def delete_part_colour(
|
||||
return Response(status_code=status.HTTP_200_OK)
|
||||
|
||||
|
||||
# --- Attachment Point Names ---------------------------------------------------
|
||||
|
||||
|
||||
@router.get("/attachment-point-names", response_class=HTMLResponse)
|
||||
async def attachment_point_names_page(
|
||||
request: Request,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
user: User = Depends(web_require("attachment_point_names:read")),
|
||||
):
|
||||
return templates.TemplateResponse(
|
||||
request,
|
||||
"admin/attachment_point_names.html",
|
||||
{"user": user, "attachment_point_names": await apn_crud.list_all(db)},
|
||||
)
|
||||
|
||||
|
||||
@router.post("/attachment-point-names", response_class=HTMLResponse)
|
||||
async def create_attachment_point_name(
|
||||
request: Request,
|
||||
name: str = Form(...),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
actor: User = Depends(web_require("attachment_point_names:write")),
|
||||
):
|
||||
if not await apn_crud.get_by_name(db, name):
|
||||
created = await apn_crud.create(db, name=name)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="create", resource_type="AttachmentPointName",
|
||||
resource_id=created.id,
|
||||
description=audit_crud.describe_create("AttachmentPointName", created.id, name),
|
||||
)
|
||||
return templates.TemplateResponse(
|
||||
request,
|
||||
"admin/_attachment_point_names_table.html",
|
||||
{"attachment_point_names": await apn_crud.list_all(db)},
|
||||
)
|
||||
|
||||
|
||||
@router.get("/attachment-point-names/{apn_id}/edit", response_class=HTMLResponse)
|
||||
async def edit_attachment_point_name_row(
|
||||
request: Request,
|
||||
apn_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
_: User = Depends(web_require("attachment_point_names:write")),
|
||||
):
|
||||
apn = await apn_crud.get(db, apn_id)
|
||||
if apn is None:
|
||||
raise HTTPException(status_code=404, detail="Attachment point name not found")
|
||||
return templates.TemplateResponse(
|
||||
request, "admin/_attachment_point_name_row_edit.html", {"apn": apn}
|
||||
)
|
||||
|
||||
|
||||
@router.get("/attachment-point-names/{apn_id}/row", response_class=HTMLResponse)
|
||||
async def attachment_point_name_row(
|
||||
request: Request,
|
||||
apn_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
_: User = Depends(web_require("attachment_point_names:read")),
|
||||
):
|
||||
apn = await apn_crud.get(db, apn_id)
|
||||
if apn is None:
|
||||
raise HTTPException(status_code=404, detail="Attachment point name not found")
|
||||
return templates.TemplateResponse(
|
||||
request, "admin/_attachment_point_name_row.html", {"apn": apn}
|
||||
)
|
||||
|
||||
|
||||
@router.post("/attachment-point-names/{apn_id}", response_class=HTMLResponse)
|
||||
async def update_attachment_point_name(
|
||||
request: Request,
|
||||
apn_id: int,
|
||||
name: str = Form(...),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
actor: User = Depends(web_require("attachment_point_names:write")),
|
||||
):
|
||||
apn = await apn_crud.get(db, apn_id)
|
||||
if apn is None:
|
||||
raise HTTPException(status_code=404, detail="Attachment point name not found")
|
||||
changes = {"name": name}
|
||||
await apn_crud.update(db, apn, changes)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="update", resource_type="AttachmentPointName",
|
||||
resource_id=apn_id,
|
||||
description=audit_crud.describe_update("AttachmentPointName", apn_id, changes),
|
||||
)
|
||||
return templates.TemplateResponse(
|
||||
request, "admin/_attachment_point_name_row.html", {"apn": apn}
|
||||
)
|
||||
|
||||
|
||||
@router.delete("/attachment-point-names/{apn_id}")
|
||||
async def delete_attachment_point_name(
|
||||
apn_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
actor: User = Depends(web_require("attachment_point_names:delete")),
|
||||
):
|
||||
apn = await apn_crud.get(db, apn_id)
|
||||
if apn is not None:
|
||||
name = apn.name
|
||||
await apn_crud.delete(db, apn)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="delete", resource_type="AttachmentPointName",
|
||||
resource_id=apn_id,
|
||||
description=audit_crud.describe_delete("AttachmentPointName", apn_id, name),
|
||||
)
|
||||
return Response(status_code=status.HTTP_200_OK)
|
||||
|
||||
|
||||
# --- Static Connections -------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user