Source code for pas.models.commission

from onegov.core.orm import Base
from onegov.core.orm.mixins import dict_markup_property
from onegov.core.orm.mixins import ContentMixin
from onegov.core.orm.mixins import TimestampMixin
from onegov.core.orm.types import UUID
from onegov.pas import _
from onegov.search import ORMSearchable
from sqlalchemy import Column
from sqlalchemy import Date
from sqlalchemy import Text
from onegov.core.orm import observes
from uuid import uuid4
from sqlalchemy import Enum
from sqlalchemy.orm import relationship


from typing import TYPE_CHECKING
if TYPE_CHECKING:
    import uuid
    from datetime import date
    from onegov.pas.models.attendence import Attendence
    from onegov.pas.models.commission_membership import CommissionMembership
    from typing import Literal
    from typing import TypeAlias

[docs] CommissionType: TypeAlias = Literal[ 'normal', 'intercantonal', 'official', ]
[docs] TYPES: dict['CommissionType', str] = { 'normal': _('normal'), 'intercantonal': _('intercantonal'), 'official': _('official mission'), }
[docs] class Commission(Base, ContentMixin, TimestampMixin, ORMSearchable):
[docs] __tablename__ = 'pas_commissions'
[docs] es_public = False
[docs] es_properties = {'name': {'type': 'text'}}
@property
[docs] def es_suggestion(self) -> str: return self.name
@property
[docs] def title(self) -> str: return self.name
#: Internal ID
[docs] id: 'Column[uuid.UUID]' = Column( UUID, # type:ignore[arg-type] primary_key=True, default=uuid4 )
#: the name
[docs] name: 'Column[str]' = Column( Text, nullable=False )
#: 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 type value
[docs] type: 'Column[CommissionType]' = Column( Enum( *TYPES.keys(), # type:ignore[arg-type] name='pas_commission_type' ), nullable=False, default='normal' )
#: The type as translated text @property
[docs] def type_label(self) -> str: return TYPES.get(self.type, '')
#: The description
[docs] description = dict_markup_property('content')
#: A commission may have n parliamentarians
[docs] memberships: 'relationship[list[CommissionMembership]]'
memberships = relationship( 'CommissionMembership', cascade='all, delete-orphan', back_populates='commission' ) #: A commission may hold meetings
[docs] attendences: 'relationship[list[Attendence]]' = relationship( 'Attendence', cascade='all, delete-orphan', back_populates='commission' )
@observes('end')
[docs] def end_observer(self, end: 'date | None') -> None: if end: for membership in self.memberships: if not membership.end: membership.end = end
[docs] def __repr__(self) -> str: return f'<Commission {self.name}>'