Source code for election_day.models.subscriber

from __future__ import annotations

from datetime import datetime
from onegov.core.orm import Base
from onegov.core.orm.mixins import TimestampMixin
from sqlalchemy.orm import mapped_column
from sqlalchemy.orm import Mapped
from uuid import uuid4, UUID


[docs] class Subscriber(Base, TimestampMixin): """ Stores subscribers for the notifications """
[docs] __tablename__ = 'subscribers'
#: the type of the item, this can be used to create custom polymorphic #: subclasses of this class. See #: `<https://docs.sqlalchemy.org/en/improve_toc/\ #: orm/extensions/declarative/inheritance.html>`_.
[docs] type: Mapped[str] = mapped_column(default=lambda: 'generic')
[docs] __mapper_args__ = { 'polymorphic_on': type, 'polymorphic_identity': 'generic' }
#: Identifies the subscriber
[docs] id: Mapped[UUID] = mapped_column( primary_key=True, default=uuid4 )
#: The address of the subscriber, e.g. the phone number or the email #: address.
[docs] address: Mapped[str]
#: The locale used by the subscriber
[docs] locale: Mapped[str]
#: True, if the subscriber has been confirmed
[docs] active: Mapped[bool | None]
#: The domain of the election compound part.
[docs] domain: Mapped[str | None]
#: The domain segment of the election compound part.
[docs] domain_segment: Mapped[str | None]
#: When has this subscriber last been (explicitly) activated.
[docs] active_since: Mapped[datetime | None]
#: When has this subscriber last been (explicitly) deactivated.
[docs] inactive_since: Mapped[datetime | None]
[docs] class SmsSubscriber(Subscriber):
[docs] __mapper_args__ = {'polymorphic_identity': 'sms'}
[docs] class EmailSubscriber(Subscriber):
[docs] __mapper_args__ = {'polymorphic_identity': 'email'}