Source code for feriennet.models.message

from onegov.activity import Period
from onegov.chat import Message
from onegov.org.models.message import TicketMessageMixin


from typing import Any, TYPE_CHECKING
if TYPE_CHECKING:
    from onegov.activity.models import PeriodMeta
    from onegov.feriennet.request import FeriennetRequest
    from onegov.ticket import Ticket
    from typing import Self


[docs] class PeriodMessage(Message):
[docs] __mapper_args__ = { 'polymorphic_identity': 'period' }
@classmethod
[docs] def create( cls, period: 'Period | PeriodMeta', request: 'FeriennetRequest', action: str ) -> 'Self': assert request.current_username, 'reserved for logged-in users' return cls.bound_messages(request.session).add( channel_id=period.id.hex, owner=request.current_username, meta={ 'title': period.title, 'action': action } )
[docs] class ActivityMessage(Message, TicketMessageMixin):
[docs] __mapper_args__ = { 'polymorphic_identity': 'activity' }
@classmethod
[docs] def create( # type:ignore[override] cls, ticket: 'Ticket', request: 'FeriennetRequest', action: str, **extra_meta: Any ) -> 'Self': # FIXME: This used to pass a scalar extra_meta=extra_meta # so it's possible there are some messages where the # extra_meta is now nested inside .meta['extra_meta'] # if so we should fix this with a migration return super().create(ticket, request, action=action, **extra_meta)