Adding ability to add attachment points when editing augmented part

This commit is contained in:
Ian Roddis committed 2026-07-02 14:13:09 -03:00
1 parent ceae27a12e
commit d67b4ceb65
7 files changed
+355 -1

No files matched your search

+184
View File
@@ -1385,6 +1385,190 @@ async def delete_augmented_part(
return Response(status_code=status.HTTP_200_OK)
async def _augmented_part_ap_ctx(db: AsyncSession, augmented_part_id: int) -> dict:
return {
"augmented_part_id": augmented_part_id,
"attachment_points_list": await attachment_point_crud.list_for_augmented_part(
db, augmented_part_id
),
"attachment_point_names": await apn_crud.list_all(db),
"iso_threads": await iso_thread_crud.list_all(db),
"unc_threads": await unc_thread_crud.list_all(db),
"clamp_connections": await clamp_connection_crud.list_all(db),
"static_connections": await static_connection_crud.list_all(db),
}
@router.get(
"/augmented-parts/{augmented_part_id}/attachment-points", response_class=HTMLResponse
)
async def augmented_part_attachment_points(
request: Request,
augmented_part_id: int,
db: AsyncSession = Depends(get_db),
_: User = Depends(web_require("attachment_points:read")),
):
ctx = await _augmented_part_ap_ctx(db, augmented_part_id)
return templates.TemplateResponse(
request, "admin/_augmented_part_attachment_points.html", ctx
)
@router.post(
"/augmented-parts/{augmented_part_id}/attachment-points", response_class=HTMLResponse
)
async def create_augmented_part_attachment_point(
request: Request,
augmented_part_id: int,
attachment_point_name_id: int = Form(...),
connection_type: str = Form(""),
iso_thread_id: str = Form(""),
unc_thread_id: str = Form(""),
clamp_connection_id: str = Form(""),
static_connection_id: str = Form(""),
db: AsyncSession = Depends(get_db),
actor: User = Depends(web_require("attachment_points:write")),
):
apoint = await attachment_point_crud.create(
db,
augmented_part_id=augmented_part_id,
attachment_point_name_id=attachment_point_name_id,
iso_thread_id=int(iso_thread_id) if iso_thread_id else None,
unc_thread_id=int(unc_thread_id) if unc_thread_id else None,
clamp_connection_id=int(clamp_connection_id) if clamp_connection_id else None,
static_connection_id=int(static_connection_id) if static_connection_id else None,
)
await audit_crud.log(
db, actor=actor, action="create", resource_type="AttachmentPoint",
resource_id=apoint.id,
description=audit_crud.describe_create(
"AttachmentPoint", apoint.id,
f"part {augmented_part_id}"
),
)
ctx = await _augmented_part_ap_ctx(db, augmented_part_id)
return templates.TemplateResponse(
request, "admin/_augmented_part_attachment_points.html", ctx
)
@router.get(
"/augmented-parts/{augmented_part_id}/attachment-points/{attachment_point_id}/edit",
response_class=HTMLResponse,
)
async def edit_augmented_part_attachment_point(
request: Request,
augmented_part_id: int,
attachment_point_id: int,
db: AsyncSession = Depends(get_db),
_: User = Depends(web_require("attachment_points:write")),
):
apoint = await attachment_point_crud.get(db, attachment_point_id)
if apoint is None:
raise HTTPException(status_code=404, detail="Attachment point not found")
ctx = await _augmented_part_ap_ctx(db, augmented_part_id)
ctx["apoint"] = apoint
if apoint.iso_thread_id:
ctx["connection_type"] = "iso_thread"
elif apoint.unc_thread_id:
ctx["connection_type"] = "unc_thread"
elif apoint.clamp_connection_id:
ctx["connection_type"] = "clamp_connection"
elif apoint.static_connection_id:
ctx["connection_type"] = "static_connection"
else:
ctx["connection_type"] = ""
return templates.TemplateResponse(
request, "admin/_augmented_part_ap_row_edit.html", ctx
)
@router.get(
"/augmented-parts/{augmented_part_id}/attachment-points/{attachment_point_id}/row",
response_class=HTMLResponse,
)
async def augmented_part_attachment_point_row(
request: Request,
augmented_part_id: int,
attachment_point_id: int,
db: AsyncSession = Depends(get_db),
_: User = Depends(web_require("attachment_points:read")),
):
apoint = await attachment_point_crud.get(db, attachment_point_id)
if apoint is None:
raise HTTPException(status_code=404, detail="Attachment point not found")
return templates.TemplateResponse(
request, "admin/_augmented_part_ap_row.html", {"apoint": apoint}
)
@router.post(
"/augmented-parts/{augmented_part_id}/attachment-points/{attachment_point_id}",
response_class=HTMLResponse,
)
async def update_augmented_part_attachment_point(
request: Request,
augmented_part_id: int,
attachment_point_id: int,
attachment_point_name_id: int = Form(...),
connection_type: str = Form(""),
iso_thread_id: str = Form(""),
unc_thread_id: str = Form(""),
clamp_connection_id: str = Form(""),
static_connection_id: str = Form(""),
db: AsyncSession = Depends(get_db),
actor: User = Depends(web_require("attachment_points:write")),
):
apoint = await attachment_point_crud.get(db, attachment_point_id)
if apoint is None:
raise HTTPException(status_code=404, detail="Attachment point not found")
changes = {
"attachment_point_name_id": attachment_point_name_id,
"iso_thread_id": int(iso_thread_id) if iso_thread_id else None,
"unc_thread_id": int(unc_thread_id) if unc_thread_id else None,
"clamp_connection_id": int(clamp_connection_id) if clamp_connection_id else None,
"static_connection_id": int(static_connection_id) if static_connection_id else None,
}
apoint = await attachment_point_crud.update(db, apoint, changes)
await audit_crud.log(
db, actor=actor, action="update", resource_type="AttachmentPoint",
resource_id=attachment_point_id,
description=audit_crud.describe_update(
"AttachmentPoint", attachment_point_id, changes
),
)
return templates.TemplateResponse(
request, "admin/_augmented_part_ap_row.html", {"apoint": apoint}
)
@router.delete(
"/augmented-parts/{augmented_part_id}/attachment-points/{attachment_point_id}",
response_class=HTMLResponse,
)
async def delete_augmented_part_attachment_point(
request: Request,
augmented_part_id: int,
attachment_point_id: int,
db: AsyncSession = Depends(get_db),
actor: User = Depends(web_require("attachment_points:delete")),
):
apoint = await attachment_point_crud.get(db, attachment_point_id)
if apoint is not None:
await attachment_point_crud.delete(db, apoint)
await audit_crud.log(
db, actor=actor, action="delete", resource_type="AttachmentPoint",
resource_id=attachment_point_id,
description=audit_crud.describe_delete(
"AttachmentPoint", attachment_point_id, f"part {augmented_part_id}"
),
)
ctx = await _augmented_part_ap_ctx(db, augmented_part_id)
return templates.TemplateResponse(
request, "admin/_augmented_part_attachment_points.html", ctx
)
# --- Part Colours ------------------------------------------------------------