mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-08 07:01:40 +02:00
The list and update endpoints serialised field by field and never named cost / energy_kwh / energy_cost, so values Bambuddy had been recording all along went out as nulls. Both now validate from the ORM row, which removes the chance to omit a field rather than patching the three that were missing. Adds a Filament Used column plus a Columns picker for Cost, Energy, Energy Cost and Finished, persisted per browser. Also fixes the log view being unreachable with zero archives: the empty state ran before the view check, hiding a log that outlives the archives it refers to. --- Sort the Print Log by any column (#2636) Adds sort_by / sort_dir to the print-log endpoint, driven by clickable column headers. Server-side because paging is: ordering the rows the client holds would sort one page rather than the log. Empty values are held last in both directions — Postgres sorts NULLs high and SQLite low, so the same click would otherwise open on blanks on one backend and values on the other. id DESC breaks ties so paging through a low-cardinality sort can't repeat or skip a row.
53 lines
1.8 KiB
Python
53 lines
1.8 KiB
Python
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, ConfigDict
|
|
|
|
|
|
class PrintLogEntrySchema(BaseModel):
|
|
# from_attributes lets the routes build this straight off the ORM row.
|
|
# The GET serialiser used to name every field by hand, and each field it
|
|
# forgot came back as its default — a silent null rather than an error.
|
|
# That cost the log its failure_reason (#1687 part 4) and then its cost /
|
|
# energy_kwh / energy_cost (#2636). Validating from the row removes the
|
|
# chance to forget one.
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
id: int
|
|
archive_id: int | None = None
|
|
print_name: str | None = None
|
|
printer_name: str | None = None
|
|
printer_id: int | None = None
|
|
status: str
|
|
started_at: datetime | None = None
|
|
completed_at: datetime | None = None
|
|
duration_seconds: int | None = None
|
|
filament_type: str | None = None
|
|
filament_color: str | None = None
|
|
filament_used_grams: float | None = None
|
|
cost: float | None = None
|
|
energy_kwh: float | None = None
|
|
energy_cost: float | None = None
|
|
failure_reason: str | None = None
|
|
thumbnail_path: str | None = None
|
|
created_by_id: int | None = None
|
|
created_by_username: str | None = None
|
|
created_at: datetime
|
|
|
|
|
|
class PrintLogResponse(BaseModel):
|
|
items: list[PrintLogEntrySchema]
|
|
total: int
|
|
|
|
|
|
class PrintLogEntryUpdate(BaseModel):
|
|
"""Per-row classification edits (#1687 part 4 — IndividualGhost1905).
|
|
|
|
Lets the user set ``failure_reason`` (and re-classify ``status``) directly
|
|
on a Print Log row, including on orphan entries that have no archive to
|
|
edit through. The Failure Analysis widget already groups by
|
|
``PrintLogEntry.failure_reason``, so this just plugs the editor gap.
|
|
"""
|
|
|
|
failure_reason: str | None = None
|
|
status: str | None = None
|