Fix blanks

This commit is contained in:
zandercymatics 2024-01-09 13:36:09 -07:00
parent ab6cbb93c6
commit 6b6aed8f24
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 5 additions and 8 deletions

View file

@ -384,7 +384,7 @@ class AlternativeDomainForm(RegistrarForm):
"""Validation code for domain names."""
requested = self.cleaned_data.get("alternative_domain", None)
validated = DraftDomain.validate_and_handle_errors(
requested, ValidationErrorReturnType.FORM_VALIDATION_ERROR, prevent_blank=False
requested, ValidationErrorReturnType.FORM_VALIDATION_ERROR, blank_ok=True
)
return validated

View file

@ -57,7 +57,7 @@ class DomainHelper:
return domain
@classmethod
def validate_and_handle_errors(cls, domain, error_return_type, prevent_blank=True, display_success=False):
def validate_and_handle_errors(cls, domain, error_return_type, blank_ok=False, display_success=False):
"""
Validates the provided domain and handles any validation errors.
@ -71,7 +71,7 @@ class DomainHelper:
Args:
domain (str): The domain to validate.
error_return_type (ValidationErrorReturnType): The type of error response to return if validation fails.
prevent_blank (bool, optional): Whether to return an exception if the input is blank. Defaults to True.
blank_ok (bool, optional): Whether to return an exception if the input is blank. Defaults to False.
display_success (bool, optional): Whether to return a success response if validation is successful. Defaults to False.
Returns:
@ -81,12 +81,9 @@ class DomainHelper:
""" # noqa
try:
validated = cls.validate(domain)
validated = cls.validate(domain, blank_ok)
except errors.BlankValueError:
if not prevent_blank:
return DomainHelper._return_form_error_or_json_response(error_return_type, code="required")
else:
return validated
return DomainHelper._return_form_error_or_json_response(error_return_type, code="required")
except errors.ExtraDotsError:
return DomainHelper._return_form_error_or_json_response(error_return_type, code="extra_dots")
except errors.DomainUnavailableError: