Source code for gazette.models.principal

from yaml import safe_load


from typing import Any
from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from typing import Self


[docs] class Principal: """ The principal is the political entity running the gazette app. """
[docs] CANTONS = { 'ag', 'ai', 'ar', 'be', 'bl', 'bs', 'fr', 'ge', 'gl', 'gr', 'ju', 'lu', 'ne', 'nw', 'ow', 'sg', 'sh', 'so', 'sz', 'tg', 'ti', 'ur', 'vd', 'vs', 'zg', 'zh' }
def __init__( self, name: str = '', logo: str = '', logo_for_pdf: str = '', color: str = '', canton: str | None = None, on_accept: dict[str, Any] | None = None, time_zone: str = 'Europe/Zurich', help_link: str = '', publishing: bool = False, frontend: bool = False, sogc_import: dict[str, Any] | None = None, links: dict[str, str] | None = None, **kwargs: object ) -> None: assert not canton or canton in self.CANTONS assert not on_accept or on_accept['mail_to'] assert not frontend or (frontend and publishing) assert not links or isinstance(links, dict) assert not sogc_import or ( sogc_import['endpoint'] and sogc_import['category'] and sogc_import['organization'] and canton )
[docs] self.canton = canton
[docs] self.name = name
[docs] self.logo_for_pdf = logo_for_pdf
[docs] self.color = color
[docs] self.on_accept = on_accept or {}
[docs] self.time_zone = time_zone
[docs] self.publishing = publishing
[docs] self.frontend = frontend
[docs] self.sogc_import = sogc_import or {}
if self.sogc_import and canton: self.sogc_import['canton'] = canton.upper() @classmethod
[docs] def from_yaml(cls, yaml_source: str) -> 'Self': return cls(**safe_load(yaml_source))