diff options
| author | Mattias Loverot <mattias@stubin.se> | 2016-08-16 12:07:03 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-08-25 16:12:40 -0400 |
| commit | 2315114090815aed72be2b9bc936d7b6374f12fc (patch) | |
| tree | 6caf23c46dfc24c499fb624a729058973c1e2ef6 /django | |
| parent | 13c3e5d5a05e9c358d212d154addd703cac3bc66 (diff) | |
Fixed #27067 -- Deprecated string_concat() in favor of format_lazy().
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/admin/options.py | 6 | ||||
| -rw-r--r-- | django/contrib/postgres/utils.py | 7 | ||||
| -rw-r--r-- | django/db/models/options.py | 8 | ||||
| -rw-r--r-- | django/utils/translation/__init__.py | 6 |
4 files changed, 17 insertions, 10 deletions
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 052a1d5a9a..11b5585f7a 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -43,9 +43,9 @@ from django.utils.encoding import force_text, python_2_unicode_compatible from django.utils.html import escape, format_html from django.utils.http import urlencode, urlquote from django.utils.safestring import mark_safe -from django.utils.text import capfirst, get_text_list +from django.utils.text import capfirst, format_lazy, get_text_list from django.utils.translation import ( - override as translation_override, string_concat, ugettext as _, ungettext, + override as translation_override, ugettext as _, ungettext, ) from django.views.decorators.csrf import csrf_protect from django.views.generic import RedirectView @@ -258,7 +258,7 @@ class BaseModelAdmin(six.with_metaclass(forms.MediaDefiningClass)): if isinstance(form_field.widget, SelectMultiple) and not isinstance(form_field.widget, CheckboxSelectMultiple): msg = _('Hold down "Control", or "Command" on a Mac, to select more than one.') help_text = form_field.help_text - form_field.help_text = string_concat(help_text, ' ', msg) if help_text else msg + form_field.help_text = format_lazy('{} {}', help_text, msg) if help_text else msg return form_field def get_view_on_site_url(self, obj=None): diff --git a/django/contrib/postgres/utils.py b/django/contrib/postgres/utils.py index 1563149c7e..a2bbb72f36 100644 --- a/django/contrib/postgres/utils.py +++ b/django/contrib/postgres/utils.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals from django.core.exceptions import ValidationError from django.utils.functional import SimpleLazyObject -from django.utils.translation import string_concat +from django.utils.text import format_lazy def prefix_validation_error(error, prefix, code, params): @@ -15,10 +15,11 @@ def prefix_validation_error(error, prefix, code, params): return ValidationError( # We can't simply concatenate messages since they might require # their associated parameters to be expressed correctly which - # is not something `string_concat` does. For example, proxied + # is not something `format_lazy` does. For example, proxied # ungettext calls require a count parameter and are converted # to an empty string if they are missing it. - message=string_concat( + message=format_lazy( + '{}{}', SimpleLazyObject(lambda: prefix % params), SimpleLazyObject(lambda: error.message % error_params), ), diff --git a/django/db/models/options.py b/django/db/models/options.py index 38f2fcfefc..f53d3bb59f 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -22,8 +22,8 @@ from django.utils.encoding import ( force_text, python_2_unicode_compatible, smart_text, ) from django.utils.functional import cached_property -from django.utils.text import camel_case_to_spaces -from django.utils.translation import override, string_concat +from django.utils.text import camel_case_to_spaces, format_lazy +from django.utils.translation import override NOT_PROVIDED = object() @@ -197,7 +197,7 @@ class Options(object): # verbose_name_plural is a special case because it uses a 's' # by default. if self.verbose_name_plural is None: - self.verbose_name_plural = string_concat(self.verbose_name, 's') + self.verbose_name_plural = format_lazy('{}s', self.verbose_name) # order_with_respect_and ordering are mutually exclusive. self._ordering_clash = bool(self.ordering and self.order_with_respect_to) @@ -206,7 +206,7 @@ class Options(object): if meta_attrs != {}: raise TypeError("'class Meta' got invalid attribute(s): %s" % ','.join(meta_attrs.keys())) else: - self.verbose_name_plural = string_concat(self.verbose_name, 's') + self.verbose_name_plural = format_lazy('{}s', self.verbose_name) del self.meta # If the db_table wasn't provided, use the app_label + model_name. diff --git a/django/utils/translation/__init__.py b/django/utils/translation/__init__.py index c42182d96d..9154ceeb7b 100644 --- a/django/utils/translation/__init__.py +++ b/django/utils/translation/__init__.py @@ -4,9 +4,11 @@ Internationalization support. from __future__ import unicode_literals import re +import warnings from django.utils import six from django.utils.decorators import ContextDecorator +from django.utils.deprecation import RemovedInDjango21Warning from django.utils.encoding import force_text from django.utils.functional import lazy @@ -224,6 +226,10 @@ def _string_concat(*strings): Lazy variant of string concatenation, needed for translations that are constructed from multiple parts. """ + warnings.warn( + 'django.utils.translate.string_concat() is deprecated in ' + 'favor of django.utils.text.format_lazy().', + RemovedInDjango21Warning, stacklevel=2) return ''.join(force_text(s) for s in strings) string_concat = lazy(_string_concat, six.text_type) |
