Modify the error message when creating subnet

The error message is incorrect:
'Specify "Network Address" or clear "Create Subnet" checkbox in previous step'
on create subnet page, It has no previous step

Change-Id: Ib91c29d8de7f75744f38bd624234e6f2416673e1
Closes-Bug: #1812157
This commit is contained in:
pengyuesheng 2019-01-17 14:12:56 +08:00
parent 64542397d8
commit 4624438f17
2 changed files with 10 additions and 5 deletions

View File

@ -41,7 +41,7 @@ class CreateSubnetInfoAction(network_workflows.CreateSubnetInfoAction):
def clean(self):
cleaned_data = workflows.Action.clean(self)
self._check_subnet_data(cleaned_data)
self._check_subnet_data(cleaned_data, with_network_form=False)
return cleaned_data
@ -114,7 +114,8 @@ class UpdateSubnetInfoAction(CreateSubnetInfoAction):
def clean(self):
cleaned_data = workflows.Action.clean(self)
self._check_subnet_data(cleaned_data, is_create=False)
self._check_subnet_data(cleaned_data, is_create=False,
with_network_form=False)
return cleaned_data

View File

@ -279,7 +279,8 @@ class CreateSubnetInfoAction(workflows.Action):
'allowed': range_str})
raise forms.ValidationError(msg)
def _check_subnet_data(self, cleaned_data, is_create=True):
def _check_subnet_data(self, cleaned_data, is_create=True,
with_network_form=True):
cidr = cleaned_data.get('cidr')
ip_version = int(cleaned_data.get('ip_version'))
gateway_ip = cleaned_data.get('gateway_ip')
@ -293,8 +294,11 @@ class CreateSubnetInfoAction(workflows.Action):
'"Network Address".')
raise forms.ValidationError(msg)
if not cidr and address_source != 'subnetpool':
msg = _('Specify "Network Address" or '
'clear "Create Subnet" checkbox in previous step.')
if with_network_form:
msg = _('Specify "Network Address" or '
'clear "Create Subnet" checkbox in previous step.')
else:
msg = _("Specify network address")
raise forms.ValidationError(msg)
if cidr:
subnet = netaddr.IPNetwork(cidr)