diff --git a/gbpui/fields.py b/gbpui/fields.py index 4ec3f2b..0028768 100644 --- a/gbpui/fields.py +++ b/gbpui/fields.py @@ -10,10 +10,13 @@ # License for the specific language governing permissions and limitations # under the License. +from itertools import chain + from django.core import urlresolvers from django.forms import fields from django.forms import TextInput from django.forms import widgets +from django.utils.encoding import force_text from django.utils.safestring import mark_safe from django.forms.utils import flatatt @@ -134,6 +137,47 @@ class TransferTableWidget(widgets.SelectMultiple): return mark_safe('\n'.join(output)) + def build_attrs(self, extra_attrs=None, **kwargs): + "Helper function for building an attribute dictionary." + attrs = dict(self.attrs, **kwargs) + if extra_attrs: + attrs.update(extra_attrs) + return attrs + + def render_option(self, selected_choices, option_value, option_label): + if option_value is None: + option_value = '' + option_value = force_text(option_value) + if option_value in selected_choices: + selected_html = mark_safe(' selected="selected"') + if not self.allow_multiple_selected: + # Only allow for a single selection. + selected_choices.remove(option_value) + else: + selected_html = '' + return format_html('', + option_value, + selected_html, + force_text(option_label)) + + def render_options(self, choices, selected_choices): + # Normalize to strings. + selected_choices = set(force_text(v) for v in selected_choices) + output = [] + for option_value, option_label in chain(self.choices, choices): + if isinstance(option_label, (list, tuple)): + output.append(format_html('', + force_text(option_value))) + for option in option_label: + output.append(self.render_option(selected_choices, + *option)) + output.append('') + else: + output.append(self.render_option(selected_choices, + option_value, + option_label)) + return '\n'.join(output) + # ...this adds the 'add item button' just by existing and returning a # true-y value def get_add_item_url(self): diff --git a/gbpui/panels/application_policy/tables.py b/gbpui/panels/application_policy/tables.py index 5d4f902..1b3eecd 100644 --- a/gbpui/panels/application_policy/tables.py +++ b/gbpui/panels/application_policy/tables.py @@ -12,6 +12,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 tables @@ -39,14 +40,26 @@ class UpdateAppPolicyLink(tables.LinkAction): class DeletePolicyRuleSetLink(tables.DeleteAction): name = "deletepolicyruleset" - action_present = _("Delete") - action_past = _("Scheduled deletion of %(data_type)s") - data_type_singular = _("Policy Rule Set") - data_type_plural = _("Policy Rule Sets") def action(self, request, object_id): client.policy_rule_set_delete(request, object_id) + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete Policy Rule Set", + u"Delete Policy Rule Sets", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Scheduled deletion of Policy Rule Set", + u"Scheduled deletion of Policy Rule Sets", + count + ) + class AddPolicyRuleLink(tables.LinkAction): name = "addpolicyrules" @@ -69,14 +82,26 @@ class UpdatePolicyRuleLink(tables.LinkAction): class DeletePolicyRuleLink(tables.DeleteAction): name = "deletepolicyrule" - action_present = _("Delete") - action_past = _("Scheduled deletion of %(data_type)s") - data_type_singular = _("Policy Rule") - data_type_plural = _("Policy Rules") def action(self, request, object_id): client.policyrule_delete(request, object_id) + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete Policy Rule", + u"Delete Policy Rules", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Scheduled deletion of Policy Rule", + u"Scheduled deletion of Policy Rules", + count + ) + class AddPolicyClassifierLink(tables.LinkAction): name = "addpolicyclassifiers" @@ -99,14 +124,26 @@ class UpdatePolicyClassifierLink(tables.LinkAction): class DeletePolicyClassifierLink(tables.DeleteAction): name = "deletepolicyclassifier" - action_present = _("Delete") - action_past = _("Scheduled deletion of %(data_type)s") - data_type_singular = _("Policy Classifier") - data_type_plural = _("Policy Classifiers") def action(self, request, object_id): client.policyclassifier_delete(request, object_id) + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete Policy Classifier", + u"Delete Policy Classifiers", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Scheduled deletion of Policy Classifier", + u"Scheduled deletion of Policy Classifiers", + count + ) + class AddPolicyActionLink(tables.LinkAction): name = "addpolicyactions" @@ -129,14 +166,26 @@ class UpdatePolicyActionLink(tables.LinkAction): class DeletePolicyActionLink(tables.DeleteAction): name = "deletepolicyaction" - action_present = _("Delete") - action_past = _("Scheduled deletion of %(data_type)s") - data_type_singular = _("Policy Action") - data_type_plural = _("Policy Actions") def action(self, request, object_id): client.policyaction_delete(request, object_id) + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete Policy Action", + u"Delete Policy Actions", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Scheduled deletion of Policy Action", + u"Scheduled deletion of Policy Actions", + count + ) + class ApplicationPoliciesTable(tables.DataTable): name = tables.Column("name", diff --git a/gbpui/panels/application_policy/templates/application_policy/_policy_rule_set_details.html b/gbpui/panels/application_policy/templates/application_policy/_policy_rule_set_details.html index 3553cff..a49367a 100644 --- a/gbpui/panels/application_policy/templates/application_policy/_policy_rule_set_details.html +++ b/gbpui/panels/application_policy/templates/application_policy/_policy_rule_set_details.html @@ -1,5 +1,5 @@ {% load i18n sizeformat parse_date %} -{% load url from future %} +

diff --git a/gbpui/panels/application_policy/templates/application_policy/_policyaction_details.html b/gbpui/panels/application_policy/templates/application_policy/_policyaction_details.html index e70d08f..01ec3d2 100644 --- a/gbpui/panels/application_policy/templates/application_policy/_policyaction_details.html +++ b/gbpui/panels/application_policy/templates/application_policy/_policyaction_details.html @@ -1,5 +1,4 @@ {% load i18n sizeformat parse_date %} -{% load url from future %}

diff --git a/gbpui/panels/application_policy/templates/application_policy/_policyclassifier_details.html b/gbpui/panels/application_policy/templates/application_policy/_policyclassifier_details.html index 08f4313..61d83f2 100644 --- a/gbpui/panels/application_policy/templates/application_policy/_policyclassifier_details.html +++ b/gbpui/panels/application_policy/templates/application_policy/_policyclassifier_details.html @@ -1,5 +1,4 @@ {% load i18n sizeformat parse_date %} -{% load url from future %}

diff --git a/gbpui/panels/application_policy/templates/application_policy/_policyrules_details.html b/gbpui/panels/application_policy/templates/application_policy/_policyrules_details.html index aab3aca..74f0308 100644 --- a/gbpui/panels/application_policy/templates/application_policy/_policyrules_details.html +++ b/gbpui/panels/application_policy/templates/application_policy/_policyrules_details.html @@ -1,5 +1,4 @@ {% load i18n sizeformat parse_date %} -{% load url from future %}

diff --git a/gbpui/panels/network_policy/tables.py b/gbpui/panels/network_policy/tables.py index 5a68786..6ed132d 100644 --- a/gbpui/panels/network_policy/tables.py +++ b/gbpui/panels/network_policy/tables.py @@ -12,6 +12,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 tables @@ -38,14 +39,26 @@ class EditL2PolicyLink(tables.LinkAction): class DeleteL2PolicyLink(tables.DeleteAction): name = "deletel2policy" - action_present = _("Delete") - action_past = _("Scheduled deletion of %(data_type)s") - data_type_singular = _("L2Policy") - data_type_plural = _("L2Policies") def action(self, request, object_id): client.l2policy_delete(request, object_id) + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete L2 Policy", + u"Delete L2 Policies", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Scheduled deletion of L2 Policy", + u"Scheduled deletion of L2 Policies", + count + ) + class L2PolicyTable(tables.DataTable): name = tables.Column( @@ -87,14 +100,26 @@ class EditL3PolicyLink(tables.LinkAction): class DeleteL3PolicyLink(tables.DeleteAction): name = "deletel3policy" - action_present = _("Delete") - action_past = _("Scheduled deletion of %(data_type)s") - data_type_singular = _("L3 Policy") - data_type_plural = _("L3 Policies") def action(self, request, object_id): client.l3policy_delete(request, object_id) + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete L3 Policy", + u"Delete L3 Policies", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Scheduled deletion of L3 Policy", + u"Scheduled deletion of L3 Policies", + count + ) + class L3PolicyTable(tables.DataTable): name = tables.Column( @@ -138,14 +163,26 @@ class EditServicePolicyLink(tables.LinkAction): class DeleteServicePolicyLink(tables.DeleteAction): name = "deletespolicy" - action_present = _("Delete") - action_past = _("Scheduled deletion of %(data_type)s") - data_type_singular = _("ServicePolicy") - data_type_plural = _("ServicePolicies") def action(self, request, object_id): client.delete_networkservice_policy(request, object_id) + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete Network Service Policy", + u"Delete Network ServiceL3 Policies", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Scheduled deletion of Network Service Policy", + u"Scheduled deletion of Network Service Policies", + count + ) + class ServicePolicyTable(tables.DataTable): name = tables.Column( @@ -191,14 +228,26 @@ class EditExternalConnectivityLink(tables.LinkAction): class DeleteExternalConnectivityLink(tables.DeleteAction): name = "deleteexternalconnectivity" - action_present = _("Delete") - action_past = _("Scheduled deletion of %(data_type)s") - data_type_singular = _("ExternalConnectivity") - data_type_plural = _("ExternalConnectivities") def action(self, request, object_id): client.delete_externalconnectivity(request, object_id) + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete External Connectivity Policy", + u"Delete External Connectivity Policies", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Scheduled deletion of External Connectivity Policy", + u"Scheduled deletion of External Connectivity Policies", + count + ) + class ExternalConnectivityTable(tables.DataTable): name = tables.Column( @@ -228,14 +277,26 @@ class CreateNATPoolLink(tables.LinkAction): class DeleteNATPoolLink(tables.DeleteAction): name = "deletenatpool" - action_present = _("Delete") - action_past = _("Scheduled deletion of %(data_type)s") - data_type_singular = _("NAT Pool") - data_type_plural = _("NAT Pools") def action(self, request, object_id): client.delete_natpool(request, object_id) + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete NAT Pool", + u"Delete NAT Pools", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Scheduled deletion of NAT Pool", + u"Scheduled deletion of NAT Pools", + count + ) + class EditNATPoolLink(tables.LinkAction): name = "update_nat_pool" diff --git a/gbpui/panels/network_policy/templates/network_policy/_external_connectivity_details.html b/gbpui/panels/network_policy/templates/network_policy/_external_connectivity_details.html index f648e3f..86a8dc7 100644 --- a/gbpui/panels/network_policy/templates/network_policy/_external_connectivity_details.html +++ b/gbpui/panels/network_policy/templates/network_policy/_external_connectivity_details.html @@ -1,5 +1,4 @@ {% load i18n sizeformat parse_date %} -{% load url from future %}

diff --git a/gbpui/panels/network_policy/templates/network_policy/_l2_policy_details.html b/gbpui/panels/network_policy/templates/network_policy/_l2_policy_details.html index 372a191..e96cfe2 100644 --- a/gbpui/panels/network_policy/templates/network_policy/_l2_policy_details.html +++ b/gbpui/panels/network_policy/templates/network_policy/_l2_policy_details.html @@ -1,5 +1,4 @@ {% load i18n sizeformat parse_date %} -{% load url from future %}

diff --git a/gbpui/panels/network_policy/templates/network_policy/_nat_pool_details.html b/gbpui/panels/network_policy/templates/network_policy/_nat_pool_details.html index 300e0f0..aaeb368 100644 --- a/gbpui/panels/network_policy/templates/network_policy/_nat_pool_details.html +++ b/gbpui/panels/network_policy/templates/network_policy/_nat_pool_details.html @@ -1,5 +1,4 @@ {% load i18n sizeformat parse_date %} -{% load url from future %}

diff --git a/gbpui/panels/network_policy/templates/network_policy/_service_policy_details.html b/gbpui/panels/network_policy/templates/network_policy/_service_policy_details.html index 447cb84..35fe226 100644 --- a/gbpui/panels/network_policy/templates/network_policy/_service_policy_details.html +++ b/gbpui/panels/network_policy/templates/network_policy/_service_policy_details.html @@ -1,5 +1,4 @@ {% load i18n sizeformat parse_date %} -{% load url from future %}

