Adding ISOThread and UNC Thread
This commit is contained in:
1 parent
9285a021c0
commit
35e8a61b1d
22 files changed
+796
-3
No files matched your search
+228
-1
@@ -1,13 +1,16 @@
|
||||
"""HTMX-driven admin dashboard for users and roles."""
|
||||
"""HTMX-driven admin dashboard for users, roles, and thread standards."""
|
||||
|
||||
from fastapi import APIRouter, Depends, Form, HTTPException, Request, status
|
||||
from fastapi.responses import HTMLResponse, RedirectResponse, Response
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.database import get_db
|
||||
from app.crud import iso_thread as iso_thread_crud
|
||||
from app.crud import role as role_crud
|
||||
from app.crud import unc_thread as unc_thread_crud
|
||||
from app.crud import user as user_crud
|
||||
from app.deps import get_current_web_user
|
||||
from app.models.unc_thread import UncSeries
|
||||
from app.models.user import User
|
||||
from app.web.templates import templates
|
||||
|
||||
@@ -208,3 +211,227 @@ async def delete_role(
|
||||
if role is not None:
|
||||
await role_crud.delete(db, role)
|
||||
return Response(status_code=status.HTTP_200_OK)
|
||||
|
||||
|
||||
# --- ISO Threads -------------------------------------------------------------
|
||||
|
||||
|
||||
@router.get("/iso-threads", response_class=HTMLResponse)
|
||||
async def iso_threads_page(
|
||||
request: Request,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
user: User = Depends(web_require("iso_threads:read")),
|
||||
):
|
||||
return templates.TemplateResponse(
|
||||
request,
|
||||
"admin/iso_threads.html",
|
||||
{"user": user, "threads": await iso_thread_crud.list_all(db)},
|
||||
)
|
||||
|
||||
|
||||
@router.post("/iso-threads", response_class=HTMLResponse)
|
||||
async def create_iso_thread(
|
||||
request: Request,
|
||||
diameter_mm: float = Form(...),
|
||||
pitch_mm: float = Form(...),
|
||||
depth_mm: str = Form(""),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
_: User = Depends(web_require("iso_threads:write")),
|
||||
):
|
||||
await iso_thread_crud.create(
|
||||
db,
|
||||
diameter_mm=diameter_mm,
|
||||
pitch_mm=pitch_mm,
|
||||
depth_mm=float(depth_mm) if depth_mm.strip() else None,
|
||||
)
|
||||
return templates.TemplateResponse(
|
||||
request,
|
||||
"admin/_iso_threads_table.html",
|
||||
{"threads": await iso_thread_crud.list_all(db)},
|
||||
)
|
||||
|
||||
|
||||
@router.get("/iso-threads/{thread_id}/edit", response_class=HTMLResponse)
|
||||
async def edit_iso_thread_row(
|
||||
request: Request,
|
||||
thread_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
_: User = Depends(web_require("iso_threads:write")),
|
||||
):
|
||||
thread = await iso_thread_crud.get(db, thread_id)
|
||||
if thread is None:
|
||||
raise HTTPException(status_code=404, detail="ISO thread not found")
|
||||
return templates.TemplateResponse(
|
||||
request, "admin/_iso_thread_row_edit.html", {"t": thread}
|
||||
)
|
||||
|
||||
|
||||
@router.get("/iso-threads/{thread_id}/row", response_class=HTMLResponse)
|
||||
async def iso_thread_row(
|
||||
request: Request,
|
||||
thread_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
_: User = Depends(web_require("iso_threads:read")),
|
||||
):
|
||||
thread = await iso_thread_crud.get(db, thread_id)
|
||||
if thread is None:
|
||||
raise HTTPException(status_code=404, detail="ISO thread not found")
|
||||
return templates.TemplateResponse(
|
||||
request, "admin/_iso_thread_row.html", {"t": thread}
|
||||
)
|
||||
|
||||
|
||||
@router.post("/iso-threads/{thread_id}", response_class=HTMLResponse)
|
||||
async def update_iso_thread(
|
||||
request: Request,
|
||||
thread_id: int,
|
||||
diameter_mm: float = Form(...),
|
||||
pitch_mm: float = Form(...),
|
||||
depth_mm: str = Form(""),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
_: User = Depends(web_require("iso_threads:write")),
|
||||
):
|
||||
thread = await iso_thread_crud.get(db, thread_id)
|
||||
if thread is None:
|
||||
raise HTTPException(status_code=404, detail="ISO thread not found")
|
||||
await iso_thread_crud.update(
|
||||
db,
|
||||
thread,
|
||||
{
|
||||
"diameter_mm": diameter_mm,
|
||||
"pitch_mm": pitch_mm,
|
||||
"depth_mm": float(depth_mm) if depth_mm.strip() else None,
|
||||
},
|
||||
)
|
||||
return templates.TemplateResponse(
|
||||
request, "admin/_iso_thread_row.html", {"t": thread}
|
||||
)
|
||||
|
||||
|
||||
@router.delete("/iso-threads/{thread_id}")
|
||||
async def delete_iso_thread(
|
||||
thread_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
_: User = Depends(web_require("iso_threads:delete")),
|
||||
):
|
||||
thread = await iso_thread_crud.get(db, thread_id)
|
||||
if thread is not None:
|
||||
await iso_thread_crud.delete(db, thread)
|
||||
return Response(status_code=status.HTTP_200_OK)
|
||||
|
||||
|
||||
# --- UNC Threads -------------------------------------------------------------
|
||||
|
||||
|
||||
@router.get("/unc-threads", response_class=HTMLResponse)
|
||||
async def unc_threads_page(
|
||||
request: Request,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
user: User = Depends(web_require("unc_threads:read")),
|
||||
):
|
||||
return templates.TemplateResponse(
|
||||
request,
|
||||
"admin/unc_threads.html",
|
||||
{
|
||||
"user": user,
|
||||
"threads": await unc_thread_crud.list_all(db),
|
||||
"series_options": list(UncSeries),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@router.post("/unc-threads", response_class=HTMLResponse)
|
||||
async def create_unc_thread(
|
||||
request: Request,
|
||||
diameter_fraction: str = Form(...),
|
||||
tpi: int = Form(...),
|
||||
series: UncSeries = Form(...),
|
||||
depth_in: str = Form(""),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
_: User = Depends(web_require("unc_threads:write")),
|
||||
):
|
||||
await unc_thread_crud.create(
|
||||
db,
|
||||
diameter_fraction=diameter_fraction,
|
||||
tpi=tpi,
|
||||
series=series,
|
||||
depth_in=float(depth_in) if depth_in.strip() else None,
|
||||
)
|
||||
return templates.TemplateResponse(
|
||||
request,
|
||||
"admin/_unc_threads_table.html",
|
||||
{"threads": await unc_thread_crud.list_all(db)},
|
||||
)
|
||||
|
||||
|
||||
@router.get("/unc-threads/{thread_id}/edit", response_class=HTMLResponse)
|
||||
async def edit_unc_thread_row(
|
||||
request: Request,
|
||||
thread_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
_: User = Depends(web_require("unc_threads:write")),
|
||||
):
|
||||
thread = await unc_thread_crud.get(db, thread_id)
|
||||
if thread is None:
|
||||
raise HTTPException(status_code=404, detail="UNC thread not found")
|
||||
return templates.TemplateResponse(
|
||||
request,
|
||||
"admin/_unc_thread_row_edit.html",
|
||||
{"t": thread, "series_options": list(UncSeries)},
|
||||
)
|
||||
|
||||
|
||||
@router.get("/unc-threads/{thread_id}/row", response_class=HTMLResponse)
|
||||
async def unc_thread_row(
|
||||
request: Request,
|
||||
thread_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
_: User = Depends(web_require("unc_threads:read")),
|
||||
):
|
||||
thread = await unc_thread_crud.get(db, thread_id)
|
||||
if thread is None:
|
||||
raise HTTPException(status_code=404, detail="UNC thread not found")
|
||||
return templates.TemplateResponse(
|
||||
request, "admin/_unc_thread_row.html", {"t": thread}
|
||||
)
|
||||
|
||||
|
||||
@router.post("/unc-threads/{thread_id}", response_class=HTMLResponse)
|
||||
async def update_unc_thread(
|
||||
request: Request,
|
||||
thread_id: int,
|
||||
diameter_fraction: str = Form(...),
|
||||
tpi: int = Form(...),
|
||||
series: UncSeries = Form(...),
|
||||
depth_in: str = Form(""),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
_: User = Depends(web_require("unc_threads:write")),
|
||||
):
|
||||
thread = await unc_thread_crud.get(db, thread_id)
|
||||
if thread is None:
|
||||
raise HTTPException(status_code=404, detail="UNC thread not found")
|
||||
await unc_thread_crud.update(
|
||||
db,
|
||||
thread,
|
||||
{
|
||||
"diameter_fraction": diameter_fraction,
|
||||
"tpi": tpi,
|
||||
"series": series,
|
||||
"depth_in": float(depth_in) if depth_in.strip() else None,
|
||||
},
|
||||
)
|
||||
return templates.TemplateResponse(
|
||||
request, "admin/_unc_thread_row.html", {"t": thread}
|
||||
)
|
||||
|
||||
|
||||
@router.delete("/unc-threads/{thread_id}")
|
||||
async def delete_unc_thread(
|
||||
thread_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
_: User = Depends(web_require("unc_threads:delete")),
|
||||
):
|
||||
thread = await unc_thread_crud.get(db, thread_id)
|
||||
if thread is not None:
|
||||
await unc_thread_crud.delete(db, thread)
|
||||
return Response(status_code=status.HTTP_200_OK)
|
||||
Reference in new issue
Block a user