betty.jinja2.filter module

Provide Betty’s default Jinja2 filters.

betty.jinja2.filter.filter_base64(input)[source]

Base-64-encode a string.

Parameters:
input

Return type:

str

async betty.jinja2.filter.filter_file(context, file)[source]

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

file

async betty.jinja2.filter.filter_flatten(values_of_values)[source]

Flatten an iterable of iterables into a single iterable.

Parameters:
values_of_values

Return type:

typing.AsyncIterator[typing.TypeVar(T)]

betty.jinja2.filter.filter_format_datey(context, datey)[source]

Format a date or a date range.

Parameters:
context

datey

Return type:

str

betty.jinja2.filter.filter_format_degrees(degrees)[source]

Format geographic coordinates.

Parameters:
degrees

Return type:

str

betty.jinja2.filter.filter_hashid(input)[source]

Create a hash ID.

Parameters:
input

Return type:

str

async betty.jinja2.filter.filter_image(context, file, width=None, height=None)[source]

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

file

width=None

height=None

betty.jinja2.filter.filter_json(data, indent=None)[source]

Convert a value to a JSON string.

Parameters:
data

indent=None

Return type:

str

betty.jinja2.filter.filter_localize(context, localizable)[source]

Localize a value using the context’s current localizer.

Parameters:
context

localizable

Return type:

str

async betty.jinja2.filter.filter_map(context, values, *args, **kwargs)[source]

Map an iterable’s values.

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

Parameters:
context

values

*args

**kwargs

Return type:

typing.Any

betty.jinja2.filter.filter_negotiate_dateds(context, dateds, date)[source]

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

Parameters:
date

A date to select by. If None, then today’s date is used.

context

dateds

Return type:

betty.model.ancestry.Dated | None

betty.jinja2.filter.filter_negotiate_localizeds(context, localizeds)[source]

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

Parameters:
context

localizeds

Return type:

betty.locale.Localized | None

betty.jinja2.filter.filter_paragraphs(eval_ctx, text)[source]

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

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

Parameters:
eval_ctx

text

Return type:

str | markupsafe.Markup

betty.jinja2.filter.filter_public_css(context, public_path)[source]

Add a CSS file to the current page.

Parameters:
context

public_path

Return type:

None

betty.jinja2.filter.filter_public_js(context, public_path)[source]

Add a JavaScript file to the current page.

Parameters:
context

public_path

Return type:

None

betty.jinja2.filter.filter_select_dateds(context, dateds, date)[source]

Select all objects whose date falls in the given date.

Parameters:
date

A date to select by. If None, then today’s date is used.

context

dateds

Return type:

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

betty.jinja2.filter.filter_select_localizeds(context, localizeds, include_unspecified=False)[source]

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

Parameters:
include_unspecified=False

If True, the return value includes all objects that do not have a locale specified.

context

localizeds

Return type:

typing.Iterable[betty.locale.Localized]

betty.jinja2.filter.filter_sort_localizeds(context, localizeds, localized_attribute, sort_attribute)[source]

Sort localized objects.

Parameters:
context

localizeds

localized_attribute

sort_attribute

Return type:

typing.Iterable[betty.locale.Localized]

betty.jinja2.filter.filter_static_url(context, resource, absolute=False)[source]

Generate a static URL for a static resource.

Parameters:
context

resource

absolute=False

Return type:

str

async betty.jinja2.filter.filter_unique(value)[source]

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

Parameters:
value

Return type:

typing.AsyncIterator[typing.TypeVar(T)]

betty.jinja2.filter.filter_url(context, resource, media_type=None, *args, locale=None, **kwargs)[source]

Generate a localized URL for a localizable resource.

Parameters:
context

resource

media_type=None

*args

locale=None

**kwargs

Return type:

str

betty.jinja2.filter.filter_walk(value, attribute_name)[source]

Walk over a data structure.

Parameters:
value

attribute_name

Return type:

typing.Iterable[typing.Any]