Source code for landsgemeinde.models.votum

from onegov.core.orm import Base
from onegov.core.orm.mixins import ContentMixin
from onegov.core.orm.mixins import dict_markup_property
from onegov.core.orm.mixins import TimestampMixin
from onegov.core.orm.types import UUID
from onegov.file import AssociatedFiles
from onegov.landsgemeinde import _
from onegov.landsgemeinde.models.mixins import TimestampedVideoMixin
from onegov.search import ORMSearchable
from sqlalchemy import Column
from sqlalchemy import Enum
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
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 as date_t
    from onegov.landsgemeinde.models import AgendaItem
    from onegov.landsgemeinde.models import Assembly
    from translationstring import TranslationString
    from typing import Literal
    from typing import TypeAlias

[docs] VotumState: TypeAlias = Literal['scheduled', 'ongoing', 'completed']
[docs] STATES: dict['VotumState', 'TranslationString'] = { 'scheduled': _('scheduled'), 'ongoing': _('ongoing'), 'completed': _('completed') }
[docs] class Votum( Base, ContentMixin, TimestampMixin, AssociatedFiles, ORMSearchable, TimestampedVideoMixin ):
[docs] __tablename__ = 'landsgemeinde_vota'
[docs] es_public = True
[docs] es_properties = { 'text': {'type': 'localized_html'}, 'motion': {'type': 'localized_html'}, 'statement_of_reasons': {'type': 'localized_html'}, 'person_name': {'type': 'text'}, 'person_function': {'type': 'text'}, 'person_place': {'type': 'text'}, 'person_political_affiliation': {'type': 'text'}, }
@property
[docs] def es_suggestion(self) -> tuple[str, ...]: return ()
#: the internal id of the votum
[docs] id: 'Column[uuid.UUID]' = Column( UUID, # type:ignore[arg-type] primary_key=True, default=uuid4 )
#: the state of the votum
[docs] state: 'Column[VotumState]' = Column( Enum(*STATES.keys(), name='votum_item_state'), # type:ignore[arg-type] nullable=False )
#: the external id of the agenda item
[docs] number: 'Column[int]' = Column(Integer, nullable=False)
#: The main text of the votum
[docs] text = dict_markup_property('content')
#: Motion of the votum
[docs] motion = dict_markup_property('content')
#: Statement of reasons of the votum
[docs] statement_of_reasons = dict_markup_property('content')
#: The name of the person
[docs] person_name: 'Column[str | None]' = Column(Text, nullable=True)
#: The function of the person
[docs] person_function: 'Column[str | None]' = Column(Text, nullable=True)
#: The place of the person
[docs] person_place: 'Column[str | None]' = Column(Text, nullable=True)
#: The political affiliation of the person (party or parliamentary group)
[docs] person_political_affiliation: 'Column[str | None]' = Column( Text, nullable=True )
#: A picture of the person
[docs] person_picture: 'Column[str | None]' = Column(Text, nullable=True)
#: the agenda this votum belongs to
[docs] agenda_item_id: 'Column[uuid.UUID]' = Column( UUID, # type:ignore[arg-type] ForeignKey( 'landsgemeinde_agenda_items.id', onupdate='CASCADE', ondelete='CASCADE' ), nullable=False )
[docs] agenda_item: 'relationship[AgendaItem]' = relationship( 'AgendaItem', back_populates='vota', )
@property
[docs] def date(self) -> 'date_t': return self.agenda_item.date
@property
[docs] def agenda_item_number(self) -> int: return self.agenda_item.number
@property
[docs] def assembly(self) -> 'Assembly': # type:ignore[override] return self.agenda_item.assembly
@property
[docs] def person_details(self) -> str: details = ( self.person_function, self.person_political_affiliation, self.person_place ) return ', '.join(d for d in details if d)