adding static connection
This commit is contained in:
1 parent
eba7896893
commit
422e217180
14 files changed
+405
-2
No files matched your search
@@ -13,6 +13,7 @@ from app.crud import manufacturer as manufacturer_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 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
|
||||
from app.crud import user as user_crud
|
||||
@@ -1117,6 +1118,120 @@ async def refresh_imported_parts(
|
||||
)
|
||||
|
||||
|
||||
# --- Static Connections -------------------------------------------------------
|
||||
|
||||
|
||||
@router.get("/static-connections", response_class=HTMLResponse)
|
||||
async def static_connections_page(
|
||||
request: Request,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
user: User = Depends(web_require("static_connections:read")),
|
||||
):
|
||||
return templates.TemplateResponse(
|
||||
request,
|
||||
"admin/static_connections.html",
|
||||
{"user": user, "static_connections": await static_connection_crud.list_all(db)},
|
||||
)
|
||||
|
||||
|
||||
@router.post("/static-connections", response_class=HTMLResponse)
|
||||
async def create_static_connection(
|
||||
request: Request,
|
||||
od_mm: float = Form(...),
|
||||
od_in: float = Form(...),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
actor: User = Depends(web_require("static_connections:write")),
|
||||
):
|
||||
if not await static_connection_crud.get_by_od_mm(db, od_mm):
|
||||
created = await static_connection_crud.create(db, od_mm=od_mm, od_in=od_in)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="create", resource_type="StaticConnection",
|
||||
resource_id=created.id,
|
||||
description=audit_crud.describe_create(
|
||||
"StaticConnection", created.id, f"{created.od_mm} mm"
|
||||
),
|
||||
)
|
||||
return templates.TemplateResponse(
|
||||
request,
|
||||
"admin/_static_connections_table.html",
|
||||
{"static_connections": await static_connection_crud.list_all(db)},
|
||||
)
|
||||
|
||||
|
||||
@router.get("/static-connections/{static_connection_id}/edit", response_class=HTMLResponse)
|
||||
async def edit_static_connection_row(
|
||||
request: Request,
|
||||
static_connection_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
_: User = Depends(web_require("static_connections:write")),
|
||||
):
|
||||
sc = await static_connection_crud.get(db, static_connection_id)
|
||||
if sc is None:
|
||||
raise HTTPException(status_code=404, detail="Static connection not found")
|
||||
return templates.TemplateResponse(
|
||||
request, "admin/_static_connection_row_edit.html", {"sc": sc}
|
||||
)
|
||||
|
||||
|
||||
@router.get("/static-connections/{static_connection_id}/row", response_class=HTMLResponse)
|
||||
async def static_connection_row(
|
||||
request: Request,
|
||||
static_connection_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
_: User = Depends(web_require("static_connections:read")),
|
||||
):
|
||||
sc = await static_connection_crud.get(db, static_connection_id)
|
||||
if sc is None:
|
||||
raise HTTPException(status_code=404, detail="Static connection not found")
|
||||
return templates.TemplateResponse(
|
||||
request, "admin/_static_connection_row.html", {"sc": sc}
|
||||
)
|
||||
|
||||
|
||||
@router.post("/static-connections/{static_connection_id}", response_class=HTMLResponse)
|
||||
async def update_static_connection(
|
||||
request: Request,
|
||||
static_connection_id: int,
|
||||
od_mm: float = Form(...),
|
||||
od_in: float = Form(...),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
actor: User = Depends(web_require("static_connections:write")),
|
||||
):
|
||||
sc = await static_connection_crud.get(db, static_connection_id)
|
||||
if sc is None:
|
||||
raise HTTPException(status_code=404, detail="Static connection not found")
|
||||
changes = {"od_mm": od_mm, "od_in": od_in}
|
||||
await static_connection_crud.update(db, sc, changes)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="update", resource_type="StaticConnection",
|
||||
resource_id=static_connection_id,
|
||||
description=audit_crud.describe_update("StaticConnection", static_connection_id, changes),
|
||||
)
|
||||
return templates.TemplateResponse(
|
||||
request, "admin/_static_connection_row.html", {"sc": sc}
|
||||
)
|
||||
|
||||
|
||||
@router.delete("/static-connections/{static_connection_id}")
|
||||
async def delete_static_connection(
|
||||
static_connection_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
actor: User = Depends(web_require("static_connections:delete")),
|
||||
):
|
||||
sc = await static_connection_crud.get(db, static_connection_id)
|
||||
if sc is not None:
|
||||
od_mm = sc.od_mm
|
||||
await static_connection_crud.delete(db, sc)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="delete", resource_type="StaticConnection",
|
||||
resource_id=static_connection_id,
|
||||
description=audit_crud.describe_delete(
|
||||
"StaticConnection", static_connection_id, f"{od_mm} mm"
|
||||
),
|
||||
)
|
||||
return Response(status_code=status.HTTP_200_OK)
|
||||
|
||||
|
||||
# --- Audit Log ---------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user