Minor styling fixes for domain name validator

This commit is contained in:
Sunil Mohan Adapa 2015-11-16 21:56:49 +05:30
parent e7fb549349
commit cc181c79c3
2 changed files with 6 additions and 6 deletions

View File

@ -60,11 +60,12 @@ class TrimmedCharField(forms.CharField):
return super(TrimmedCharField, self).clean(value)
def domain_labelvalidator(domainname):
"""Validating Domain Name Labels"""
for label in domainname.split("."):
def domain_label_validator(domainname):
"""Validate domain name labels."""
for label in domainname.split('.'):
if not re.match(HOSTNAME_REGEX, label):
raise ValidationError(ugettext_lazy('Invalid Domain Name'))
raise ValidationError(_('Invalid domain name'))
class ConfigurationForm(forms.Form):
"""Main system configuration form"""
@ -101,7 +102,7 @@ class ConfigurationForm(forms.Form):
validators.RegexValidator(
r'^[a-zA-Z0-9]([-a-zA-Z0-9.]{,251}[a-zA-Z0-9])?$',
ugettext_lazy('Invalid domain name')),
domain_labelvalidator])
domain_label_validator])
def init():

View File

@ -47,7 +47,6 @@ class TestConfig(unittest.TestCase):
def test_domainname_field(self):
"""Test that domainname field accepts only valid domainnames."""
valid_domainnames = [
'', 'a', '0a', 'a0', 'AAA', '00', '0-0', 'example-hostname',
'example', 'example.org', 'a.b.c.d', 'a-0.b-0.c-0',