Adding part details page
This commit is contained in:
1 parent
2587ccbceb
commit
1b52ad04bc
7 files changed
+305
-9
No files matched your search
+59
-6
@@ -26,6 +26,7 @@ from app.crud import manufacturer as manufacturer_crud
|
||||
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_info as scope_info_crud
|
||||
from app.crud import scope_model as scope_model_crud
|
||||
from app.crud import attachment_point as attachment_point_crud
|
||||
from app.crud import attachment_point_name as apn_crud
|
||||
@@ -1780,6 +1781,37 @@ async def filter_skipped_parts(
|
||||
)
|
||||
|
||||
|
||||
@router.get("/augmented-parts/{augmented_part_id}", response_class=HTMLResponse)
|
||||
async def augmented_part_detail(
|
||||
request: Request,
|
||||
augmented_part_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
user: User = Depends(web_require("augmented_parts:read")),
|
||||
):
|
||||
ap = await augmented_part_crud.get(db, augmented_part_id)
|
||||
if ap is None:
|
||||
raise HTTPException(status_code=404, detail="Augmented part not found")
|
||||
can_read_fits = user.is_superuser or "fits:read" in user.permissions
|
||||
ctx = {
|
||||
"user": user,
|
||||
"ap": ap,
|
||||
"scope_info": await scope_info_crud.get_by_augmented_part(
|
||||
db, augmented_part_id
|
||||
),
|
||||
"attachment_points": await attachment_point_crud.list_for_augmented_part(
|
||||
db, augmented_part_id
|
||||
),
|
||||
"can_read_fits": can_read_fits,
|
||||
}
|
||||
if can_read_fits:
|
||||
ctx.update(
|
||||
await _augmented_part_fits_ctx(
|
||||
db, augmented_part_id, can_write=_can_write_fits(user)
|
||||
)
|
||||
)
|
||||
return templates.TemplateResponse(request, "admin/augmented_part_detail.html", ctx)
|
||||
|
||||
|
||||
@router.get("/augmented-parts/{augmented_part_id}/edit", response_class=HTMLResponse)
|
||||
async def edit_augmented_part_row(
|
||||
request: Request,
|
||||
@@ -2102,10 +2134,15 @@ async def _fit_view(db: AsyncSession, fit, part_id: int) -> dict:
|
||||
}
|
||||
|
||||
|
||||
def _can_write_fits(user: User) -> bool:
|
||||
return user.is_superuser or "fits:write" in user.permissions
|
||||
|
||||
|
||||
async def _augmented_part_fits_ctx(
|
||||
db: AsyncSession,
|
||||
augmented_part_id: int,
|
||||
*,
|
||||
can_write: bool = True,
|
||||
message: str | None = None,
|
||||
error: str | None = None,
|
||||
) -> dict:
|
||||
@@ -2122,6 +2159,7 @@ async def _augmented_part_fits_ctx(
|
||||
db, augmented_part_id
|
||||
),
|
||||
"other_parts": other_parts,
|
||||
"can_write": can_write,
|
||||
"message": message,
|
||||
"error": error,
|
||||
}
|
||||
@@ -2132,9 +2170,11 @@ async def augmented_part_fits(
|
||||
request: Request,
|
||||
augmented_part_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
_: User = Depends(web_require("fits:read")),
|
||||
user: User = Depends(web_require("fits:read")),
|
||||
):
|
||||
ctx = await _augmented_part_fits_ctx(db, augmented_part_id)
|
||||
ctx = await _augmented_part_fits_ctx(
|
||||
db, augmented_part_id, can_write=_can_write_fits(user)
|
||||
)
|
||||
return templates.TemplateResponse(request, "admin/_augmented_part_fits.html", ctx)
|
||||
|
||||
|
||||
@@ -2162,6 +2202,7 @@ async def recompute_augmented_part_fits(
|
||||
ctx = await _augmented_part_fits_ctx(
|
||||
db,
|
||||
augmented_part_id,
|
||||
can_write=_can_write_fits(actor),
|
||||
message=f"{result.created} created, {result.removed} removed.",
|
||||
)
|
||||
return templates.TemplateResponse(request, "admin/_augmented_part_fits.html", ctx)
|
||||
@@ -2223,7 +2264,9 @@ async def create_augmented_part_fit(
|
||||
"Fit", fit.id, f"attachment points {ap_a.id}↔{ap_b.id}"
|
||||
),
|
||||
)
|
||||
ctx = await _augmented_part_fits_ctx(db, augmented_part_id, error=error)
|
||||
ctx = await _augmented_part_fits_ctx(
|
||||
db, augmented_part_id, can_write=_can_write_fits(actor), error=error
|
||||
)
|
||||
return templates.TemplateResponse(request, "admin/_augmented_part_fits.html", ctx)
|
||||
|
||||
|
||||
@@ -2255,7 +2298,11 @@ async def update_augmented_part_fit_label(
|
||||
return templates.TemplateResponse(
|
||||
request,
|
||||
"admin/_augmented_part_fit_row.html",
|
||||
{"augmented_part_id": augmented_part_id, **view},
|
||||
{
|
||||
"augmented_part_id": augmented_part_id,
|
||||
"can_write": _can_write_fits(actor),
|
||||
**view,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -2281,7 +2328,11 @@ async def create_augmented_part_fit_note(
|
||||
return templates.TemplateResponse(
|
||||
request,
|
||||
"admin/_augmented_part_fit_row.html",
|
||||
{"augmented_part_id": augmented_part_id, **view},
|
||||
{
|
||||
"augmented_part_id": augmented_part_id,
|
||||
"can_write": _can_write_fits(actor),
|
||||
**view,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -2309,7 +2360,9 @@ async def delete_augmented_part_fit(
|
||||
resource_id=fit_id,
|
||||
description=audit_crud.describe_delete("Fit", fit_id, label),
|
||||
)
|
||||
ctx = await _augmented_part_fits_ctx(db, augmented_part_id)
|
||||
ctx = await _augmented_part_fits_ctx(
|
||||
db, augmented_part_id, can_write=_can_write_fits(actor)
|
||||
)
|
||||
return templates.TemplateResponse(request, "admin/_augmented_part_fits.html", ctx)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user