module documentation

Undocumented

Constant FORMAT​_SETTINGS Undocumented
Constant ISO​_INPUT​_FORMATS Undocumented
Variable get​_format​_lazy Undocumented
Function date​_format Format a datetime.date or datetime.datetime object using a localizable format.
Function get​_format For a specific format type, return the format for the current language (locale). Default to the format in the settings. format_type is the name of the format, e.g. 'DATE_FORMAT'.
Function get​_format​_modules Return a list of the format modules found.
Function iter​_format​_modules Find format modules.
Function localize Check if value is a localizable type (date, number...) and return it formatted as a string using current locale format.
Function localize​_input Check if an input value is a localizable type and return it formatted with the appropriate formatting string of the current locale.
Function number​_format Format a numeric value using localization settings.
Function reset​_format​_cache Clear any cached formats.
Function sanitize​_separators Sanitize a value according to the current decimal and thousand separator setting. Used with form field input.
Function sanitize​_strftime​_format Ensure that certain specifiers are correctly padded with leading zeros.
Function time​_format Format a datetime.time object using a localizable format.
Variable ​_format​_cache Undocumented
Variable ​_format​_modules​_cache Undocumented
FORMAT_SETTINGS =

Undocumented

Value
frozenset(['DECIMAL_SEPARATOR',
           'THOUSAND_SEPARATOR',
           'NUMBER_GROUPING',
           'FIRST_DAY_OF_WEEK',
           'MONTH_DAY_FORMAT',
           'TIME_FORMAT',
           'DATE_FORMAT',
...
ISO_INPUT_FORMATS: dict =

Undocumented

Value
{'DATE_INPUT_FORMATS': ['%Y-%m-%d'],
 'TIME_INPUT_FORMATS': ['%H:%M:%S', '%H:%M:%S.%f', '%H:%M'],
 'DATETIME_INPUT_FORMATS': ['%Y-%m-%d %H:%M:%S',
                            '%Y-%m-%d %H:%M:%S.%f',
                            '%Y-%m-%d %H:%M',
                            '%Y-%m-%d']}
get_format_lazy =

Undocumented

def date_format(value, format=None, use_l10n=None):

Format a datetime.date or datetime.datetime object using a localizable format.

If use_l10n is provided and is not None, that will force the value to be localized (or not), overriding the value of settings.USE_L10N.

def get_format(format_type, lang=None, use_l10n=None):

For a specific format type, return the format for the current language (locale). Default to the format in the settings. format_type is the name of the format, e.g. 'DATE_FORMAT'.

If use_l10n is provided and is not None, it forces the value to be localized (or not), overriding the value of settings.USE_L10N.

def get_format_modules(lang=None):
Return a list of the format modules found.
def iter_format_modules(lang, format_module_path=None):
Find format modules.
def localize(value, use_l10n=None):

Check if value is a localizable type (date, number...) and return it formatted as a string using current locale format.

If use_l10n is provided and is not None, it forces the value to be localized (or not), overriding the value of settings.USE_L10N.

def localize_input(value, default=None):
Check if an input value is a localizable type and return it formatted with the appropriate formatting string of the current locale.
def number_format(value, decimal_pos=None, use_l10n=None, force_grouping=False):

Format a numeric value using localization settings.

If use_l10n is provided and is not None, it forces the value to be localized (or not), overriding the value of settings.USE_L10N.

def reset_format_cache():

Clear any cached formats.

This method is provided primarily for testing purposes, so that the effects of cached formats can be removed.

def sanitize_separators(value):
Sanitize a value according to the current decimal and thousand separator setting. Used with form field input.
@functools.lru_cache()
def sanitize_strftime_format(fmt):

Ensure that certain specifiers are correctly padded with leading zeros.

For years < 1000 specifiers %C, %F, %G, and %Y don't work as expected for strftime provided by glibc on Linux as they don't pad the year or century with leading zeros. Support for specifying the padding explicitly is available, however, which can be used to fix this issue.

FreeBSD, macOS, and Windows do not support explicitly specifying the padding, but return four digit years (with leading zeros) as expected.

This function checks whether the %Y produces a correctly padded string and, if not, makes the following substitutions:

  • %C → %02C
  • %F → %010F
  • %G → %04G
  • %Y → %04Y

See https://bugs.python.org/issue13305 for more details.

def time_format(value, format=None, use_l10n=None):

Format a datetime.time object using a localizable format.

If use_l10n is provided and is not None, it forces the value to be localized (or not), overriding the value of settings.USE_L10N.

_format_cache: dict =

Undocumented

_format_modules_cache: dict =

Undocumented