mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-30 09:20:15 +02:00
wip on validation in form
This commit is contained in:
parent
1a01fdc98d
commit
8dba1234c1
1 changed files with 25 additions and 7 deletions
|
@ -5,8 +5,9 @@ from django.core.validators import MinValueValidator, MaxValueValidator, RegexVa
|
||||||
from django.forms import formset_factory
|
from django.forms import formset_factory
|
||||||
|
|
||||||
from phonenumber_field.widgets import RegionalPhoneNumberWidget
|
from phonenumber_field.widgets import RegionalPhoneNumberWidget
|
||||||
|
from registrar.utility.errors import NameserverError
|
||||||
|
|
||||||
from ..models import Contact, DomainInformation
|
from ..models import Contact, DomainInformation, Domain
|
||||||
from .common import (
|
from .common import (
|
||||||
ALGORITHM_CHOICES,
|
ALGORITHM_CHOICES,
|
||||||
DIGEST_TYPE_CHOICES,
|
DIGEST_TYPE_CHOICES,
|
||||||
|
@ -21,18 +22,35 @@ class DomainAddUserForm(forms.Form):
|
||||||
email = forms.EmailField(label="Email")
|
email = forms.EmailField(label="Email")
|
||||||
|
|
||||||
|
|
||||||
|
class IPAddressField(forms.CharField):
|
||||||
|
# def __init__(self, server_value, *args, **kwargs):
|
||||||
|
# self.server_value = server_value
|
||||||
|
# super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def validate(self, value):
|
||||||
|
super().validate(value) # Run the default CharField validation
|
||||||
|
|
||||||
|
ip_list = [ip.strip() for ip in value.split(",")] # Split IPs and remove whitespace
|
||||||
|
|
||||||
|
# TODO: pass hostname from view?
|
||||||
|
hostname = ""
|
||||||
|
|
||||||
|
# Call the IP validation method from Domain
|
||||||
|
try:
|
||||||
|
Domain.checkHostIPCombo(hostname, ip_list)
|
||||||
|
except NameserverError as e:
|
||||||
|
raise forms.ValidationError(str(e))
|
||||||
|
|
||||||
|
|
||||||
class DomainNameserverForm(forms.Form):
|
class DomainNameserverForm(forms.Form):
|
||||||
"""Form for changing nameservers."""
|
"""Form for changing nameservers."""
|
||||||
|
|
||||||
server = forms.CharField(label="Name server", strip=True)
|
server = forms.CharField(label="Name server", strip=True)
|
||||||
|
|
||||||
ip = forms.CharField(
|
ip = IPAddressField(
|
||||||
label="IP address",
|
label="IP address",
|
||||||
strip=True,
|
strip=True,
|
||||||
required=False,
|
required=False,
|
||||||
validators=[
|
|
||||||
# TODO in progress
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue