Add printer lifecycle fields and printer log
- Printer: bought_at, last_maintenance_at, decommissioned_at (all Date, nullable)
- PrinterLog: per-printer timestamped text entries (CASCADE delete)
- Migration 0003: adds columns + printer_logs table
- /printers/{id}: detail page showing lifecycle info + scrollable log
- POST /printers/{id}/log: add a log entry via modal form
- Printer names in list are now links to the detail page
- Add Printer modal includes optional purchase date
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ from app.db import get_db
|
||||
from app.models.filament import Filament
|
||||
from app.models.print_job import JobStatus, PrintJob
|
||||
from app.models.printer import Printer, PrinterStatus
|
||||
from app.models.printer_log import PrinterLog
|
||||
from app.models.printer_type import PrinterType
|
||||
from app.models.pricing import PricingConfig
|
||||
from app.models.todo import Todo
|
||||
@@ -48,18 +49,42 @@ def create_printer(
|
||||
name: str = Form(...),
|
||||
location: str = Form(""),
|
||||
type_id: str = Form(""),
|
||||
bought_at: str = Form(""),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
from datetime import date
|
||||
printer = Printer(
|
||||
name=name.strip(),
|
||||
location=location.strip() or None,
|
||||
type_id=int(type_id) if type_id else None,
|
||||
bought_at=date.fromisoformat(bought_at) if bought_at else None,
|
||||
)
|
||||
db.add(printer)
|
||||
db.commit()
|
||||
return RedirectResponse(url="/printers", status_code=HTTP_303_SEE_OTHER)
|
||||
|
||||
|
||||
@router.get("/printers/{printer_id}", response_class=HTMLResponse)
|
||||
def printer_detail(printer_id: int, request: Request, db: Session = Depends(get_db)):
|
||||
printer = db.query(Printer).filter(Printer.id == printer_id).first()
|
||||
if not printer:
|
||||
from fastapi import HTTPException
|
||||
raise HTTPException(status_code=404, detail="Printer not found")
|
||||
return templates.TemplateResponse("printer_detail.html", {
|
||||
"request": request,
|
||||
"active": "printers",
|
||||
"printer": printer,
|
||||
})
|
||||
|
||||
|
||||
@router.post("/printers/{printer_id}/log")
|
||||
def add_printer_log(printer_id: int, message: str = Form(...), db: Session = Depends(get_db)):
|
||||
entry = PrinterLog(printer_id=printer_id, message=message.strip())
|
||||
db.add(entry)
|
||||
db.commit()
|
||||
return RedirectResponse(url=f"/printers/{printer_id}", status_code=HTTP_303_SEE_OTHER)
|
||||
|
||||
|
||||
@router.get("/printer-types", response_class=HTMLResponse)
|
||||
def printer_types_page(request: Request, db: Session = Depends(get_db)):
|
||||
return templates.TemplateResponse("printer_types.html", {
|
||||
|
||||
Reference in New Issue
Block a user