mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-18 02:19:23 +02:00
Respond to PR feedback
This commit is contained in:
parent
456cab6cee
commit
b3784776d7
22 changed files with 54 additions and 62 deletions
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from django.core.exceptions import BadRequest
|
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.test import TestCase, RequestFactory
|
from django.test import TestCase, RequestFactory
|
||||||
|
|
||||||
|
@ -85,8 +84,8 @@ class AvailableViewTest(TestCase):
|
||||||
bad_string = "blah!;"
|
bad_string = "blah!;"
|
||||||
request = self.factory.get(API_BASE_PATH + bad_string)
|
request = self.factory.get(API_BASE_PATH + bad_string)
|
||||||
request.user = self.user
|
request.user = self.user
|
||||||
with self.assertRaisesMessage(BadRequest, "Invalid"):
|
response = available(request, domain=bad_string)
|
||||||
available(request, domain=bad_string)
|
self.assertFalse(json.loads(response.content)["available"])
|
||||||
|
|
||||||
|
|
||||||
class AvailableAPITest(TestCase):
|
class AvailableAPITest(TestCase):
|
||||||
|
@ -108,9 +107,3 @@ class AvailableAPITest(TestCase):
|
||||||
with less_console_noise():
|
with less_console_noise():
|
||||||
response = self.client.post(API_BASE_PATH + "nonsense")
|
response = self.client.post(API_BASE_PATH + "nonsense")
|
||||||
self.assertEqual(response.status_code, 405)
|
self.assertEqual(response.status_code, 405)
|
||||||
|
|
||||||
def test_available_bad_input(self):
|
|
||||||
self.client.force_login(self.user)
|
|
||||||
with less_console_noise():
|
|
||||||
response = self.client.get(API_BASE_PATH + "blah!;")
|
|
||||||
self.assertEqual(response.status_code, 400)
|
|
||||||
|
|
|
@ -83,18 +83,15 @@ def available(request, domain=""):
|
||||||
Domain.string_could_be_domain(domain)
|
Domain.string_could_be_domain(domain)
|
||||||
or Domain.string_could_be_domain(domain + ".gov")
|
or Domain.string_could_be_domain(domain + ".gov")
|
||||||
):
|
):
|
||||||
return JsonResponse({
|
return JsonResponse(
|
||||||
"available": False,
|
{"available": False, "message": DOMAIN_API_MESSAGES["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
|
||||||
if in_domains(domain):
|
if in_domains(domain):
|
||||||
return JsonResponse({
|
return JsonResponse(
|
||||||
"available": False,
|
{"available": False, "message": DOMAIN_API_MESSAGES["unavailable"]}
|
||||||
"message": DOMAIN_API_MESSAGES["unavailable"]
|
)
|
||||||
})
|
|
||||||
else:
|
else:
|
||||||
return JsonResponse({
|
return JsonResponse(
|
||||||
"available": True,
|
{"available": True, "message": DOMAIN_API_MESSAGES["success"]}
|
||||||
"message": DOMAIN_API_MESSAGES["success"]
|
)
|
||||||
})
|
|
||||||
|
|
|
@ -416,6 +416,7 @@ CurrentSitesFormSet = forms.formset_factory(
|
||||||
formset=BaseCurrentSitesFormSet,
|
formset=BaseCurrentSitesFormSet,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class AlternativeDomainForm(RegistrarForm):
|
class AlternativeDomainForm(RegistrarForm):
|
||||||
def clean_alternative_domain(self):
|
def clean_alternative_domain(self):
|
||||||
"""Validation code for domain names."""
|
"""Validation code for domain names."""
|
||||||
|
@ -423,19 +424,23 @@ class AlternativeDomainForm(RegistrarForm):
|
||||||
requested = self.cleaned_data.get("alternative_domain", None)
|
requested = self.cleaned_data.get("alternative_domain", None)
|
||||||
validated = Domain.validate(requested, blank_ok=True)
|
validated = Domain.validate(requested, blank_ok=True)
|
||||||
except errors.ExtraDotsError:
|
except errors.ExtraDotsError:
|
||||||
raise forms.ValidationError(code="extra_dots")
|
raise forms.ValidationError(
|
||||||
|
DOMAIN_API_MESSAGES["extra_dots"], code="extra_dots"
|
||||||
|
)
|
||||||
except errors.DomainUnavailableError:
|
except errors.DomainUnavailableError:
|
||||||
raise forms.ValidationError(code="unavailable")
|
raise forms.ValidationError(
|
||||||
|
DOMAIN_API_MESSAGES["unavailable"], code="unavailable"
|
||||||
|
)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise forms.ValidationError(code="invalid")
|
raise forms.ValidationError(DOMAIN_API_MESSAGES["invalid"], code="invalid")
|
||||||
return validated
|
return validated
|
||||||
|
|
||||||
alternative_domain = forms.CharField(
|
alternative_domain = forms.CharField(
|
||||||
required=False,
|
required=False,
|
||||||
label="Alternative domain",
|
label="Alternative domain",
|
||||||
error_messages=DOMAIN_API_MESSAGES
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class BaseAlternativeDomainFormSet(RegistrarFormSet):
|
class BaseAlternativeDomainFormSet(RegistrarFormSet):
|
||||||
JOIN = "alternative_domains"
|
JOIN = "alternative_domains"
|
||||||
|
|
||||||
|
@ -508,19 +513,22 @@ class DotGovDomainForm(RegistrarForm):
|
||||||
requested = self.cleaned_data.get("requested_domain", None)
|
requested = self.cleaned_data.get("requested_domain", None)
|
||||||
validated = Domain.validate(requested)
|
validated = Domain.validate(requested)
|
||||||
except errors.BlankValueError:
|
except errors.BlankValueError:
|
||||||
raise forms.ValidationError(code="required")
|
raise forms.ValidationError(
|
||||||
|
DOMAIN_API_MESSAGES["required"], code="required"
|
||||||
|
)
|
||||||
except errors.ExtraDotsError:
|
except errors.ExtraDotsError:
|
||||||
raise forms.ValidationError(code="extra_dots")
|
raise forms.ValidationError(
|
||||||
|
DOMAIN_API_MESSAGES["extra_dots"], code="extra_dots"
|
||||||
|
)
|
||||||
except errors.DomainUnavailableError:
|
except errors.DomainUnavailableError:
|
||||||
raise forms.ValidationError(code="unavailable")
|
raise forms.ValidationError(
|
||||||
|
DOMAIN_API_MESSAGES["unavailable"], code="unavailable"
|
||||||
|
)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise forms.ValidationError(code="invalid")
|
raise forms.ValidationError(DOMAIN_API_MESSAGES["invalid"], code="invalid")
|
||||||
return validated
|
return validated
|
||||||
|
|
||||||
requested_domain = forms.CharField(
|
requested_domain = forms.CharField(label="What .gov domain do you want?")
|
||||||
label="What .gov domain do you want?",
|
|
||||||
error_messages=DOMAIN_API_MESSAGES
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class PurposeForm(RegistrarForm):
|
class PurposeForm(RegistrarForm):
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
|
|
||||||
|
|
||||||
{% block form_fields %}
|
{% block form_fields %}
|
||||||
{% csrf_token %}
|
|
||||||
{% with add_label_class="usa-sr-only" attr_maxlength=500 %}
|
{% with add_label_class="usa-sr-only" attr_maxlength=500 %}
|
||||||
{% input_with_errors forms.0.anything_else %}
|
{% input_with_errors forms.0.anything_else %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
|
|
||||||
|
|
||||||
{% block form_fields %}
|
{% block form_fields %}
|
||||||
{% csrf_token %}
|
|
||||||
<fieldset class="usa-fieldset">
|
<fieldset class="usa-fieldset">
|
||||||
<legend class="usa-sr-only">
|
<legend class="usa-sr-only">
|
||||||
Who is the authorizing official for your organization?
|
Who is the authorizing official for your organization?
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
{% extends 'application_form.html' %}
|
{% extends 'application_form.html' %}
|
||||||
{% load static %}
|
{% load static field_helpers %}
|
||||||
{% load field_helpers %}
|
|
||||||
|
|
||||||
{% block form_instructions %}
|
{% block form_instructions %}
|
||||||
<p>Enter your organization’s public website, if you have one. For example,
|
<p>Enter your organization’s public website, if you have one. For example,
|
||||||
|
@ -9,7 +8,6 @@
|
||||||
|
|
||||||
|
|
||||||
{% block form_fields %}
|
{% block form_fields %}
|
||||||
{% csrf_token %}
|
|
||||||
{{ forms.0.management_form }}
|
{{ forms.0.management_form }}
|
||||||
|
|
||||||
{% for form in forms.0 %}
|
{% for form in forms.0 %}
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
|
|
||||||
|
|
||||||
{% block form_fields %}
|
{% block form_fields %}
|
||||||
{% csrf_token %}
|
|
||||||
<fieldset class="usa-fieldset">
|
<fieldset class="usa-fieldset">
|
||||||
<legend class="usa-sr-only">
|
<legend class="usa-sr-only">
|
||||||
What is the name and mailing address of your organization?
|
What is the name and mailing address of your organization?
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
|
|
||||||
{% block form_fields %}
|
{% block form_fields %}
|
||||||
{% csrf_token %}
|
|
||||||
{% with add_class="usa-radio__input--tile" %}
|
{% with add_class="usa-radio__input--tile" %}
|
||||||
{% input_with_errors forms.0.is_election_board %}
|
{% input_with_errors forms.0.is_election_board %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
|
|
||||||
{% block form_fields %}
|
{% block form_fields %}
|
||||||
{% csrf_token %}
|
|
||||||
{% with add_class="usa-radio__input--tile" %}
|
{% with add_class="usa-radio__input--tile" %}
|
||||||
{% input_with_errors forms.0.federal_type %}
|
{% input_with_errors forms.0.federal_type %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
|
|
||||||
{% block form_fields %}
|
{% block form_fields %}
|
||||||
{% csrf_token %}
|
|
||||||
{% with add_class="usa-radio__input--tile" %}
|
{% with add_class="usa-radio__input--tile" %}
|
||||||
{% input_with_errors forms.0.organization_type %}
|
{% input_with_errors forms.0.organization_type %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
{% extends 'application_form.html' %}
|
{% extends 'application_form.html' %}
|
||||||
{% load static %}
|
{% load static field_helpers %}
|
||||||
{% load field_helpers %}
|
|
||||||
|
|
||||||
{% block form_instructions %}
|
{% block form_instructions %}
|
||||||
<p>We’d like to contact other employees with administrative or technical
|
<p>We’d like to contact other employees with administrative or technical
|
||||||
|
@ -12,7 +11,6 @@
|
||||||
|
|
||||||
|
|
||||||
{% block form_fields %}
|
{% block form_fields %}
|
||||||
{% csrf_token %}
|
|
||||||
{{ forms.0.management_form }}
|
{{ forms.0.management_form }}
|
||||||
{# forms.0 is a formset and this iterates over its forms #}
|
{# forms.0 is a formset and this iterates over its forms #}
|
||||||
{% for form in forms.0.forms %}
|
{% for form in forms.0.forms %}
|
||||||
|
@ -21,8 +19,6 @@
|
||||||
<h2>Contact {{ forloop.counter }}</h2>
|
<h2>Contact {{ forloop.counter }}</h2>
|
||||||
</legend>
|
</legend>
|
||||||
|
|
||||||
{% if form.is_bound %}HAS INITIAL DATA{% else %}NO INITIAL DATA{% endif %}
|
|
||||||
|
|
||||||
{% input_with_errors form.first_name %}
|
{% input_with_errors form.first_name %}
|
||||||
|
|
||||||
{% input_with_errors form.middle_name %}
|
{% input_with_errors form.middle_name %}
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
|
|
||||||
|
|
||||||
{% block form_fields %}
|
{% block form_fields %}
|
||||||
{% csrf_token %}
|
|
||||||
{% with attr_maxlength=500 %}
|
{% with attr_maxlength=500 %}
|
||||||
{% input_with_errors forms.0.purpose %}
|
{% input_with_errors forms.0.purpose %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
|
|
@ -183,7 +183,6 @@
|
||||||
|
|
||||||
|
|
||||||
{% block form_fields %}
|
{% block form_fields %}
|
||||||
{% csrf_token %}
|
|
||||||
<fieldset class="usa-fieldset">
|
<fieldset class="usa-fieldset">
|
||||||
<legend>
|
<legend>
|
||||||
<h2>Acknowledgement of .gov domain requirements</h2>
|
<h2>Acknowledgement of .gov domain requirements</h2>
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
{% load static url_helpers %}
|
{% load static url_helpers %}
|
||||||
|
|
||||||
{% block form_fields %}
|
{% block form_fields %}
|
||||||
{% csrf_token %}
|
|
||||||
|
|
||||||
{% for step in steps.all|slice:":-1" %}
|
{% for step in steps.all|slice:":-1" %}
|
||||||
<section class="review__step margin-top-205">
|
<section class="review__step margin-top-205">
|
||||||
<hr />
|
<hr />
|
||||||
|
|
|
@ -10,6 +10,5 @@
|
||||||
|
|
||||||
|
|
||||||
{% block form_fields %}
|
{% block form_fields %}
|
||||||
{% csrf_token %}
|
|
||||||
{% input_with_errors forms.0.security_email %}
|
{% input_with_errors forms.0.security_email %}
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
|
|
||||||
{% block form_fields %}
|
{% block form_fields %}
|
||||||
{% csrf_token %}
|
|
||||||
{% input_with_errors forms.0.tribe_name %}
|
{% input_with_errors forms.0.tribe_name %}
|
||||||
<fieldset class="usa-fieldset">
|
<fieldset class="usa-fieldset">
|
||||||
<legend class="usa-legend">
|
<legend class="usa-legend">
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
|
|
||||||
{% block form_fields %}
|
{% block form_fields %}
|
||||||
{% csrf_token %}
|
|
||||||
{% with attr_maxlength=500 %}
|
{% with attr_maxlength=500 %}
|
||||||
{% input_with_errors forms.0.type_of_work %}
|
{% input_with_errors forms.0.type_of_work %}
|
||||||
{% input_with_errors forms.0.more_organization_information %}
|
{% input_with_errors forms.0.more_organization_information %}
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
|
|
||||||
|
|
||||||
{% block form_fields %}
|
{% block form_fields %}
|
||||||
{% csrf_token %}
|
|
||||||
<fieldset class="usa-fieldset">
|
<fieldset class="usa-fieldset">
|
||||||
<legend class="usa-sr-only">
|
<legend class="usa-sr-only">
|
||||||
Your contact information
|
Your contact information
|
||||||
|
|
|
@ -7,7 +7,6 @@ Edit your User Profile
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<main id="main-content" class="grid-container">
|
<main id="main-content" class="grid-container">
|
||||||
<form class="usa-form usa-form--large" method="post" enctype="multipart/form-data">
|
<form class="usa-form usa-form--large" method="post" enctype="multipart/form-data">
|
||||||
{% csrf_token %}
|
|
||||||
<fieldset class="usa-fieldset">
|
<fieldset class="usa-fieldset">
|
||||||
<legend class="usa-legend usa-legend--large">Your profile</legend>
|
<legend class="usa-legend usa-legend--large">Your profile</legend>
|
||||||
<p>
|
<p>
|
||||||
|
|
|
@ -35,6 +35,11 @@ def input_with_errors(context, field=None): # noqa: C901
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{% endfor }
|
{% endfor }
|
||||||
|
|
||||||
|
There are a few edge cases to keep in mind:
|
||||||
|
- a "maxlength" attribute will cause the input to use USWDS Character counter
|
||||||
|
- the field's `use_fieldset` controls whether the output is label/field or
|
||||||
|
fieldset/legend/field
|
||||||
|
- checkbox label styling is different (this is handled, don't worry about it)
|
||||||
"""
|
"""
|
||||||
context = context.flatten()
|
context = context.flatten()
|
||||||
context["field"] = field
|
context["field"] = field
|
||||||
|
@ -54,6 +59,12 @@ def input_with_errors(context, field=None): # noqa: C901
|
||||||
classes.append(attrs.pop("class"))
|
classes.append(attrs.pop("class"))
|
||||||
|
|
||||||
# parse context for field attributes and classes
|
# parse context for field attributes and classes
|
||||||
|
# ---
|
||||||
|
# here we loop through all items in the context dictionary
|
||||||
|
# (this is the context which was being used to render the
|
||||||
|
# outer template in which this {% input_with_errors %} appeared!)
|
||||||
|
# and look for "magic" keys -- these are used to modify the
|
||||||
|
# appearance and behavior of the final HTML
|
||||||
for key, value in context.items():
|
for key, value in context.items():
|
||||||
if key.startswith("attr_"):
|
if key.startswith("attr_"):
|
||||||
attr_name = re.sub("_", "-", key[5:])
|
attr_name = re.sub("_", "-", key[5:])
|
||||||
|
|
|
@ -219,7 +219,11 @@ class ApplicationWizard(LoginRequiredMixin, TemplateView):
|
||||||
return render(request, self.template_name, context)
|
return render(request, self.template_name, context)
|
||||||
|
|
||||||
def get_all_forms(self, **kwargs) -> list:
|
def get_all_forms(self, **kwargs) -> list:
|
||||||
"""Calls `get_forms` for all steps and returns a flat list."""
|
"""
|
||||||
|
Calls `get_forms` for all steps and returns a flat list.
|
||||||
|
|
||||||
|
All arguments (**kwargs) are passed directly to `get_forms`.
|
||||||
|
"""
|
||||||
nested = (self.get_forms(step=step, **kwargs) for step in self.steps)
|
nested = (self.get_forms(step=step, **kwargs) for step in self.steps)
|
||||||
flattened = [form for lst in nested for form in lst]
|
flattened = [form for lst in nested for form in lst]
|
||||||
return flattened
|
return flattened
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue