print_log.py 1.9 KB

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