Switch from django string_concat to format_lazy

string_concat was removed in django 2.1 when it reached the end
of it's deprecation cycle. It was removed because the same behavior
can be achieved with format_lazy.

For more details see:
https://docs.djangoproject.com/en/2.2/releases/2.1/

Change-Id: I5e1c9bdfa1d0e049e0516198abbdb76be1667216
Closes-Bug: #1836671
Partial-Bug: #1789046
This commit is contained in:
Corey Bryant 2019-07-16 09:56:48 -04:00
parent 350efbe4f2
commit 6f4742457f
5 changed files with 34 additions and 20 deletions

View File

@ -18,7 +18,7 @@
from django.conf import settings from django.conf import settings
from django.template.defaultfilters import floatformat from django.template.defaultfilters import floatformat
from django.utils import translation from django.utils.text import format_lazy
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from horizon import exceptions from horizon import exceptions
@ -71,6 +71,7 @@ class GlobalOverview(usage.UsageView):
instance.project_name = getattr(project[0], "name", None) instance.project_name = getattr(project[0], "name", None)
else: else:
deleted = _("Deleted") deleted = _("Deleted")
instance.project_name = translation.string_concat( instance.project_name = format_lazy(
instance.tenant_id, " (", deleted, ")") '{tenant_id} ({deleted})',
tenant_id=instance.tenant_id, deleted=deleted)
return data return data

View File

@ -18,8 +18,8 @@ import logging
from django import shortcuts from django import shortcuts
from django.urls import reverse from django.urls import reverse
from django.utils.http import urlencode from django.utils.http import urlencode
from django.utils.text import format_lazy
from django.utils.translation import pgettext_lazy from django.utils.translation import pgettext_lazy
from django.utils.translation import string_concat
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy from django.utils.translation import ungettext_lazy
@ -52,8 +52,10 @@ class AllocateIP(tables.LinkAction):
if usages['floatingip']['available'] <= 0: if usages['floatingip']['available'] <= 0:
if "disabled" not in self.classes: if "disabled" not in self.classes:
self.classes = [c for c in self.classes] + ['disabled'] self.classes = [c for c in self.classes] + ['disabled']
self.verbose_name = string_concat(self.verbose_name, ' ', self.verbose_name = format_lazy(
_("(Quota exceeded)")) '{verbose_name} {quota_exceeded}',
verbose_name=self.verbose_name,
quota_exceeded=_("(Quota exceeded)"))
else: else:
self.verbose_name = _("Allocate IP To Project") self.verbose_name = _("Allocate IP To Project")
classes = [c for c in self.classes if c != "disabled"] classes = [c for c in self.classes if c != "disabled"]

View File

@ -23,9 +23,9 @@ from django.template.defaultfilters import title
from django import urls from django import urls
from django.utils.http import urlencode from django.utils.http import urlencode
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils.text import format_lazy
from django.utils.translation import npgettext_lazy from django.utils.translation import npgettext_lazy
from django.utils.translation import pgettext_lazy from django.utils.translation import pgettext_lazy
from django.utils.translation import string_concat
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy from django.utils.translation import ungettext_lazy
import netaddr import netaddr
@ -449,8 +449,10 @@ class LaunchLink(tables.LinkAction):
or ram_available <= 0: or ram_available <= 0:
if "disabled" not in self.classes: if "disabled" not in self.classes:
self.classes = [c for c in self.classes] + ['disabled'] self.classes = [c for c in self.classes] + ['disabled']
self.verbose_name = string_concat(self.verbose_name, ' ', self.verbose_name = format_lazy(
_("(Quota exceeded)")) '{verbose_name} {quota_exceeded}',
verbose_name=self.verbose_name,
quota_exceeded=_("(Quota exceeded)"))
else: else:
self.verbose_name = _("Launch Instance") self.verbose_name = _("Launch Instance")
classes = [c for c in self.classes if c != "disabled"] classes = [c for c in self.classes if c != "disabled"]
@ -772,7 +774,8 @@ def get_instance_error(instance):
message = instance_fault_to_friendly_message(instance) message = instance_fault_to_friendly_message(instance)
preamble = _('Failed to perform requested operation on instance "%s", the ' preamble = _('Failed to perform requested operation on instance "%s", the '
'instance has an error status') % instance.name or instance.id 'instance has an error status') % instance.name or instance.id
message = string_concat(preamble, ': ', message) message = format_lazy('{preamble}: {message}',
preamble=preamble, message=message)
return message return message

