Utils Templating

inyoka.utils.templating

This module contains functions for template-related things.

copyright:
  1. 2007-2024 by the Inyoka Team, see AUTHORS for more details.

license:

BSD, see LICENSE for more details.

inyoka.utils.templating.FILTERS = {'date': <function <lambda>>, 'datetime': <function <lambda>>, 'hnumber': <function human_number>, 'ischeckbox': <function ischeckbox_filter>, 'jsonencode': <function json_filter>, 'naturalday': <function <lambda>>, 'time': <function <lambda>>, 'timedeltaformat': <function timesince>, 'timetz': <function <lambda>>, 'url': <function url_for>, 'urlencode': <function urlencode_filter>}

Filters that are globally available in the template environment

class inyoka.utils.templating.LazyJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)

Encode a given object as JSON string, taking care of lazy objects. Lazy objects, such as ugettext_lazy() will be forced to unicode.

default(obj)

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return super().default(o)
inyoka.utils.templating.context_data(request)

Fill in context defaults.

inyoka.utils.templating.environment(**options)
inyoka.utils.templating.flash_message(request, template_name: str, context: dict)
inyoka.utils.templating.ischeckbox_filter(input)
inyoka.utils.templating.json_filter(value)

“A wrapper function that uses the LazyJSONEncoder

inyoka.utils.templating.urlencode_filter(value)

URL encode a string or dict.