From 02456e92971528e5ac93a978916f13a33e357f83 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 8 Jan 2024 14:20:49 -0700 Subject: [PATCH] Update views.py --- src/api/views.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/api/views.py b/src/api/views.py index a7dd7600a..e40924708 100644 --- a/src/api/views.py +++ b/src/api/views.py @@ -88,10 +88,17 @@ def available(request, domain=""): """ domain = request.GET.get("domain", "") 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 # not. if not (DraftDomain.string_could_be_domain(domain) or DraftDomain.string_could_be_domain(domain + ".gov")): - return JsonResponse({"available": False, "code": "invalid", "message": DOMAIN_API_MESSAGES["invalid"]}) + 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"]}) # a domain is available if it is NOT in the list of current domains try: if check_domain_available(domain):