print_queue.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from datetime import datetime
  2. from typing import Annotated, Literal
  3. from pydantic import BaseModel, PlainSerializer
  4. # Custom serializer to ensure UTC datetimes have Z suffix
  5. def serialize_utc_datetime(dt: datetime | None) -> str | None:
  6. if dt is None:
  7. return None
  8. # Add Z suffix to indicate UTC
  9. return dt.isoformat() + "Z"
  10. UTCDatetime = Annotated[datetime | None, PlainSerializer(serialize_utc_datetime)]
  11. class PrintQueueItemCreate(BaseModel):
  12. printer_id: int
  13. archive_id: int
  14. scheduled_time: datetime | None = None # None = ASAP (next when idle)
  15. require_previous_success: bool = False
  16. auto_off_after: bool = False # Power off printer after print completes
  17. manual_start: bool = False # Requires manual trigger to start (staged)
  18. # AMS mapping: list of global tray IDs for each filament slot
  19. # Format: [5, -1, 2, -1] where position = slot_id-1, value = global tray ID (-1 = unused)
  20. ams_mapping: list[int] | None = None
  21. class PrintQueueItemUpdate(BaseModel):
  22. printer_id: int | None = None
  23. position: int | None = None
  24. scheduled_time: datetime | None = None
  25. require_previous_success: bool | None = None
  26. auto_off_after: bool | None = None
  27. manual_start: bool | None = None
  28. class PrintQueueItemResponse(BaseModel):
  29. id: int
  30. printer_id: int
  31. archive_id: int
  32. position: int
  33. scheduled_time: UTCDatetime
  34. require_previous_success: bool
  35. auto_off_after: bool
  36. manual_start: bool
  37. ams_mapping: list[int] | None = None
  38. status: Literal["pending", "printing", "completed", "failed", "skipped", "cancelled"]
  39. started_at: UTCDatetime
  40. completed_at: UTCDatetime
  41. error_message: str | None
  42. created_at: UTCDatetime
  43. # Nested info for UI (populated in route)
  44. archive_name: str | None = None
  45. archive_thumbnail: str | None = None
  46. printer_name: str | None = None
  47. print_time_seconds: int | None = None # Estimated print time from archive
  48. class Config:
  49. from_attributes = True
  50. class PrintQueueReorderItem(BaseModel):
  51. id: int
  52. position: int
  53. class PrintQueueReorder(BaseModel):
  54. items: list[PrintQueueReorderItem]