from sqlalchemy.orm import DeclarativeBase, Mapped, declared_attr, mapped_column from ..utils.password_helper import password_helper class Base(DeclarativeBase): """Base from DeclarativeBase""" pass class CommonMixin: """ CommonMixin for all common fields in projetc """ @declared_attr.directive def __tablename__(cls) -> str: """__tablename__. :rtype: str """ return cls.__name__.lower() # type: ignore id: Mapped[int] = mapped_column(primary_key=True) class PasswordMixin: """ PasswordMixin for entities with password """ hashed_password: Mapped[str] def set_password(self, password: str) -> None: self.hashed_password = password_helper.hash(password) def verify_password(self, password: str) -> bool: return password_helper.verify(password, self.hashed_password)