From dc73c9a8c1cd1516edf0ef64294167a8d4a50226 Mon Sep 17 00:00:00 2001 From: Martin Hohenberg Date: Thu, 18 Jun 2026 22:06:35 +0200 Subject: [PATCH] =?UTF-8?q?Add=20amount=20field=20to=20job=20creation=20?= =?UTF-8?q?=E2=80=94=20auto-creates=20bracket=20when=20>=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Amount > 1 with no bracket selected: auto-creates a bracket named '{customer} – {file} ×{amount}', assigns all jobs to it, and redirects to the new bracket page. Amount = 1 behaves as before. Co-Authored-By: Claude Sonnet 4.6 --- app/routers/ui.py | 47 +++++++++++++++++++++++++++++------------ app/templates/jobs.html | 28 +++++++++++++++++------- 2 files changed, 54 insertions(+), 21 deletions(-) diff --git a/app/routers/ui.py b/app/routers/ui.py index 8dd07bd..3410038 100644 --- a/app/routers/ui.py +++ b/app/routers/ui.py @@ -149,6 +149,7 @@ async def create_job( customer: str = Form(""), filament_id: str = Form(""), bracket_id: str = Form(""), + amount: int = Form(1), notes: str = Form(""), stl_file: UploadFile = File(None), stl_select: str = Form(""), @@ -162,20 +163,40 @@ async def create_job( elif stl_select: filename = stl_select - job = PrintJob( - job_uuid=str(_uuid.uuid4()), - name=Path(filename).stem if filename else (customer.strip() or "Unnamed"), - file_name=filename, - printer_id=int(printer_id) if printer_id else None, - filament_id=int(filament_id) if filament_id else None, - bracket_id=int(bracket_id) if bracket_id else None, - customer=customer.strip() or None, - notes=notes.strip() or None, - ) - db.add(job) - db.flush() - db.add(JobLog(job_id=job.id, message="Job created")) + amount = max(1, amount) + customer_str = customer.strip() or None + job_name = Path(filename).stem if filename else (customer_str or "Unnamed") + + # Resolve bracket — auto-create one when printing multiple copies + effective_bracket_id = int(bracket_id) if bracket_id else None + if amount > 1 and not effective_bracket_id: + bracket_name = f"{job_name} ×{amount}" + if customer_str: + bracket_name = f"{customer_str} – {bracket_name}" + new_bracket = JobBracket(name=bracket_name, customer=customer_str) + db.add(new_bracket) + db.flush() + effective_bracket_id = new_bracket.id + + for _ in range(amount): + job = PrintJob( + job_uuid=str(_uuid.uuid4()), + name=job_name, + file_name=filename, + printer_id=int(printer_id) if printer_id else None, + filament_id=int(filament_id) if filament_id else None, + bracket_id=effective_bracket_id, + customer=customer_str, + notes=notes.strip() or None, + ) + db.add(job) + db.flush() + db.add(JobLog(job_id=job.id, message="Job created")) + db.commit() + + if effective_bracket_id and amount > 1: + return RedirectResponse(url=f"/brackets/{effective_bracket_id}", status_code=HTTP_303_SEE_OTHER) return RedirectResponse(url="/jobs", status_code=HTTP_303_SEE_OTHER) diff --git a/app/templates/jobs.html b/app/templates/jobs.html index 1b94e07..4271091 100644 --- a/app/templates/jobs.html +++ b/app/templates/jobs.html @@ -153,14 +153,26 @@ -
- - +
+
+ + +
+
+ + +