Source code for

from import AgencyApiEndpoint
from import MembershipApiEndpoint
from import PersonApiEndpoint
from import get_global_tools
from import get_top_navigation
from import UserGroupForm
from import create_new_organisation
from import AgencyPdfAr, AgencyPdfBs
from import AgencyPdfDefault
from import AgencyPdfZg
from import AgencyRequest
from import AgencyTheme
from onegov.api import ApiApp
from onegov.core import utils
from import OrgApp
from import get_editor_asset as editor_assets
from import get_i18n_localedirs as get_org_i18n_localedirs
from import get_redactor_asset as redactor_assets

from typing import Any
from typing import TYPE_CHECKING
    from _typeshed import SupportsRead
    from import Callable
    from import Iterator
    from datetime import datetime
    from fs.base import FS
    from fs.base import SubFS
    from onegov.api import ApiEndpoint
    from onegov.core.types import RenderData
    from import Organisation

[docs] class AgencyApp(OrgApp, ApiApp):
[docs] request_class = AgencyRequest
if TYPE_CHECKING: # FIXME: Maybe we should consider just raising an exception # if filestorage is accesed without it being configured @property def filestorage(self) -> SubFS[FS]: ... @property
[docs] def root_pdf_exists(self) -> bool: return self.filestorage.exists('root.pdf')
[docs] def people_xlsx_exists(self) -> bool: return self.filestorage.exists('people.xlsx')
[docs] def root_pdf_modified(self) -> 'datetime | None': if self.root_pdf_exists: return self.filestorage.getdetails('root.pdf').modified return None
[docs] def people_xlsx_modified(self) -> 'datetime | None': if self.people_xlsx: return self.filestorage.getdetails('people.xlsx').modified return None
[docs] def root_pdf(self) -> bytes | None: result: bytes | None = None if self.filestorage.exists('root.pdf'): with'root.pdf', 'rb') as file: # FS bug with mode=rb result = # type:ignore[assignment] return result
# FIXME: asymmetric property @root_pdf.setter def root_pdf(self, value: 'SupportsRead[bytes] | bytes') -> None: with'root.pdf', 'wb') as file: if hasattr(value, 'read'): value = # FS bug with mode=wb file.write(value) # type:ignore @property
[docs] def people_xlsx(self) -> bytes | None: result: bytes | None = None if self.filestorage.exists('people.xlsx'): with'people.xlsx', 'rb') as file: # FS bug with mode=rb result = # type:ignore[assignment] return result
# FIXME: asymmetric property @people_xlsx.setter def people_xlsx(self, value: 'SupportsRead[bytes] | bytes') -> None: with'people.xlsx', 'wb') as file: if hasattr(value, 'read'): value = # FS bug with mode=wb file.write(value) # type:ignore @property
[docs] def pdf_class(self) -> type[AgencyPdfDefault]: pdf_layout ='pdf_layout') if pdf_layout == 'ar': return AgencyPdfAr if pdf_layout == 'zg': return AgencyPdfZg if pdf_layout == 'bs': return AgencyPdfBs return AgencyPdfDefault
[docs] def enable_yubikey(self) -> bool: return'enable_yubikey', self._enable_yubikey)
@enable_yubikey.setter def enable_yubikey(self, value: bool) -> None: self._enable_yubikey = value
@AgencyApp.setting(section='org', name='create_new_organisation')
[docs] def get_create_new_organisation_factory( ) -> 'Callable[[AgencyApp, str], Organisation]': return create_new_organisation
[docs] def get_template_directory() -> str: return 'templates'
[docs] def get_template_variables(request: AgencyRequest) -> 'RenderData': return { 'global_tools': tuple(get_global_tools(request)), 'top_navigation': tuple(get_top_navigation(request)), }
@AgencyApp.setting(section='core', name='theme')
[docs] def get_theme() -> AgencyTheme: return AgencyTheme()
@AgencyApp.setting(section='org', name='usergroup_form_class')
[docs] def get_usergroup_form_class() -> type[UserGroupForm]: return UserGroupForm
@AgencyApp.setting(section='i18n', name='localedirs')
[docs] def get_i18n_localedirs() -> list[str]: mine = utils.module_path('', 'locale') return [mine] + get_org_i18n_localedirs()
@AgencyApp.setting(section='org', name='ticket_manager_roles')
[docs] def get_ticket_manager_roles() -> tuple[str, ...]: return ('admin', 'editor', 'member')
@AgencyApp.setting(section='org', name='disabled_extensions')
[docs] def get_disabled_extensions() -> tuple[str, ...]: return ('PersonLinkExtension', )
[docs] def get_webasset_output() -> str: return 'assets/bundles'
[docs] def get_js_path() -> str: return 'assets/js'
[docs] def get_people_select_asset() -> 'Iterator[str]': yield 'people-select.js'
[docs] def get_sortable_multi_checkbox_asset() -> 'Iterator[str]': yield 'jquery.js' yield 'sortable.js' yield 'sortable-multi-checkbox.js'
@AgencyApp.webasset('redactor', filters={'js': None})
[docs] def get_redactor_asserts() -> 'Iterator[str]': yield from redactor_assets()
[docs] def get_editor_assets() -> 'Iterator[str]': yield from editor_assets()
@AgencyApp.setting(section='api', name='endpoints')
[docs] def get_api_endpoints() -> list[type['ApiEndpoint[Any]']]: return [ AgencyApiEndpoint, PersonApiEndpoint, MembershipApiEndpoint ]