print_log.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. plate_id: int | None = None
  16. printer_name: str | None = None
  17. printer_id: int | None = None
  18. status: str
  19. started_at: datetime | None = None
  20. completed_at: datetime | None = None
  21. duration_seconds: int | None = None
  22. filament_type: str | None = None
  23. filament_color: str | None = None
  24. filament_used_grams: float | None = None
  25. cost: float | None = None
  26. energy_kwh: float | None = None
  27. energy_cost: float | None = None
  28. wear_cost: float | None = None # #694
  29. failure_reason: str | None = None
  30. user_verdict: str | None = None # Post-print quality verdict (#1898)
  31. user_verdict_source: str | None = None
  32. confirm_requested: bool | None = None
  33. duration_unmeasured: bool | None = None
  34. quantity: int | None = None
  35. # This print's own (archive redesign): its note, its finish photos (served
  36. # by the archive's photo route) and its video (the run's timelapse route).
  37. notes: str | None = None
  38. photos: list[str] | None = None
  39. timelapse_path: str | None = None
  40. thumbnail_path: str | None = None
  41. created_by_id: int | None = None
  42. created_by_username: str | None = None
  43. created_at: datetime
  44. class PrintLogResponse(BaseModel):
  45. items: list[PrintLogEntrySchema]
  46. total: int
  47. # The print log only: archives of these prints that were deleted, whose
  48. # prints stay logged (#1343) but have no archive page to open.
  49. deleted_archive_ids: list[int] = []
  50. class PrintLogEntryUpdate(IgnoresNullForRequiredColumns):
  51. """Per-row classification edits (#1687 part 4 — IndividualGhost1905).
  52. Lets the user set ``failure_reason`` (and re-classify ``status``) directly
  53. on a Print Log row, including on orphan entries that have no archive to
  54. edit through. The Failure Analysis widget already groups by
  55. ``PrintLogEntry.failure_reason``, so this just plugs the editor gap.
  56. """
  57. __orm_table__ = "print_log_entries"
  58. failure_reason: str | None = None
  59. status: str | None = None
  60. # The print's own note, beside the archive's (the file's) note.
  61. notes: str | None = None