Use "isspace()" to make code more simple

Use "isspace()" to replace "len()" and "strip()" function, reducing one
a judgment step.

Change-Id: I4c33f356402ab254ff80d59f0d32ed1390536a3e
This commit is contained in:
chen.qiaomin@99cloud.net 2016-07-01 10:30:53 +00:00
parent 8737813e8d
commit 7fdebb62f3
3 changed files with 4 additions and 4 deletions

View File

@ -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])

View File

@ -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])

View File

@ -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])