implement domain name validation
- implement domains.forms.relative_domain_validator - use the validator for domain field validation in domains.forms.CreateHostingDomainForm - use the validator for subdomain field validation in websites.forms.AddWebsiteForm
This commit is contained in:
parent
7da5cfe406
commit
7c9509c159
3 changed files with 23 additions and 1 deletions
|
@ -15,6 +15,7 @@ from crispy_forms.layout import (
|
|||
Submit,
|
||||
)
|
||||
|
||||
from domains.forms import relative_domain_validator
|
||||
from .models import Website
|
||||
|
||||
|
||||
|
@ -31,7 +32,10 @@ class AddWebsiteForm(forms.ModelForm):
|
|||
self.hosting_package = kwargs.pop('hostingpackage')
|
||||
self.hosting_domain = kwargs.pop('domain')
|
||||
super(AddWebsiteForm, self).__init__(*args, **kwargs)
|
||||
if Website.objects.filter(wildcard=True).exists():
|
||||
self.fields['subdomain'].validators.append(relative_domain_validator)
|
||||
if Website.objects.filter(
|
||||
wildcard=True, domain=self.hosting_domain
|
||||
).exists():
|
||||
self.fields['wildcard'].widget = forms.HiddenInput()
|
||||
|
||||
self.helper = FormHelper()
|
||||
|
@ -54,6 +58,8 @@ class AddWebsiteForm(forms.ModelForm):
|
|||
).exists():
|
||||
raise forms.ValidationError(
|
||||
_('There is already a website for this subdomain'))
|
||||
relative_domain_validator(
|
||||
"{0}.{1}".format(data, self.hosting_domain.domain))
|
||||
return data
|
||||
|
||||
def save(self, commit=True):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue