from __future__ import annotations
from onegov.core.orm import Base
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 uuid import uuid4
from typing import TYPE_CHECKING
if TYPE_CHECKING:
import uuid
from datetime import date
[docs]
class LegislativePeriod(Base, TimestampMixin, ORMSearchable):
[docs]
__tablename__ = 'par_legislative_periods'
[docs]
fts_type_title = _('Legislative periods')
[docs]
fts_properties = {'name': {'type': 'text', 'weight': 'A'}}
@property
[docs]
def fts_suggestion(self) -> str:
return self.name
#: The polymorphic type of legislative period
[docs]
type: Column[str] = Column(
Text,
nullable=False,
default=lambda: 'generic'
)
[docs]
__mapper_args__ = {
'polymorphic_on': type,
'polymorphic_identity': 'pas_legislative_period',
}
@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 start date
[docs]
start: Column[date] = Column(
Date,
nullable=False
)
#: The end date
[docs]
end: Column[date] = Column(
Date,
nullable=False
)
#: The name
[docs]
name: Column[str] = Column(
Text,
nullable=False
)