Update views.py

This commit is contained in:
zandercymatics 2024-01-08 14:20:49 -07:00
parent f8d2898836
commit 02456e9297
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7

View file

@ -88,9 +88,16 @@ def available(request, domain=""):
""" """
domain = request.GET.get("domain", "") domain = request.GET.get("domain", "")
DraftDomain = apps.get_model("registrar.DraftDomain") DraftDomain = apps.get_model("registrar.DraftDomain")
if domain is None or domain.strip() == "":
# TODO - change this... should it be the regular required?
return JsonResponse({"available": False, "code": "invalid", "message": "This field is required"})
# validate that the given domain could be a domain name and fail early if # validate that the given domain could be a domain name and fail early if
# not. # not.
if not (DraftDomain.string_could_be_domain(domain) or DraftDomain.string_could_be_domain(domain + ".gov")): if not (DraftDomain.string_could_be_domain(domain) or DraftDomain.string_could_be_domain(domain + ".gov")):
print(f"What is the domain at this point? {domain}")
if "." in domain:
return JsonResponse({"available": False, "code": "invalid", "message": DOMAIN_API_MESSAGES["extra_dots"]})
else:
return JsonResponse({"available": False, "code": "invalid", "message": DOMAIN_API_MESSAGES["invalid"]}) return JsonResponse({"available": False, "code": "invalid", "message": DOMAIN_API_MESSAGES["invalid"]})
# a domain is available if it is NOT in the list of current domains # a domain is available if it is NOT in the list of current domains
try: try: