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:
parent
8737813e8d
commit
7fdebb62f3
@ -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])
|
||||
|
||||
|
@ -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])
|
||||
|
||||
|
@ -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])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user