Add job edit modal on detail page
POST /jobs/{id}/edit updates: customer, material, color, priority, bracket,
printer, status, notes. Bracket field has '— none —' to detach from bracket.
Save auto-logs 'Job updated'. Edit button in page header.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,7 @@ from app.db import get_db
|
||||
from app.models.job_bracket import JobBracket
|
||||
from app.models.stl_cache import StlCache
|
||||
from app.models.job_log import JobLog
|
||||
from app.models.print_job import JobStatus, PrintJob
|
||||
from app.models.print_job import JobStatus, PrintJob # noqa: F401
|
||||
from app.models.printer import Printer, PrinterStatus
|
||||
from app.models.printer_log import PrinterLog
|
||||
from app.models.printer_type import PrinterType
|
||||
@@ -227,9 +227,45 @@ def job_detail(job_id: int, request: Request, db: Session = Depends(get_db)):
|
||||
"active": "jobs",
|
||||
"job": job,
|
||||
"stl": stl,
|
||||
"printers": db.query(Printer).order_by(Printer.name).all(),
|
||||
"brackets": db.query(JobBracket).order_by(JobBracket.name).all(),
|
||||
"materials": available_materials() or MATERIALS,
|
||||
"colors": available_colors() or COLORS,
|
||||
"all_statuses": [s.value for s in JobStatus],
|
||||
})
|
||||
|
||||
|
||||
@router.post("/jobs/{job_id}/edit")
|
||||
def edit_job(
|
||||
job_id: int,
|
||||
customer: str = Form(""),
|
||||
job_material: str = Form(""),
|
||||
job_color: str = Form(""),
|
||||
priority: str = Form(""),
|
||||
bracket_id: str = Form(""),
|
||||
printer_id: str = Form(""),
|
||||
status: str = Form(""),
|
||||
notes: str = Form(""),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
from fastapi import HTTPException
|
||||
job = db.query(PrintJob).filter(PrintJob.id == job_id).first()
|
||||
if not job:
|
||||
raise HTTPException(status_code=404, detail="Job not found")
|
||||
job.customer = customer.strip() or None
|
||||
job.job_material = job_material or None
|
||||
job.job_color = job_color or None
|
||||
job.priority = bool(priority)
|
||||
job.bracket_id = int(bracket_id) if bracket_id else None
|
||||
job.printer_id = int(printer_id) if printer_id else None
|
||||
job.notes = notes.strip() or None
|
||||
if status:
|
||||
job.status = JobStatus(status)
|
||||
db.add(JobLog(job_id=job.id, message=f"Job updated"))
|
||||
db.commit()
|
||||
return RedirectResponse(url=f"/jobs/{job_id}", status_code=HTTP_303_SEE_OTHER)
|
||||
|
||||
|
||||
@router.post("/jobs/{job_id}/analyse")
|
||||
def analyse_job_file(job_id: int, db: Session = Depends(get_db)):
|
||||
from fastapi import HTTPException
|
||||
|
||||
Reference in New Issue
Block a user