mirror of
https://github.com/django/django.git
synced 2025-09-22 10:12:43 +00:00
Fixed #26866 -- Added format_lazy function
Added format_lazy function to django.utils.text module. Useful when dealing with relative complex lazy string concatenations (e.g. in urls.py when translating urls in regular expressions).
This commit is contained in:
parent
cf2cd4053f
commit
9aaeec337e
3 changed files with 55 additions and 2 deletions
|
@ -7,7 +7,9 @@ from io import BytesIO
|
|||
|
||||
from django.utils import six
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.functional import SimpleLazyObject, keep_lazy, keep_lazy_text
|
||||
from django.utils.functional import (
|
||||
SimpleLazyObject, keep_lazy, keep_lazy_text, lazy,
|
||||
)
|
||||
from django.utils.safestring import SafeText, mark_safe
|
||||
from django.utils.six.moves import html_entities
|
||||
from django.utils.translation import pgettext, ugettext as _, ugettext_lazy
|
||||
|
@ -434,3 +436,12 @@ def camel_case_to_spaces(value):
|
|||
trailing whitespace.
|
||||
"""
|
||||
return re_camel_case.sub(r' \1', value).strip().lower()
|
||||
|
||||
|
||||
def _format_lazy(format_string, *args, **kwargs):
|
||||
"""
|
||||
Apply str.format() on 'format_string' where format_string, args,
|
||||
and/or kwargs might be lazy.
|
||||
"""
|
||||
return format_string.format(*args, **kwargs)
|
||||
format_lazy = lazy(_format_lazy, six.text_type)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue