Correct error messages on create and update router form
The name is not required, so data["name"] may be empty.
When data["name"] is empty, get the id value.
This patch correct error messages on create and update form
@@ -145,7 +145,10 @@ class CreateForm(forms.SelfHandlingForm):
if exc.status_code == 409:
msg = _('Quota exceeded for resource router.')
else:
+ if data["name"]:
msg = _('Failed to create router "%s".') % data['name']
+ else:
+ msg = _('Failed to create router.')
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)
return False
@@ -203,5 +206,6 @@ class UpdateForm(forms.SelfHandlingForm):
except Exception as exc:
LOG.info('Failed to update router %(id)s: %(exc)s',
{'id': self.initial['router_id'], 'exc': exc})
- msg = _('Failed to update router %s') % data['name']
+ name_or_id = data['name'] or self.initial['router_id']
+ msg = _('Failed to update router %s') % name_or_id
exceptions.handle(request, msg, redirect=self.redirect_url)
