betty.jinja2.filter module¶
Provide Betty’s default Jinja2 filters.
- async betty.jinja2.filter.filter_file(context: Context, file: File) str[source]¶
Preprocess a file for use in a page.
- Return type:
- 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][source]¶
Flatten an iterable of iterables into a single iterable.
- Parameters:
values_of_values (
typing.Iterable[typing.Iterable[typing.TypeVar(_T)]])- Return type:
- betty.jinja2.filter.filter_format_datey(context: jinja2.runtime.Context, datey: betty.locale.Date | betty.locale.DateRange) str[source]¶
Format a date or a date range.
- Parameters:
context (
jinja2.runtime.Context)datey (
betty.locale.Date|betty.locale.DateRange)
- Return type:
- async betty.jinja2.filter.filter_image(context: jinja2.runtime.Context, file: betty.model.ancestry.File, width: int | None = None, height: int | None = None) str[source]¶
Preprocess an image file for use in a page.
- Return type:
- 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)
- betty.jinja2.filter.filter_json(data: Any, indent: int | None = None) str[source]¶
Convert a value to a JSON string.
- Parameters:
data (
typing.Any)
- Return type:
- betty.jinja2.filter.filter_localize(context: jinja2.runtime.Context, localizable: betty.locale.Localizable) str[source]¶
Localize a value using the context’s current localizer.
- Parameters:
context (
jinja2.runtime.Context)localizable (
betty.locale.Localizable)
- Return type:
- async betty.jinja2.filter.filter_map(context: jinja2.runtime.Context, values: Iterable[Any], *args: Any, **kwargs: Any) Any[source]¶
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:
- 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[source]¶
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.jinja2.filter.filter_negotiate_localizeds(context: jinja2.runtime.Context, localizeds: Iterable[betty.locale.Localized]) betty.locale.Localized | None[source]¶
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.jinja2.filter.filter_paragraphs(eval_ctx: jinja2.nodes.EvalContext, text: str) str | markupsafe.Markup[source]¶
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:
- betty.jinja2.filter.filter_public_css(context: jinja2.runtime.Context, public_path: str) None[source]¶
Add a CSS file to the current page.
- Parameters:
context (
jinja2.runtime.Context)public_path (
str)
- Return type:
- betty.jinja2.filter.filter_public_js(context: jinja2.runtime.Context, public_path: str) None[source]¶
Add a JavaScript file to the current page.
- Parameters:
context (
jinja2.runtime.Context)public_path (
str)
- Return type:
- 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][source]¶
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:
- betty.jinja2.filter.filter_select_localizeds(context: jinja2.runtime.Context, localizeds: Iterable[betty.locale.Localized], include_unspecified: bool = False) Iterable[betty.locale.Localized][source]¶
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:
- 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][source]¶
Sort localized objects.
- Parameters:
context (
jinja2.runtime.Context)localizeds (
typing.Iterable[betty.locale.Localized])localized_attribute (
str)sort_attribute (
str)
- Return type:
- betty.jinja2.filter.filter_static_url(context: jinja2.runtime.Context, resource: Any, absolute: bool = False) str[source]¶
Generate a static URL for a static resource.
- Parameters:
context (
jinja2.runtime.Context)resource (
typing.Any)absolute (
bool)
- Return type:
- async betty.jinja2.filter.filter_unique(values: Iterable[betty.jinja2.filter._T]) AsyncIterator[betty.jinja2.filter._T][source]¶
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:
- 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[source]¶
Generate a localized URL for a localizable resource.
- Parameters:
context (
jinja2.runtime.Context)resource (
typing.Any)args (
typing.Any)locale (
str|babel.core.Locale|None)kwargs (
typing.Any)
- Return type: