Source code for landsgemeinde.models.assembly

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 UTCDateTime
from onegov.core.orm.types import UUID
from onegov.file import AssociatedFiles
from onegov.file import NamedFile
from onegov.landsgemeinde import _
from onegov.landsgemeinde.models.agenda import AgendaItem
from onegov.landsgemeinde.models.file import LandsgemeindeFile
from onegov.landsgemeinde.models.mixins import StartTimeMixin
from onegov.search import ORMSearchable
from sqlalchemy import Boolean
from sqlalchemy import Column
from sqlalchemy import Date
from sqlalchemy import Enum
from sqlalchemy import Text
from sqlalchemy.orm import relationship
from uuid import uuid4


from typing import Literal
from typing import TYPE_CHECKING
if TYPE_CHECKING:
    import uuid
    from datetime import date as date_t
    from datetime import datetime
    from translationstring import TranslationString
    from typing import TypeAlias

[docs] AssemblyState: TypeAlias = Literal['scheduled', 'ongoing', 'completed']
[docs] STATES: dict['AssemblyState', 'TranslationString'] = { 'scheduled': _('scheduled'), 'ongoing': _('ongoing'), 'completed': _('completed') }
[docs] class Assembly( Base, ContentMixin, TimestampMixin, AssociatedFiles, ORMSearchable, StartTimeMixin ):
[docs] __tablename__ = 'landsgemeinde_assemblies'
[docs] es_public = True
[docs] es_properties = { 'overview': {'type': 'localized_html'}, }
@property
[docs] def es_suggestion(self) -> tuple[str, ...]: return ( str(self.date.year), f'Landsgemeinde {self.date.year}', )
#: Internal number of the event
[docs] id: 'Column[uuid.UUID]' = Column( UUID, # type:ignore[arg-type] primary_key=True, default=uuid4 )
#: the state of the assembly
[docs] state: 'Column[AssemblyState]' = Column( Enum(*STATES.keys(), name='assembly_state'), # type:ignore[arg-type] nullable=False )
#: The date of the assembly
[docs] date: 'Column[date_t]' = Column(Date, nullable=False, unique=True)
#: True if this is an extraordinary assembly
[docs] extraordinary: 'Column[bool]' = Column( Boolean, nullable=False, default=False )
#: The video URL of the assembly
[docs] video_url: 'Column[str | None]' = Column(Text, nullable=True)
#: The memorial of the assembly
[docs] memorial_pdf = NamedFile(cls=LandsgemeindeFile)
#: An optional second part of the memorial of the assembly
[docs] memorial_2_pdf = NamedFile(cls=LandsgemeindeFile)
#: The supplement to the memorial of the assembly
[docs] memorial_supplement_pdf = NamedFile(cls=LandsgemeindeFile)
#: The protocol of the assembly
[docs] protocol_pdf = NamedFile(cls=LandsgemeindeFile)
#: The audio of the assembly as MP3
[docs] audio_mp3 = NamedFile(cls=LandsgemeindeFile)
#: The audio of the assembly as ZIP
[docs] audio_zip = NamedFile(cls=LandsgemeindeFile)
#: The overview (text) over the assembly
[docs] overview = dict_markup_property('content')
#: An assembly contains n agenda items
[docs] agenda_items: 'relationship[list[AgendaItem]]' = relationship( AgendaItem, cascade='all, delete-orphan', back_populates='assembly', order_by='AgendaItem.number', )
[docs] last_modified: 'Column[datetime | None]' = Column(UTCDateTime)
[docs] def stamp(self) -> None: self.last_modified = self.timestamp()