Source code for pas.models.party

from __future__ import annotations

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.i18n import _
from onegov.search import ORMSearchable
from sqlalchemy import Column
from sqlalchemy import Date
from sqlalchemy import Text
from sqlalchemy.orm import relationship
from uuid import uuid4


from typing import TYPE_CHECKING
if TYPE_CHECKING:
    import uuid
    from datetime import date
    from onegov.pas.models import PASParliamentarianRole


[docs] class Party(Base, ContentMixin, TimestampMixin, ORMSearchable):
[docs] __tablename__ = 'par_parties'
[docs] fts_type_title = _('Parties')
[docs] fts_public = False
[docs] fts_properties = {'name': {'type': 'text', 'weight': 'A'}}
#: The polymorphic type of party
[docs] type: Column[str] = Column( Text, nullable=False, default=lambda: 'generic' )
[docs] __mapper_args__ = { 'polymorphic_on': type, 'polymorphic_identity': 'pas_party', }
@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 )
#: External ID
[docs] external_kub_id: Column[uuid.UUID | None] = Column( UUID, # type:ignore[arg-type] nullable=True, default=uuid4, unique=True )
#: 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 portrait
[docs] portrait = dict_markup_property('content')
#: The description
[docs] description = dict_markup_property('content')
#: A party may have n roles
[docs] roles: relationship[list[PASParliamentarianRole]]
roles = relationship( 'PASParliamentarianRole', cascade='all, delete-orphan', back_populates='party' )
[docs] def __repr__(self) -> str: return f'<Party {self.name}>'