betty.jinja2.filter module - Betty 0.4.0a3 documentation

Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# betty.jinja2.filter module

Provide Betty’s default Jinja2 filters.

async betty.jinja2.filter.filter_file(context: Context, file: File) → str

  Preprocess a file for use in a page.

  Return type:

    `str`

  Returns:

    The public path to the preprocessed file. This can be used on a web page.

  Parameters:

    - context (`jinja2.runtime.Context`)

    - file (`betty.model.ancestry.File`)

async betty.jinja2.filter.filter_flatten(values_of_values: Iterable[Iterable[betty.jinja2.filter._T]]) → AsyncIterator[betty.jinja2.filter._T]

  Flatten an iterable of iterables into a single iterable.

  Parameters:

    values_of_values (`typing.Iterable`[`typing.Iterable`[`typing.TypeVar`(`_T`)]])

  Return type:

    `typing.AsyncIterator`[`typing.TypeVar`(`_T`)]

betty.jinja2.filter.filter_format_datey(context: jinja2.runtime.Context, datey: betty.locale.Date | betty.locale.DateRange) → str

  Format a date or a date range.

  Parameters:

    - context (`jinja2.runtime.Context`)

    - datey (`betty.locale.Date` | `betty.locale.DateRange`)

  Return type:

    `str`

betty.jinja2.filter.filter_format_degrees(degrees: int) → str

  Format geographic coordinates.

  Parameters:

    degrees (`int`)

  Return type:

    `str`

betty.jinja2.filter.filter_hashid(source: str) → str

  Create a hash ID.

  Parameters:

    source (`str`)

  Return type:

    `str`

async betty.jinja2.filter.filter_image(context: jinja2.runtime.Context, file: betty.model.ancestry.File, size: tuple[int, None] | tuple[None, int] | tuple[int, int] | None = None) → str

  Preprocess an image file for use in a page.

  Return type:

    `str`

  Returns:

    The public path to the preprocessed file. This can be embedded in a web page.

  Parameters:

    - context (`jinja2.runtime.Context`)

    - file (`betty.model.ancestry.File`)

    - size (`tuple`[`int`, `None`] | `tuple`[`None`, `int`] | `tuple`[`int`, `int`] | `None`)

betty.jinja2.filter.filter_json(data: Any, indent: int | None = None) → str

  Convert a value to a JSON string.

  Parameters:

    - data (`typing.Any`)

    - indent (`int` | `None`)

  Return type:

    `str`

betty.jinja2.filter.filter_localize(context: jinja2.runtime.Context, localizable: betty.locale.localizable.Localizable) → str

  Localize a value using the context’s current localizer.

  Parameters:

    - context (`jinja2.runtime.Context`)

    - localizable (`betty.locale.localizable.Localizable`)

  Return type:

    `str`

async betty.jinja2.filter.filter_map(context: jinja2.runtime.Context, values: Iterable[Any], *args: Any, **kwargs: Any) → Any

  Map an iterable’s values.

  This mimics Jinja2’s built-in map filter, but allows macros as callbacks.

  Parameters:

    - context (`jinja2.runtime.Context`)

    - values (`typing.Iterable`[`typing.Any`])

    - args (`typing.Any`)

    - kwargs (`typing.Any`)

  Return type:

    `typing.Any`

betty.jinja2.filter.filter_negotiate_dateds(context: jinja2.runtime.Context, dateds: Iterable[betty.model.ancestry.Dated], date: betty.locale.Date | betty.locale.DateRange | None) → betty.model.ancestry.Dated | None

  Try to find an object whose date falls in the given date.

  Parameters:

    - date (`betty.locale.Date` | `betty.locale.DateRange` | `None`) – A date to select by. If None, then today’s date is used.

    - context (`jinja2.runtime.Context`)

    - dateds (`typing.Iterable`[`betty.model.ancestry.Dated`])

  Return type:

    `betty.model.ancestry.Dated` | `None`

betty.jinja2.filter.filter_negotiate_localizeds(context: jinja2.runtime.Context, localizeds: Iterable[betty.locale.Localized]) → betty.locale.Localized | None

  Try to find an object whose locale matches the context’s current locale.

  Parameters:

    - context (`jinja2.runtime.Context`)

    - localizeds (`typing.Iterable`[`betty.locale.Localized`])

  Return type:

    `betty.locale.Localized` | `None`

