Source code for winterthur.layout

from functools import cached_property
from onegov.org.layout import DefaultLayout
from onegov.core.elements import Link, LinkGroup, Intercooler, Confirm, Block
from onegov.winterthur import _
from onegov.winterthur.collections import AddressCollection
from onegov.winterthur.collections import MissionReportCollection
from onegov.winterthur.collections import MissionReportFileCollection
from onegov.winterthur.collections import MissionReportVehicleCollection
from onegov.winterthur.models import MissionReport
from onegov.winterthur.models import MissionReportVehicle
from onegov.winterthur.roadwork import RoadworkCollection


from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from collections.abc import Iterator
    from onegov.winterthur.request import WinterthurRequest
    from typing_extensions import TypeAlias

[docs] MissionReportContext: TypeAlias = ( MissionReport | MissionReportVehicle | MissionReportCollection | MissionReportVehicleCollection | MissionReportFileCollection )
[docs] class AddressLayout(DefaultLayout): @cached_property
[docs] def breadcrumbs(self) -> list[Link]: return [ Link(_("Homepage"), self.homepage_url), Link(_("Addresses"), '#'), ]
@cached_property
[docs] class AddressSubsetLayout(DefaultLayout): @cached_property
[docs] def breadcrumbs(self) -> list[Link]: return [ Link(_("Homepage"), self.homepage_url), Link(_("Addresses"), self.request.class_link(AddressCollection)), Link(_(self.model.street), '#') ]
[docs] class RoadworkCollectionLayout(DefaultLayout): @cached_property
[docs] def breadcrumbs(self) -> list[Link]: return [ Link(_("Homepage"), self.homepage_url), Link(_("Roadworks"), '#'), ]
[docs] class RoadworkLayout(DefaultLayout): @cached_property
[docs] def breadcrumbs(self) -> list[Link]: return [ Link(_("Homepage"), self.homepage_url), Link(_("Roadworks"), self.request.class_link(RoadworkCollection)), Link(self.model.title, self.request.link(self.model)) ]
[docs] class DaycareSubsidyCalculatorLayout(DefaultLayout): @cached_property
[docs] def breadcrumbs(self) -> list[Link]: return [ Link(_("Homepage"), self.homepage_url), Link( _("Daycare Subsidy Calculator"), self.request.link(self.model) ) ]
[docs] class MissionReportLayout(DefaultLayout):
[docs] model: 'MissionReportContext'
def __init__( self, model: 'MissionReportContext', request: 'WinterthurRequest', *suffixes: Link ) -> None: self.suffixes = suffixes super().__init__(model, request) request.include('iframe-enhancements')
[docs] def breadcrumbs_iter(self) -> 'Iterator[Link]': yield Link( _("Homepage"), self.homepage_url) yield Link( _("Mission Reports"), self.request.class_link(MissionReportCollection)) yield from self.suffixes
@cached_property
[docs] def breadcrumbs(self) -> list[Link]: return list(self.breadcrumbs_iter())
@cached_property
[docs] def image_upload_url(self) -> str: if not hasattr(self.model, 'report'): return super().image_upload_url url = self.request.link( MissionReportFileCollection( self.request.session, self.model.report), name='upload') return self.csrf_protected_url(url)
@cached_property
[docs] def image_upload_json_url(self) -> str: if not hasattr(self.model, 'report'): return super().image_upload_json_url url = self.request.link( MissionReportFileCollection( self.request.session, self.model.report), name='upload.json') return self.csrf_protected_url(url)
@cached_property