core.layout

Module Contents

Classes

Layout

Contains useful methods related to rendering pages in html. Think of it

ChameleonLayout

Extends the base layout class with methods related to chameleon

Attributes

_T

core.layout._T[source]
class core.layout.Layout(model: Any, request: core.request.CoreRequest)[source]

Contains useful methods related to rendering pages in html. Think of it as an API that you can rely on in your templates.

The idea is to provide basic layout functions here, if they are usful for any kind of html application. You should then extend the core layout classes with your own.

property view_name: str | None[source]

Returns the view name of the current view, or None if it is the default view.

Note: This relies on morepath internals and is experimental in nature!

timezone[source]
time_format = 'HH:mm'[source]
date_format = 'dd.MM.yyyy'[source]
datetime_format = 'dd.MM.yyyy HH:mm'[source]
date_long_format = 'dd. MMMM yyyy'[source]
datetime_long_format = 'd. MMMM yyyy HH:mm'[source]
weekday_long_format = 'EEEE'[source]
weekday_short_format = 'E'[source]
month_long_format = 'MMMM'[source]
custom_body_attributes: dict[str, Any][source]
custom_html_attributes: dict[str, Any][source]
app() core.framework.Framework[source]

Returns the application behind the request.

batched(iterable: Iterable[_T], batch_size: int, container_factory: type[tuple] = ...) Iterator[tuple[_T, ...]][source]
batched(iterable: Iterable[_T], batch_size: int, container_factory: type[list]) Iterator[list[_T]]
batched(iterable: Iterable[_T], batch_size: int, container_factory: Callable[[Iterator[_T]], Collection[_T]]) Iterator[Collection[_T]]

See onegov.core.utils.batched().

csrf_token() str[source]

Returns a csrf token for use with DELETE links (forms do their own thing automatically).

csrf_protected_url(url: str) str[source]

Adds a csrf token to the given url.

format_date(dt: datetime | date | None, format: str) str[source]

Takes a datetime and formats it according to local timezone and the given format.

isodate(date: datetime.datetime) str[source]

Returns the given date in the ISO 8601 format.

parse_isodate(string: str) datetime.datetime[source]

Returns the given ISO 8601 string as datetime.

static number_symbols(locale: str) tuple[str, str][source]

Returns the locale specific number symbols.

format_number(number: numbers.Number | Decimal | float | None, decimal_places: int | None = None, padding: str = '') str[source]

Takes the given numer and formats it according to locale.

If the number is an integer, the default decimal places are 0, otherwise 2.

today() datetime.date[source]
now() datetime.datetime[source]
class core.layout.ChameleonLayout(model: Any, request: core.request.CoreRequest)[source]

Bases: Layout

Extends the base layout class with methods related to chameleon template rendering.

This class assumes the existance of two templates:

  • layout.pt -> Contains the page skeleton with headers, body and so on.

  • macros.pt -> Contains chameleon macros.

template_loader() core.templates.TemplateLoader[source]

Returns the chameleon template loader.

base() chameleon.PageTemplateFile[source]

Returns the layout, which defines the base layout of all pages.

See templates/layout.pt.

macros() core.templates.MacrosLookup[source]

Returns the macros, which offer often used html constructs. See templates/macros.pt.

elements() PageTemplate | PageTemplateFile[source]

The templates used by the elements. Overwrite this with your own templates/elements.pt if neccessary.