print_log.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from datetime import datetime
  2. from pydantic import BaseModel, ConfigDict
  3. from backend.app.schemas.not_null import IgnoresNullForRequiredColumns
  4. class PrintLogEntrySchema(BaseModel):
  5. # from_attributes lets the routes build this straight off the ORM row.
  6. # The GET serialiser used to name every field by hand, and each field it
  7. # forgot came back as its default — a silent null rather than an error.
  8. # That cost the log its failure_reason (#1687 part 4) and then its cost /
  9. # energy_kwh / energy_cost (#2636). Validating from the row removes the
  10. # chance to forget one.
  11. model_config = ConfigDict(from_attributes=True)
  12. id: int
  13. archive_id: int | None = None
  14. print_name: str | None = None
  15. printer_name: str | None = None
  16. printer_id: int | None = None
  17. status: str
  18. started_at: datetime | None = None
  19. completed_at: datetime | None = None
  20. duration_seconds: int | None = None
  21. filament_type: str | None = None
  22. filament_color: str | None = None
  23. filament_used_grams: float | None = None
  24. cost: float | None = None
  25. energy_kwh: float | None = None
  26. energy_cost: float | None = None
  27. wear_cost: float | None = None # #694
  28. failure_reason: str | None = None
  29. user_verdict: str | None = None # Post-print quality verdict (#1898)
  30. thumbnail_path: str | None = None
  31. created_by_id: int | None = None
  32. created_by_username: str | None = None
  33. created_at: datetime
  34. class PrintLogResponse(BaseModel):
  35. items: list[PrintLogEntrySchema]
  36. total: int
  37. class PrintLogEntryUpdate(IgnoresNullForRequiredColumns):
  38. """Per-row classification edits (#1687 part 4 — IndividualGhost1905).
  39. Lets the user set ``failure_reason`` (and re-classify ``status``) directly
  40. on a Print Log row, including on orphan entries that have no archive to
  41. edit through. The Failure Analysis widget already groups by
  42. ``PrintLogEntry.failure_reason``, so this just plugs the editor gap.
  43. """
  44. __orm_table__ = "print_log_entries"
  45. failure_reason: str | None = None
  46. status: str | None = None