Add clamp connection
This commit is contained in:
1 parent
0168b023af
commit
59184124e7
14 files changed
+452
-2
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 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
|
||||
from app.crud import unc_thread as unc_thread_crud
|
||||
@@ -1604,6 +1605,141 @@ async def delete_static_connection(
|
||||
return Response(status_code=status.HTTP_200_OK)
|
||||
|
||||
|
||||
# --- Clamp Connections -------------------------------------------------------
|
||||
|
||||
|
||||
@router.get("/clamp-connections", response_class=HTMLResponse)
|
||||
async def clamp_connections_page(
|
||||
request: Request,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
user: User = Depends(web_require("clamp_connections:read")),
|
||||
):
|
||||
return templates.TemplateResponse(
|
||||
request,
|
||||
"admin/clamp_connections.html",
|
||||
{"user": user, "clamp_connections": await clamp_connection_crud.list_all(db)},
|
||||
)
|
||||
|
||||
|
||||
@router.post("/clamp-connections", response_class=HTMLResponse)
|
||||
async def create_clamp_connection(
|
||||
request: Request,
|
||||
min_mm: str = Form(""),
|
||||
max_mm: str = Form(""),
|
||||
min_in: str = Form(""),
|
||||
max_in: str = Form(""),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
actor: User = Depends(web_require("clamp_connections:write")),
|
||||
):
|
||||
cc = await clamp_connection_crud.create(
|
||||
db,
|
||||
min_mm=float(min_mm) if min_mm else None,
|
||||
max_mm=float(max_mm) if max_mm else None,
|
||||
min_in=float(min_in) if min_in else None,
|
||||
max_in=float(max_in) if max_in else None,
|
||||
)
|
||||
label = (
|
||||
f"{cc.min_mm}–{cc.max_mm} mm" if cc.min_mm is not None
|
||||
else f"{cc.min_in}–{cc.max_in} in"
|
||||
)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="create", resource_type="ClampConnection",
|
||||
resource_id=cc.id,
|
||||
description=audit_crud.describe_create("ClampConnection", cc.id, label),
|
||||
)
|
||||
return templates.TemplateResponse(
|
||||
request,
|
||||
"admin/_clamp_connections_table.html",
|
||||
{"clamp_connections": await clamp_connection_crud.list_all(db)},
|
||||
)
|
||||
|
||||
|
||||
@router.get("/clamp-connections/{clamp_connection_id}/edit", response_class=HTMLResponse)
|
||||
async def edit_clamp_connection_row(
|
||||
request: Request,
|
||||
clamp_connection_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
_: User = Depends(web_require("clamp_connections:write")),
|
||||
):
|
||||
cc = await clamp_connection_crud.get(db, clamp_connection_id)
|
||||
if cc is None:
|
||||
raise HTTPException(status_code=404, detail="Clamp connection not found")
|
||||
return templates.TemplateResponse(
|
||||
request, "admin/_clamp_connection_row_edit.html", {"cc": cc}
|
||||
)
|
||||
|
||||
|
||||
@router.get("/clamp-connections/{clamp_connection_id}/row", response_class=HTMLResponse)
|
||||
async def clamp_connection_row(
|
||||
request: Request,
|
||||
clamp_connection_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
_: User = Depends(web_require("clamp_connections:read")),
|
||||
):
|
||||
cc = await clamp_connection_crud.get(db, clamp_connection_id)
|
||||
if cc is None:
|
||||
raise HTTPException(status_code=404, detail="Clamp connection not found")
|
||||
return templates.TemplateResponse(
|
||||
request, "admin/_clamp_connection_row.html", {"cc": cc}
|
||||
)
|
||||
|
||||
|
||||
@router.post("/clamp-connections/{clamp_connection_id}", response_class=HTMLResponse)
|
||||
async def update_clamp_connection(
|
||||
request: Request,
|
||||
clamp_connection_id: int,
|
||||
min_mm: str = Form(""),
|
||||
max_mm: str = Form(""),
|
||||
min_in: str = Form(""),
|
||||
max_in: str = Form(""),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
actor: User = Depends(web_require("clamp_connections:write")),
|
||||
):
|
||||
cc = await clamp_connection_crud.get(db, clamp_connection_id)
|
||||
if cc is None:
|
||||
raise HTTPException(status_code=404, detail="Clamp connection not found")
|
||||
changes = {
|
||||
"min_mm": float(min_mm) if min_mm else None,
|
||||
"max_mm": float(max_mm) if max_mm else None,
|
||||
"min_in": float(min_in) if min_in else None,
|
||||
"max_in": float(max_in) if max_in else None,
|
||||
}
|
||||
await clamp_connection_crud.update(db, cc, changes)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="update", resource_type="ClampConnection",
|
||||
resource_id=clamp_connection_id,
|
||||
description=audit_crud.describe_update(
|
||||
"ClampConnection", clamp_connection_id, changes
|
||||
),
|
||||
)
|
||||
return templates.TemplateResponse(
|
||||
request, "admin/_clamp_connection_row.html", {"cc": cc}
|
||||
)
|
||||
|
||||
|
||||
@router.delete("/clamp-connections/{clamp_connection_id}")
|
||||
async def delete_clamp_connection(
|
||||
clamp_connection_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
actor: User = Depends(web_require("clamp_connections:delete")),
|
||||
):
|
||||
cc = await clamp_connection_crud.get(db, clamp_connection_id)
|
||||
if cc is not None:
|
||||
label = (
|
||||
f"{cc.min_mm}–{cc.max_mm} mm" if cc.min_mm is not None
|
||||
else f"{cc.min_in}–{cc.max_in} in"
|
||||
)
|
||||
await clamp_connection_crud.delete(db, cc)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="delete", resource_type="ClampConnection",
|
||||
resource_id=clamp_connection_id,
|
||||
description=audit_crud.describe_delete(
|
||||
"ClampConnection", clamp_connection_id, label
|
||||
),
|
||||
)
|
||||
return Response(status_code=status.HTTP_200_OK)
|
||||
|
||||
|
||||
# --- Audit Log ---------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user