Use form field errors on create key pair form
When input a key pair name that is already exist, we will see the error message on the top of the modal form. If the error message beside the key pair name field, it will be more better. This patch is inspired from https://review.openstack.org/#/c/200158/ Change-Id: I5f543063aa3bc90824299b53f18123bac000348e Closes-Bug: #1483191
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
|
||||
import re
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from horizon import exceptions
|
||||
@@ -54,7 +53,8 @@ class CreateKeypair(forms.SelfHandlingForm):
|
||||
exceptions.handle(self.request, ignore=True)
|
||||
keypairs = []
|
||||
if name in [keypair.name for keypair in keypairs]:
|
||||
raise ValidationError(_('The name is already in use.'))
|
||||
error_msg = _("The name is already in use.")
|
||||
self._errors['name'] = self.error_class([error_msg])
|
||||
return cleaned_data
|
||||
|
||||
|
||||
|
||||
@@ -253,4 +253,4 @@ class KeyPairViewTests(test.TestCase):
|
||||
form = CreateKeypair(self.request, data={'name': keypair_name})
|
||||
self.assertFalse(form.is_valid())
|
||||
self.assertIn('The name is already in use.',
|
||||
form.errors['__all__'][0])
|
||||
form.errors['name'][0])
|
||||
|
||||
Reference in New Issue
Block a user