Source code for pas.models.commission_membership

from onegov.core.orm import Base
from onegov.core.orm.mixins import TimestampMixin
from onegov.core.orm.types import UUID
from onegov.pas import _
from onegov.pas.models.commission import Commission
from onegov.pas.models.parliamentarian import Parliamentarian
from sqlalchemy import Column
from sqlalchemy import Date
from sqlalchemy import Enum
from sqlalchemy import ForeignKey
from sqlalchemy.orm import relationship
from uuid import uuid4

from typing import TYPE_CHECKING
    import uuid
    from datetime import date
    from typing import Literal
    from typing_extensions import TypeAlias

[docs] MembershipRole: TypeAlias = Literal[ 'guest', 'member', 'extended_member', 'president', ]
[docs] ROLES: dict['MembershipRole', str] = { 'guest': _('Guest'), 'member': _('Member'), 'extended_member': _('Extended Member'), 'president': _('President') }
[docs] class CommissionMembership(Base, TimestampMixin):
[docs] __tablename__ = 'pas_commission_memberships'
#: Internal ID
[docs] id: 'Column[uuid.UUID]' = Column( UUID, # type:ignore[arg-type] primary_key=True, default=uuid4 )
#: The start date
[docs] start: 'Column[date|None]' = Column( Date, nullable=True )
#: The end date
[docs] end: 'Column[date|None]' = Column( Date, nullable=True )
#: The role value
[docs] role: 'Column[MembershipRole]' = Column( Enum( *ROLES.keys(), # type:ignore[arg-type] name='pas_commission_membership_role' ), nullable=False, default='member' )
#: The role as translated text @property
[docs] def role_label(self) -> str: return ROLES.get(self.role, '')
#: the id of the commission
[docs] commission_id: 'Column[uuid.UUID]' = Column( UUID, # type:ignore[arg-type] ForeignKey(''), nullable=False )
#: the related commission (which may have any number of memberships)
[docs] commission: 'relationship[Commission]' = relationship( Commission, back_populates='memberships' )
#: the id of the parliamentarian
[docs] parliamentarian_id: 'Column[uuid.UUID]' = Column( UUID, # type:ignore[arg-type] ForeignKey(''), nullable=False )
#: the related parliamentarian (which may have any number of memberships)
[docs] parliamentarian: 'relationship[Parliamentarian]' = relationship( Parliamentarian, back_populates='commission_memberships' )