from functools import cached_property
from onegov.core.static import StaticFile
from onegov.landsgemeinde import _
from onegov.landsgemeinde.collections import AssemblyCollection
from onegov.town6.layout import DefaultLayout as BaseDefaultLayout
from onegov.landsgemeinde.models import Assembly
from typing import Any
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from onegov.landsgemeinde.models import AgendaItem
from onegov.landsgemeinde.models import Votum
from onegov.landsgemeinde.request import LandsgemeindeRequest
[docs]
class DefaultLayout(BaseDefaultLayout):
[docs]
request: 'LandsgemeindeRequest'
def __init__(self, model: Any, request: 'LandsgemeindeRequest') -> None:
super().__init__(model, request)
self.custom_body_attributes['data-websocket-endpoint'] = ''
self.custom_body_attributes['data-websocket-schema'] = ''
self.custom_body_attributes['data-websocket-channel'] = ''
[docs]
def assembly_title(self, assembly: Assembly) -> str:
if assembly.extraordinary:
return _(
'Extraodinary assembly from ${date}',
mapping={'date': self.format_date(assembly.date, 'date_long')}
)
return _(
'Assembly from ${date}',
mapping={'date': self.format_date(assembly.date, 'date_long')}
)
[docs]
def agenda_item_title(
self,
agenda_item: 'AgendaItem',
short: bool = False
) -> str:
if agenda_item.irrelevant:
if agenda_item.title:
return agenda_item.title
return self.request.translate(_('Irrelevant motion'))
if not agenda_item.title or short:
return '{} {}'.format(
self.request.translate(_('Agenda item')),
agenda_item.number
)
return '{} {}: {}'.format(
self.request.translate(_('Agenda item')),
agenda_item.number,
agenda_item.title
)
[docs]
def votum_title(self, votum: 'Votum') -> str:
return '{} {}'.format(
self.request.translate(_('Votum')),
votum.number
)
[docs]
def assembly_collection(self) -> AssemblyCollection:
return AssemblyCollection(self.request.session)
[docs]
def current_assembly(self) -> Assembly | None:
return AssemblyCollection(self.request.session).query().filter(
Assembly.state == 'ongoing').order_by(
Assembly.date.desc()).first()
@cached_property
[docs]
def terms_icon(self) -> str:
static_file = StaticFile.from_application(
self.app, 'terms_by.svg'
)
return self.request.link(static_file)