From 7fdebb62f3d99ccdefa362fc0222fb5015de7b17 Mon Sep 17 00:00:00 2001 From: "chen.qiaomin@99cloud.net" Date: Fri, 1 Jul 2016 10:30:53 +0000 Subject: [PATCH] Use "isspace()" to make code more simple Use "isspace()" to replace "len()" and "strip()" function, reducing one a judgment step. Change-Id: I4c33f356402ab254ff80d59f0d32ed1390536a3e --- openstack_dashboard/dashboards/admin/flavors/workflows.py | 2 +- .../dashboards/admin/volumes/volume_types/forms.py | 4 ++-- .../dashboards/project/volumes/volumes/forms.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/openstack_dashboard/dashboards/admin/flavors/workflows.py b/openstack_dashboard/dashboards/admin/flavors/workflows.py index 00f8228821..830e4bf043 100644 --- a/openstack_dashboard/dashboards/admin/flavors/workflows.py +++ b/openstack_dashboard/dashboards/admin/flavors/workflows.py @@ -73,7 +73,7 @@ class CreateFlavorInfoAction(workflows.Action): name = cleaned_data.get('name') flavor_id = cleaned_data.get('flavor_id') - if name and len(name.strip()) == 0: + if name and name.isspace(): msg = _('Flavor name cannot be empty.') self._errors['name'] = self.error_class([msg]) diff --git a/openstack_dashboard/dashboards/admin/volumes/volume_types/forms.py b/openstack_dashboard/dashboards/admin/volumes/volume_types/forms.py index 6de23194ce..63e24ba0b2 100644 --- a/openstack_dashboard/dashboards/admin/volumes/volume_types/forms.py +++ b/openstack_dashboard/dashboards/admin/volumes/volume_types/forms.py @@ -37,7 +37,7 @@ class CreateVolumeType(forms.SelfHandlingForm): def clean_name(self): cleaned_name = self.cleaned_data['name'] - if len(cleaned_name.strip()) == 0: + if cleaned_name.isspace(): raise ValidationError(_('Volume type name can not be empty.')) return cleaned_name @@ -276,7 +276,7 @@ class EditVolumeType(forms.SelfHandlingForm): def clean_name(self): cleaned_name = self.cleaned_data['name'] - if len(cleaned_name.strip()) == 0: + if cleaned_name.isspace(): msg = _('New name cannot be empty.') self._errors['name'] = self.error_class([msg]) diff --git a/openstack_dashboard/dashboards/project/volumes/volumes/forms.py b/openstack_dashboard/dashboards/project/volumes/volumes/forms.py index 63eee50723..829a5245b0 100644 --- a/openstack_dashboard/dashboards/project/volumes/volumes/forms.py +++ b/openstack_dashboard/dashboards/project/volumes/volumes/forms.py @@ -539,7 +539,7 @@ class CreateTransferForm(forms.SelfHandlingForm): def clean_name(self): cleaned_name = self.cleaned_data['name'] - if len(cleaned_name.strip()) == 0: + if cleaned_name.isspace(): msg = _('Volume transfer name cannot be empty.') self._errors['name'] = self.error_class([msg])