Allow some translations to be made.

Transform some action_present and action_past variables from attributes to
methods with the solution proposed in this patch:
https://review.openstack.org/#/c/91338/
Also fix a bug in the solution above where the __init__ function in the
deleteAction class overwrite the action_present and action_past methods.
Closes-Bug: 1366731

Change-Id: I9595f9d5a5a3f1ef4d528ddb3e08737a43471402
This commit is contained in:
Ambroise Christea 2014-09-08 14:19:07 +02:00
parent f4594e8199
commit 209d83bc02
4 changed files with 55 additions and 10 deletions

View File

@ -869,8 +869,10 @@ class DeleteAction(BatchAction):
def __init__(self, **kwargs):
super(DeleteAction, self).__init__(**kwargs)
self.name = kwargs.get('name', self.name)
self.action_present = kwargs.get('action_present', _("Delete"))
self.action_past = kwargs.get('action_past', _("Deleted"))
if not hasattr(self, "action_present"):
self.action_present = kwargs.get('action_present', _("Delete"))
if not hasattr(self, "action_past"):
self.action_past = kwargs.get('action_past', _("Deleted"))
self.icon = "remove"
def action(self, request, obj_id):

View File

@ -21,6 +21,7 @@ from django import shortcuts
from django.utils.http import urlencode
from django.utils.translation import string_concat # noqa
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
from horizon import exceptions
from horizon import messages
@ -69,13 +70,25 @@ class AllocateIP(tables.LinkAction):
class ReleaseIPs(tables.BatchAction):
name = "release"
action_present = _("Release")
action_past = _("Released")
data_type_singular = _("Floating IP")
data_type_plural = _("Floating IPs")
classes = ('btn-danger',)
icon = "arrow-up"
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Release floating IP",
u"Release floating IPs",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Floating IP released",
u"Floating IPs released",
count
)
def allowed(self, request, fip=None):
if api.base.is_service_enabled(request, "network"):
policy = (("network", "delete_floatingip"),)

View File

@ -14,6 +14,7 @@
from django.utils.translation import string_concat # noqa
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
from horizon import tables
@ -22,10 +23,24 @@ from openstack_dashboard.usage import quotas
class DeleteKeyPairs(tables.DeleteAction):
data_type_singular = _("Key Pair")
data_type_plural = _("Key Pairs")
policy_rules = (("compute", "compute_extension:keypairs:delete"),)
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Delete key pair",
u"Delete key pairs",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Key pair deleted",
u"Key pairs deleted",
count
)
def delete(self, request, obj_id):
api.nova.keypair_delete(request, obj_id)

View File

@ -15,6 +15,7 @@
from django.conf import settings
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
from horizon import tables
@ -27,8 +28,22 @@ POLICY_CHECK = getattr(settings, "POLICY_CHECK_FUNCTION",
class DeleteGroup(tables.DeleteAction):
data_type_singular = _("Security Group")
data_type_plural = _("Security Groups")
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Delete security group",
u"Delete security groups",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Security group deleted",
u"Security groups deleted",
count
)
def get_policy_target(self, request, datum=None):
project_id = None