adding part colour
This commit is contained in:
1 parent
422e217180
commit
2e7002b73b
14 files changed
+379
-2
No files matched your search
@@ -10,6 +10,7 @@ from app.crud import imported_part as imported_part_crud
|
||||
from app.crud import imported_part_config as imported_part_config_crud
|
||||
from app.crud import iso_thread as iso_thread_crud
|
||||
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_model as scope_model_crud
|
||||
@@ -1118,6 +1119,114 @@ async def refresh_imported_parts(
|
||||
)
|
||||
|
||||
|
||||
# --- Part Colours ------------------------------------------------------------
|
||||
|
||||
|
||||
@router.get("/part-colours", response_class=HTMLResponse)
|
||||
async def part_colours_page(
|
||||
request: Request,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
user: User = Depends(web_require("part_colours:read")),
|
||||
):
|
||||
return templates.TemplateResponse(
|
||||
request,
|
||||
"admin/part_colours.html",
|
||||
{"user": user, "part_colours": await part_colour_crud.list_all(db)},
|
||||
)
|
||||
|
||||
|
||||
@router.post("/part-colours", response_class=HTMLResponse)
|
||||
async def create_part_colour(
|
||||
request: Request,
|
||||
name: str = Form(...),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
actor: User = Depends(web_require("part_colours:write")),
|
||||
):
|
||||
if not await part_colour_crud.get_by_name(db, name):
|
||||
created = await part_colour_crud.create(db, name=name)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="create", resource_type="PartColour",
|
||||
resource_id=created.id,
|
||||
description=audit_crud.describe_create("PartColour", created.id, created.name),
|
||||
)
|
||||
return templates.TemplateResponse(
|
||||
request,
|
||||
"admin/_part_colours_table.html",
|
||||
{"part_colours": await part_colour_crud.list_all(db)},
|
||||
)
|
||||
|
||||
|
||||
@router.get("/part-colours/{part_colour_id}/edit", response_class=HTMLResponse)
|
||||
async def edit_part_colour_row(
|
||||
request: Request,
|
||||
part_colour_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
_: User = Depends(web_require("part_colours:write")),
|
||||
):
|
||||
pc = await part_colour_crud.get(db, part_colour_id)
|
||||
if pc is None:
|
||||
raise HTTPException(status_code=404, detail="Part colour not found")
|
||||
return templates.TemplateResponse(
|
||||
request, "admin/_part_colour_row_edit.html", {"pc": pc}
|
||||
)
|
||||
|
||||
|
||||
@router.get("/part-colours/{part_colour_id}/row", response_class=HTMLResponse)
|
||||
async def part_colour_row(
|
||||
request: Request,
|
||||
part_colour_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
_: User = Depends(web_require("part_colours:read")),
|
||||
):
|
||||
pc = await part_colour_crud.get(db, part_colour_id)
|
||||
if pc is None:
|
||||
raise HTTPException(status_code=404, detail="Part colour not found")
|
||||
return templates.TemplateResponse(
|
||||
request, "admin/_part_colour_row.html", {"pc": pc}
|
||||
)
|
||||
|
||||
|
||||
@router.post("/part-colours/{part_colour_id}", response_class=HTMLResponse)
|
||||
async def update_part_colour(
|
||||
request: Request,
|
||||
part_colour_id: int,
|
||||
name: str = Form(...),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
actor: User = Depends(web_require("part_colours:write")),
|
||||
):
|
||||
pc = await part_colour_crud.get(db, part_colour_id)
|
||||
if pc is None:
|
||||
raise HTTPException(status_code=404, detail="Part colour not found")
|
||||
changes = {"name": name}
|
||||
await part_colour_crud.update(db, pc, changes)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="update", resource_type="PartColour",
|
||||
resource_id=part_colour_id,
|
||||
description=audit_crud.describe_update("PartColour", part_colour_id, changes),
|
||||
)
|
||||
return templates.TemplateResponse(
|
||||
request, "admin/_part_colour_row.html", {"pc": pc}
|
||||
)
|
||||
|
||||
|
||||
@router.delete("/part-colours/{part_colour_id}")
|
||||
async def delete_part_colour(
|
||||
part_colour_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
actor: User = Depends(web_require("part_colours:delete")),
|
||||
):
|
||||
pc = await part_colour_crud.get(db, part_colour_id)
|
||||
if pc is not None:
|
||||
name = pc.name
|
||||
await part_colour_crud.delete(db, pc)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="delete", resource_type="PartColour",
|
||||
resource_id=part_colour_id,
|
||||
description=audit_crud.describe_delete("PartColour", part_colour_id, name),
|
||||
)
|
||||
return Response(status_code=status.HTTP_200_OK)
|
||||
|
||||
|
||||
# --- Static Connections -------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user