i18n: Use new way to define action_present/past

In Kilo or Liberty cycle, the way to define action messages in
horizon BatchAction was changed for better translation support
(pluralization and better word order control).
The previous way with data_type_singular/plural is deprecated.
This commit cleans up the deprecated usage.

Change-Id: Icbb75710ac7e7c9c97a6198a28d02583c37136d7
This commit is contained in:
Akihiro Motoki 2016-03-12 18:34:51 +09:00
parent 4e7f649ca4
commit 12f232699b
4 changed files with 113 additions and 19 deletions

View File

@ -14,6 +14,7 @@
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
from horizon import exceptions
from horizon import tables
from muranoclient.common import exceptions as exc
@ -33,8 +34,21 @@ class AddCategory(tables.LinkAction):
class DeleteCategory(tables.DeleteAction):
data_type_singular = _('Category')
data_type_plural = _('Categories')
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Delete Category",
u"Delete Categories",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Deleted Category",
u"Deleted Categories",
count
)
def allowed(self, request, category=None):
if category is not None:

View File

@ -19,6 +19,7 @@ from django import http as django_http
from django import shortcuts
from django.template import defaultfilters
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
from horizon import exceptions
from horizon import forms
@ -87,11 +88,24 @@ class CreateEnvironment(tables.LinkAction):
class DeleteEnvironment(tables.DeleteAction):
data_type_singular = _('Environment')
data_type_plural = _('Environments')
action_past = _('Start Deleting')
redirect_url = "horizon:project:murano:environments"
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Delete Environment",
u"Delete Environments",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Start Deleting Environment",
u"Start Deleting Environments",
count
)
def allowed(self, request, environment):
if environment:
return environment.status not in (consts.STATUS_ID_DEPLOYING,
@ -113,12 +127,24 @@ class AbandonEnvironment(tables.DeleteAction):
help_text = _("This action cannot be undone. Any resources created by "
"this environment will have to be released manually.")
name = 'abandon'
action_present = _('Abandon')
action_past = _('Abandoned')
data_type_singular = _('Environment')
data_type_plural = _('Environments')
redirect_url = "horizon:project:murano:environments"
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Abandon Environment",
u"Abandon Environments",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Abandoned Environment",
u"Abandoned Environments",
count
)
def allowed(self, request, environment):
"""Limit when 'Abandon Environment' button is shown
@ -143,9 +169,22 @@ class AbandonEnvironment(tables.DeleteAction):
class DeleteService(tables.DeleteAction):
data_type_singular = _('Component')
data_type_plural = _('Components')
action_past = _('Start Deleting')
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Delete Component",
u"Delete Components",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Start Deleting Component",
u"Start Deleting Components",
count
)
def allowed(self, request, service=None):
status, version = _get_environment_status_and_version(request,
@ -168,12 +207,24 @@ class DeleteService(tables.DeleteAction):
class DeployEnvironment(tables.BatchAction):
name = 'deploy'
action_present = _('Deploy')
action_past = _('Deployed')
data_type_singular = _('Environment')
data_type_plural = _('Environment')
classes = ('btn-launch',)
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Deploy Environment",
u"Deploy Environments",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Deployed Environment",
u"Deployed Environments",
count
)
def allowed(self, request, environment):
"""Limit when 'Deploy Environment' button is shown

View File

@ -14,6 +14,7 @@
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
from horizon import exceptions
from horizon import tables
from openstack_dashboard.api import glance
@ -31,8 +32,21 @@ class MarkImage(tables.LinkAction):
class RemoveImageMetadata(tables.DeleteAction):
data_type_singular = _('Metadata')
data_type_plural = _('Metadata')
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Delete Metadata",
u"Delete Metadata",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Deleted Metadata",
u"Deleted Metadata",
count
)
def delete(self, request, obj_id):
try:

View File

@ -175,7 +175,22 @@ class TogglePublicEnabled(tables.BatchAction):
class DeletePackage(tables.DeleteAction):
name = 'delete_package'
data_type_singular = _('Package')
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Delete Package",
u"Delete Packages",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Deleted Package",
u"Deleted Packages",
count
)
def delete(self, request, obj_id):
try: