diff options
| author | Mattias Loverot <mattias@stubin.se> | 2016-08-24 18:18:17 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2016-08-24 18:18:17 +0200 |
| commit | 9aaeec337e217109208672d8fe47eeb49ca492b5 (patch) | |
| tree | 4b815546bfd3b8a5844464c3cea9d397b792c4c2 /django | |
| parent | cf2cd4053fe3eed50ab2b7269ed72d25712c970a (diff) | |
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).
Diffstat (limited to 'django')
| -rw-r--r-- | django/utils/text.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/django/utils/text.py b/django/utils/text.py index f51113b483..3b8fc581bf 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -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) |
