label_template.py 1.6 KB

12345678910111213141516171819202122232425262728293031
  1. from datetime import datetime
  2. from sqlalchemy import DateTime, Float, Integer, String, func
  3. from sqlalchemy.orm import Mapped, mapped_column
  4. from backend.app.core.database import Base
  5. class LabelTemplate(Base):
  6. """A custom label sheet saved under a name (#3296). Shared by everyone on
  7. the install, like storage locations. Lengths are in millimetres."""
  8. __tablename__ = "label_templates"
  9. id: Mapped[int] = mapped_column(primary_key=True)
  10. name: Mapped[str] = mapped_column(String(100), nullable=False)
  11. # Uniqueness ignoring case and Unicode composition: "Avery 3490" and
  12. # "avery 3490" are one template. Casefolding can lengthen a name up to
  13. # three times, hence the wider column (schemas.label_template).
  14. name_key: Mapped[str] = mapped_column(String(300), nullable=False, unique=True, index=True)
  15. page: Mapped[str] = mapped_column(String(10), nullable=False)
  16. label_w_mm: Mapped[float] = mapped_column(Float, nullable=False)
  17. label_h_mm: Mapped[float] = mapped_column(Float, nullable=False)
  18. cols: Mapped[int] = mapped_column(Integer, nullable=False)
  19. rows: Mapped[int] = mapped_column(Integer, nullable=False)
  20. top_mm: Mapped[float] = mapped_column(Float, nullable=False)
  21. left_mm: Mapped[float] = mapped_column(Float, nullable=False)
  22. col_gap_mm: Mapped[float] = mapped_column(Float, nullable=False, default=0.0)
  23. row_gap_mm: Mapped[float] = mapped_column(Float, nullable=False, default=0.0)
  24. created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
  25. updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now())