38 lines
2 KiB
Python
38 lines
2 KiB
Python
"""Table membres."""
|
|
import uuid
|
|
from datetime import datetime, date, timezone
|
|
from sqlalchemy import String, Boolean, Date, DateTime, ForeignKey, JSON, UniqueConstraint
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from app.core.database import Base
|
|
|
|
|
|
class Membre(Base):
|
|
__tablename__ = "membres"
|
|
__table_args__ = (
|
|
UniqueConstraint("courriel", "groupe_id", name="uq_courriel_groupe"),
|
|
)
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(primary_key=True, default=uuid.uuid4)
|
|
groupe_id: Mapped[uuid.UUID] = mapped_column(ForeignKey("groupes.id"), nullable=False)
|
|
prenom: Mapped[str] = mapped_column(String(50), nullable=False)
|
|
nom: Mapped[str | None] = mapped_column(String(50)) # optionnel
|
|
telephone: Mapped[str] = mapped_column(String(20), nullable=False) # obligatoire
|
|
courriel: Mapped[str] = mapped_column(String(100), nullable=False) # identifiant unique
|
|
date_abstinence: Mapped[date | None] = mapped_column(Date)
|
|
pin_hash: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
actif: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
push_sub: Mapped[dict | None] = mapped_column(JSON)
|
|
notification_preferences: Mapped[dict | None] = mapped_column(JSON)
|
|
cree_le: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=lambda: datetime.now(timezone.utc))
|
|
modifie_le: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=lambda: datetime.now(timezone.utc), onupdate=lambda: datetime.now(timezone.utc))
|
|
|
|
groupe = relationship("Groupe", back_populates="membres")
|
|
affectations = relationship("Affectation", back_populates="membre", foreign_keys="Affectation.membre_id")
|
|
|
|
@property
|
|
def is_sysadmin(self) -> bool:
|
|
return (self.courriel or "").strip().lower() == "sysadmin" or bool(getattr(self, "_sysadmin_session", False))
|
|
|
|
@property
|
|
def anonymise(self) -> bool:
|
|
return (self.pin_hash or "") == "SUPPRIME" or (self.courriel or "").startswith("supprime_")
|