from onegov.core.orm import Base
from onegov.core.orm.mixins import TimestampMixin
from onegov.core.orm.types import UTCDateTime
from onegov.core.orm.types import UUID
from sqlalchemy import Boolean
from sqlalchemy import Column
from sqlalchemy import Text
from uuid import uuid4
from typing import TYPE_CHECKING
if TYPE_CHECKING:
import uuid
from datetime import datetime
[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: 'Column[str]' = Column(
Text,
nullable=False,
default=lambda: 'generic'
)
[docs]
__mapper_args__ = {
'polymorphic_on': type,
'polymorphic_identity': 'generic'
}
#: Identifies the subscriber
[docs]
id: 'Column[uuid.UUID]' = Column(
UUID, # type:ignore[arg-type]
primary_key=True,
default=uuid4
)
#: The address of the subscriber, e.g. the phone number or the email
#: address.
[docs]
address: 'Column[str]' = Column(Text, nullable=False)
#: The locale used by the subscriber
[docs]
locale: 'Column[str]' = Column(Text, nullable=False)
#: True, if the subscriber has been confirmed
[docs]
active: 'Column[bool | None]' = Column(Boolean, nullable=True)
#: The domain of the election compound part.
[docs]
domain: 'Column[str | None]' = Column(Text, nullable=True)
#: The domain segment of the election compound part.
[docs]
domain_segment: 'Column[str | None]' = Column(Text, nullable=True)
#: When has this subscriber last been (explicitly) activated.
[docs]
active_since: 'Column[datetime | None]' = Column(
UTCDateTime,
nullable=True
)
#: When has this subscriber last been (explicitly) deactivated.
[docs]
inactive_since: 'Column[datetime | None]' = Column(
UTCDateTime,
nullable=True
)
[docs]
class SmsSubscriber(Subscriber):
[docs]
__mapper_args__ = {'polymorphic_identity': 'sms'}
[docs]
class EmailSubscriber(Subscriber):
[docs]
__mapper_args__ = {'polymorphic_identity': 'email'}