printer_location.py 1.4 KB

123456789101112131415161718192021222324252627282930
  1. from datetime import datetime
  2. from sqlalchemy import DateTime, String, func
  3. from sqlalchemy.orm import Mapped, mapped_column
  4. from backend.app.core.database import Base
  5. class PrinterLocation(Base):
  6. """A printer location (group) and how it looks (#2962).
  7. A printer's location is still the free-text ``printers.location`` column,
  8. which the scheduler's model-based targeting and the printers filter match
  9. exactly. This table only adds what that column cannot hold: a location with
  10. no printers yet (a rack or room planned before the printers move in), and
  11. the icon and colour the Printer Locations page shows for it. A location used
  12. by printers but missing here is still a location, with no icon or colour.
  13. """
  14. __tablename__ = "printer_locations"
  15. id: Mapped[int] = mapped_column(primary_key=True)
  16. # Same width as printers.location, which holds the same value.
  17. name: Mapped[str] = mapped_column(String(100), nullable=False, unique=True)
  18. # An IconPicker name ("home", "wrench"); None shows the default icon.
  19. icon: Mapped[str | None] = mapped_column(String(50))
  20. # "#rrggbb"; None means no colour.
  21. color: Mapped[str | None] = mapped_column(String(7))
  22. created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
  23. updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now())