From 209d83bc02da259067306858b41a3efa00efdd2a Mon Sep 17 00:00:00 2001 From: Ambroise Christea Date: Mon, 8 Sep 2014 14:19:07 +0200 Subject: [PATCH] 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 --- horizon/tables/actions.py | 6 ++++-- .../floating_ips/tables.py | 21 +++++++++++++++---- .../access_and_security/keypairs/tables.py | 19 +++++++++++++++-- .../security_groups/tables.py | 19 +++++++++++++++-- 4 files changed, 55 insertions(+), 10 deletions(-) diff --git a/horizon/tables/actions.py b/horizon/tables/actions.py index ccea5e3833..a0b51d15c1 100644 --- a/horizon/tables/actions.py +++ b/horizon/tables/actions.py @@ -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): diff --git a/openstack_dashboard/dashboards/project/access_and_security/floating_ips/tables.py b/openstack_dashboard/dashboards/project/access_and_security/floating_ips/tables.py index 96f1b94a0f..72b3ae8c7f 100644 --- a/openstack_dashboard/dashboards/project/access_and_security/floating_ips/tables.py +++ b/openstack_dashboard/dashboards/project/access_and_security/floating_ips/tables.py @@ -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"),) diff --git a/openstack_dashboard/dashboards/project/access_and_security/keypairs/tables.py b/openstack_dashboard/dashboards/project/access_and_security/keypairs/tables.py index 9c37e484b1..65e6efee9d 100644 --- a/openstack_dashboard/dashboards/project/access_and_security/keypairs/tables.py +++ b/openstack_dashboard/dashboards/project/access_and_security/keypairs/tables.py @@ -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) diff --git a/openstack_dashboard/dashboards/project/access_and_security/security_groups/tables.py b/openstack_dashboard/dashboards/project/access_and_security/security_groups/tables.py index 40d6c84289..da3b48948c 100644 --- a/openstack_dashboard/dashboards/project/access_and_security/security_groups/tables.py +++ b/openstack_dashboard/dashboards/project/access_and_security/security_groups/tables.py @@ -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