betty.jinja2.filter.filter_paragraphs(eval_ctx: jinja2.nodes.EvalContext, text: str) → str | markupsafe.Markup

  Convert newlines to <p> and <br> tags.

  Taken from http://jinja.pocoo.org/docs/2.10/api/#custom-filters.

  Parameters:

    - eval_ctx (`jinja2.nodes.EvalContext`)

    - text (`str`)

  Return type:

    `str` | `markupsafe.Markup`

betty.jinja2.filter.filter_public_css(context: jinja2.runtime.Context, public_path: str) → None

  Add a CSS file to the current page.

  Parameters:

    - context (`jinja2.runtime.Context`)

    - public_path (`str`)

  Return type:

    `None`

betty.jinja2.filter.filter_public_js(context: jinja2.runtime.Context, public_path: str) → None

  Add a JavaScript file to the current page.

  Parameters:

    - context (`jinja2.runtime.Context`)

    - public_path (`str`)

  Return type:

    `None`

betty.jinja2.filter.filter_select_dateds(context: jinja2.runtime.Context, dateds: Iterable[betty.model.ancestry.Dated], date: betty.locale.Date | betty.locale.DateRange | None) → Iterator[betty.model.ancestry.Dated]

  Select all objects whose date falls in the given date.

  Parameters:

    - date (`betty.locale.Date` | `betty.locale.DateRange` | `None`) – A date to select by. If None, then today’s date is used.

    - context (`jinja2.runtime.Context`)

    - dateds (`typing.Iterable`[`betty.model.ancestry.Dated`])

  Return type:

    `typing.Iterator`[`betty.model.ancestry.Dated`]

betty.jinja2.filter.filter_select_localizeds(context: jinja2.runtime.Context, localizeds: Iterable[betty.locale.Localized], include_unspecified: bool = False) → Iterable[betty.locale.Localized]

  Select all objects whose locale matches the context’s current locale.

  Parameters:

    - include_unspecified (`bool`) – If True, the return value includes all objects that do not have a locale specified.

    - context (`jinja2.runtime.Context`)

    - localizeds (`typing.Iterable`[`betty.locale.Localized`])

  Return type:

    `typing.Iterable`[`betty.locale.Localized`]

betty.jinja2.filter.filter_sort_localizeds(context: jinja2.runtime.Context, localizeds: Iterable[betty.locale.Localized], localized_attribute: str, sort_attribute: str) → Iterable[betty.locale.Localized]

  Sort localized objects.

  Parameters:

    - context (`jinja2.runtime.Context`)

    - localizeds (`typing.Iterable`[`betty.locale.Localized`])

    - localized_attribute (`str`)

    - sort_attribute (`str`)

  Return type:

    `typing.Iterable`[`betty.locale.Localized`]

betty.jinja2.filter.filter_static_url(context: jinja2.runtime.Context, resource: Any, absolute: bool = False) → str

  Generate a static URL for a static resource.

  Parameters:

    - context (`jinja2.runtime.Context`)

    - resource (`typing.Any`)

    - absolute (`bool`)

  Return type:

    `str`

async betty.jinja2.filter.filter_unique(values: Iterable[betty.jinja2.filter._T]) → AsyncIterator[betty.jinja2.filter._T]

  Iterate over an iterable of values and only yield those values that have not been yielded before.

  Parameters:

    values (`typing.Iterable`[`typing.TypeVar`(`_T`)])

  Return type:

    `typing.AsyncIterator`[`typing.TypeVar`(`_T`)]

betty.jinja2.filter.filter_url(context: jinja2.runtime.Context, resource: Any, media_type: str | None = None, *args: Any, locale: str | babel.core.Locale | None = None, **kwargs: Any) → str

  Generate a localized URL for a localizable resource.

  Parameters:

    - context (`jinja2.runtime.Context`)

    - resource (`typing.Any`)

    - media_type (`str` | `None`)

    - args (`typing.Any`)

    - locale (`str` | `babel.core.Locale` | `None`)

    - kwargs (`typing.Any`)

  Return type:

    `str`