View File

@ -13,7 +13,7 @@
# under the License. # under the License.
from django import urls from django import urls
from django.utils.translation import string_concat from django.utils.text import format_lazy
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy from django.utils.translation import ungettext_lazy
from six.moves.urllib import parse from six.moves.urllib import parse
@ -57,8 +57,10 @@ class QuotaKeypairMixin(object):
if usages['key_pairs']['available'] <= 0: if usages['key_pairs']['available'] <= 0:
if "disabled" not in self.classes: if "disabled" not in self.classes:
self.classes = [c for c in self.classes] + ['disabled'] self.classes = [c for c in self.classes] + ['disabled']
self.verbose_name = string_concat(self.verbose_name, ' ', self.verbose_name = format_lazy(
_("(Quota exceeded)")) '{verbose_name} {quota_exceeded}',
verbose_name=self.verbose_name,
quota_exceeded=_("(Quota exceeded)"))
return False return False
else: else:
classes = [c for c in self.classes if c != "disabled"] classes = [c for c in self.classes if c != "disabled"]

View File

@ -20,9 +20,9 @@ from django.urls import reverse
from django.utils import html from django.utils import html
from django.utils.http import urlencode from django.utils.http import urlencode
from django.utils import safestring from django.utils import safestring
from django.utils.text import format_lazy
from django.utils.translation import npgettext_lazy from django.utils.translation import npgettext_lazy
from django.utils.translation import pgettext_lazy from django.utils.translation import pgettext_lazy
from django.utils.translation import string_concat
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy from django.utils.translation import ungettext_lazy
@ -153,8 +153,10 @@ class CreateVolume(tables.LinkAction):
if gb_available <= 0 or volumes_available <= 0: if gb_available <= 0 or volumes_available <= 0:
if "disabled" not in self.classes: if "disabled" not in self.classes:
self.classes = [c for c in self.classes] + ['disabled'] self.classes = [c for c in self.classes] + ['disabled']
self.verbose_name = string_concat(self.verbose_name, ' ', self.verbose_name = format_lazy(
_("(Quota exceeded)")) '{verbose_name} {quota_exceeded}',
verbose_name=self.verbose_name,
quota_exceeded=_("(Quota exceeded)"))
else: else:
self.verbose_name = _("Create Volume") self.verbose_name = _("Create Volume")
classes = [c for c in self.classes if c != "disabled"] classes = [c for c in self.classes if c != "disabled"]
@ -226,8 +228,10 @@ class CreateSnapshot(VolumePolicyTargetMixin, tables.LinkAction):
if snapshots_available <= 0 and "disabled" not in self.classes: if snapshots_available <= 0 and "disabled" not in self.classes:
self.classes = [c for c in self.classes] + ['disabled'] self.classes = [c for c in self.classes] + ['disabled']
self.verbose_name = string_concat(self.verbose_name, ' ', self.verbose_name = format_lazy(
_("(Quota exceeded)")) '{verbose_name} {quota_exceeded}',
verbose_name=self.verbose_name,
quota_exceeded=_("(Quota exceeded)"))
return volume.status in ("available", "in-use") return volume.status in ("available", "in-use")
@ -312,8 +316,10 @@ class AcceptTransfer(tables.LinkAction):
if gb_available <= 0 or volumes_available <= 0: if gb_available <= 0 or volumes_available <= 0:
if "disabled" not in self.classes: if "disabled" not in self.classes:
self.classes = [c for c in self.classes] + ['disabled'] self.classes = [c for c in self.classes] + ['disabled']
self.verbose_name = string_concat(self.verbose_name, ' ', self.verbose_name = format_lazy(
_("(Quota exceeded)")) '{verbose_name} {quota_exceeded}',
verbose_name=self.verbose_name,
quota_exceeded=_("(Quota exceeded)"))
else: else:
self.verbose_name = _("Accept Transfer") self.verbose_name = _("Accept Transfer")
classes = [c for c in self.classes if c != "disabled"] classes = [c for c in self.classes if c != "disabled"]