diff --git a/gbpui/panels/network_services/tables.py b/gbpui/panels/network_services/tables.py index 3aedb95..db866e5 100644 --- a/gbpui/panels/network_services/tables.py +++ b/gbpui/panels/network_services/tables.py @@ -12,6 +12,7 @@ from django.core.urlresolvers import reverse from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import ungettext_lazy from gbpui import client from horizon import tables @@ -37,14 +38,26 @@ class EditServiceChainSpecLink(tables.LinkAction): class DeleteServiceChainSpecLink(tables.DeleteAction): name = "deletescspec" - action_present = _("Delete") - action_past = _("Scheduled deletion of %(data_type)s") - data_type_singular = _("Service Chain Spec") - data_type_plural = _("Service Chain Specs") def action(self, request, object_id): client.delete_servicechain_spec(request, object_id) + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete Service Chain Spec", + u"Delete Service Chain Specs", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Scheduled deletion of Service Chain Spec", + u"Scheduled deletion of Service Chain Specs", + count + ) + class ServiceChainSpecTable(tables.DataTable): name = tables.Column( @@ -85,14 +98,26 @@ class EditServiceChainNodeLink(tables.LinkAction): class DeleteServiceChainNodeLink(tables.DeleteAction): name = "deletescnode" - action_present = _("Delete") - action_past = _("Scheduled deletion of %(data_type)s") - data_type_singular = _("Service Chain Node") - data_type_plural = _("Service Chain Nodes") def action(self, request, object_id): client.delete_servicechain_node(request, object_id) + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete Service Chain Node", + u"Delete Service Chain Nodes", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Scheduled deletion of Service Chain Node", + u"Scheduled deletion of Service Chain Nodes", + count + ) + class ServiceChainNodeTable(tables.DataTable): name = tables.Column( @@ -134,14 +159,26 @@ class EditServiceChainInstanceLink(tables.LinkAction): class DeleteServiceChainInstanceLink(tables.DeleteAction): name = "deletescinstance" - action_present = _("Delete") - action_past = _("Scheduled deletion of %(data_type)s") - data_type_singular = _("ServiceChainInstance") - data_type_plural = _("ServiceChainInstances") def action(self, request, object_id): client.delete_servicechain_instance(request, object_id) + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete Service Chain Instance", + u"Delete Service Chain Instances", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Scheduled deletion of Service Chain Instance", + u"Scheduled deletion of Service Chain Instances", + count + ) + class ServiceChainInstanceTable(tables.DataTable): name = tables.Column( @@ -175,14 +212,26 @@ class CreateServiceProfileLink(tables.LinkAction): class DeleteServiceProfileLink(tables.DeleteAction): name = "deleteserviceprofile" - action_present = _("Delete") - action_past = _("Scheduled deletion of %(data_type)s") - data_type_singular = _("ServiceProfile") - data_type_plural = _("ServiceProfiles") def action(self, request, object_id): client.delete_service_profile(request, object_id) + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete Service Chain Profile", + u"Delete Service Chain Profiles", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Scheduled deletion of Service Chain Profile", + u"Scheduled deletion of Service Chain Profiles", + count + ) + class ServiceProfileTable(tables.DataTable): name = tables.Column( diff --git a/gbpui/panels/network_services/templates/network_services/_create_service_chain_spec.html b/gbpui/panels/network_services/templates/network_services/_create_service_chain_spec.html index e9b4997..5467902 100644 --- a/gbpui/panels/network_services/templates/network_services/_create_service_chain_spec.html +++ b/gbpui/panels/network_services/templates/network_services/_create_service_chain_spec.html @@ -1,6 +1,5 @@ {% extends "horizon/common/_modal_form.html" %} {% load i18n %} -{% load url from future %} {% block form_id %}create_service_chain_spec{% endblock %} {% block form_action %}{% url 'horizon:project:network_services:create_sc_spec' %}{% endblock %} diff --git a/gbpui/panels/network_services/templates/network_services/_scinstance_details.html b/gbpui/panels/network_services/templates/network_services/_scinstance_details.html index 1988b69..1ff6b7e 100644 --- a/gbpui/panels/network_services/templates/network_services/_scinstance_details.html +++ b/gbpui/panels/network_services/templates/network_services/_scinstance_details.html @@ -1,5 +1,4 @@ {% load i18n sizeformat parse_date %} -{% load url from future %}

diff --git a/gbpui/panels/network_services/templates/network_services/_scnode_details.html b/gbpui/panels/network_services/templates/network_services/_scnode_details.html index f631c0d..739e865 100644 --- a/gbpui/panels/network_services/templates/network_services/_scnode_details.html +++ b/gbpui/panels/network_services/templates/network_services/_scnode_details.html @@ -1,5 +1,4 @@ {% load i18n sizeformat parse_date %} -{% load url from future %} {% load staticfiles %} {% block css %} diff --git a/gbpui/panels/network_services/templates/network_services/_scspec_details.html b/gbpui/panels/network_services/templates/network_services/_scspec_details.html index 14cb7ad..65a9d4f 100644 --- a/gbpui/panels/network_services/templates/network_services/_scspec_details.html +++ b/gbpui/panels/network_services/templates/network_services/_scspec_details.html @@ -1,5 +1,4 @@ {% load i18n sizeformat parse_date %} -{% load url from future %}

diff --git a/gbpui/panels/network_services/templates/network_services/_serviceprofile_details.html b/gbpui/panels/network_services/templates/network_services/_serviceprofile_details.html index 1ff8f10..eaac7a5 100644 --- a/gbpui/panels/network_services/templates/network_services/_serviceprofile_details.html +++ b/gbpui/panels/network_services/templates/network_services/_serviceprofile_details.html @@ -1,5 +1,4 @@ {% load i18n sizeformat parse_date %} -{% load url from future %}

diff --git a/gbpui/panels/network_services/templates/network_services/_update_service_chain_spec.html b/gbpui/panels/network_services/templates/network_services/_update_service_chain_spec.html index 62a4467..212248f 100644 --- a/gbpui/panels/network_services/templates/network_services/_update_service_chain_spec.html +++ b/gbpui/panels/network_services/templates/network_services/_update_service_chain_spec.html @@ -1,6 +1,5 @@ {% extends "horizon/common/_modal_form.html" %} {% load i18n %} -{% load url from future %} {% block form_id %}update_service_chain_spec{% endblock %} {% block form_action %}{% url 'horizon:project:network_services:update_sc_spec' scspec_id %}{% endblock %} diff --git a/gbpui/panels/policytargets/tables.py b/gbpui/panels/policytargets/tables.py index d2a938f..4869545 100644 --- a/gbpui/panels/policytargets/tables.py +++ b/gbpui/panels/policytargets/tables.py @@ -15,6 +15,7 @@ from django.core.urlresolvers import reverse from django import http from django import shortcuts from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables @@ -41,14 +42,26 @@ class UpdatePTGLink(tables.LinkAction): class DeletePTGLink(tables.DeleteAction): name = "deletepolicytarget" - action_present = _("Delete") - action_past = _("Scheduled deletion of %(data_type)s") - data_type_singular = _("Group") - data_type_plural = _("Groups") def action(self, request, object_id): client.policy_target_delete(request, object_id) + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete Group", + u"Delete Groups", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Scheduled deletion of Group", + u"Scheduled deletion of Groups", + count + ) + class AddPTGLink(tables.LinkAction): name = "addpolicy_target" @@ -102,14 +115,26 @@ class AddExternalPTGLink(tables.LinkAction): class DeleteExternalPTGLink(tables.DeleteAction): name = "deleteexternalpolicytarget" - action_present = _("Delete") - action_past = _("Scheduled deletion of %(data_type)s") - data_type_singular = _("Group") - data_type_plural = _("Groups") def action(self, request, object_id): client.ext_policy_target_delete(request, object_id) + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete External Group", + u"Delete External Groups", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Scheduled deletion of External Group", + u"Scheduled deletion of External Groups", + count + ) + class ExternalPTGsTable(tables.DataTable): name = tables.Column( @@ -163,8 +188,22 @@ class LaunchVMLink(tables.LinkAction): class RemoveVMLink(tables.DeleteAction): - data_type_singular = _("Member") - data_type_plural = _("Members") + + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete Member", + u"Delete Members", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Deleted Member", + u"Deleted Members", + count + ) def delete(self, request, instance_id): url = reverse("horizon:project:policytargets:policy_targetdetails", diff --git a/gbpui/panels/policytargets/templates/policytargets/_policy_target_details.html b/gbpui/panels/policytargets/templates/policytargets/_policy_target_details.html index f38d132..ee1e6ca 100644 --- a/gbpui/panels/policytargets/templates/policytargets/_policy_target_details.html +++ b/gbpui/panels/policytargets/templates/policytargets/_policy_target_details.html @@ -1,5 +1,4 @@ {% load i18n sizeformat parse_date %} -{% load url from future %}