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.
- Returns:
The public path to the preprocessed file. This can be used on a web page.
- async betty.jinja2.filter.filter_flatten(values_of_values: Iterable[Iterable[_T]]) AsyncIterator[_T] [source]¶
Flatten an iterable of iterables into a single iterable.
- betty.jinja2.filter.filter_format_datey(context: Context, datey: Datey) str [source]¶
Format a date or a date range.
- betty.jinja2.filter.filter_format_degrees(degrees: int) str [source]¶
Format geographic coordinates.
- betty.jinja2.filter.filter_html_lang(context: Context, localized: LocalizedStr | str) str | Markup [source]¶
Optionally add the necessary HTML to indicate the localized string has a different locale than the surrounding HTML.
- async betty.jinja2.filter.filter_image_resize_cover(context: Context, filey: File | FileReference, size: tuple[int, None] | tuple[None, int] | tuple[int, int] | None = None, *, focus: tuple[int, int, int, int] | None = None) str [source]¶
Preprocess an image file for use in a page.
- Returns:
The public path to the preprocessed file. This can be embedded in a web page.
- betty.jinja2.filter.filter_json(data: Any, indent: int | None = None) str [source]¶
Convert a value to a JSON string.
- betty.jinja2.filter.filter_localize(context: Context, localizable: Localizable) str [source]¶
Localize a value using the context’s current localizer.
- async betty.jinja2.filter.filter_localized_url(context: Context, resource: Any, locale: str | Locale | None = None, media_type: str | None = None, **kwargs: Any) str [source]¶
Generate a localized URL for a localizable resource.
- async betty.jinja2.filter.filter_map(context: 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.
- betty.jinja2.filter.filter_negotiate_has_dates(context: Context, has_dates: Iterable[HasDate], date: Datey | None) HasDate | None [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.
- betty.jinja2.filter.filter_negotiate_localizeds(context: Context, localizeds: Iterable[Localized]) Localized | None [source]¶
Try to find an object whose locale matches the context’s current locale.
- betty.jinja2.filter.filter_paragraphs(eval_ctx: EvalContext, text: str) str | Markup [source]¶
Convert newlines to <p> and <br> tags.
Taken from http://jinja.pocoo.org/docs/2.10/api/#custom-filters.
- async betty.jinja2.filter.filter_public_css(context: Context, public_path: str) None [source]¶
Add a CSS file to the current page.
- async betty.jinja2.filter.filter_public_js(context: Context, public_path: str) None [source]¶
Add a JavaScript file to the current page.
- betty.jinja2.filter.filter_select_has_dates(context: Context, has_dates: Iterable[HasDate], date: Datey | None) Iterator[HasDate] [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.
- betty.jinja2.filter.filter_select_localizeds(context: Context, localizeds: Iterable[Localized], include_unspecified: bool = False) Iterable[Localized] [source]¶
Select all objects whose locale matches the context’s current locale.
- Parameters:
include_unspecified – If True, the return value includes all objects that do not have a locale specified.
- betty.jinja2.filter.filter_sort_localizeds(context: Context, localizeds: Iterable[Localized], localized_attribute: str, sort_attribute: str) Iterable[Localized] [source]¶
Sort localized objects.
- async betty.jinja2.filter.filter_static_url(context: Context, resource: Any, absolute: bool = False) str [source]¶
Generate a static URL for a static resource.
- async betty.jinja2.filter.filter_unique(values: Iterable[_T]) AsyncIterator[_T] [source]¶
Iterate over an iterable of values and only yield those values that have not been yielded before.