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
|
||||
|
||||
from django.core.exceptions import BadRequest
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.test import TestCase, RequestFactory
|
||||
|
||||
|
@ -85,8 +84,8 @@ class AvailableViewTest(TestCase):
|
|||
bad_string = "blah!;"
|
||||
request = self.factory.get(API_BASE_PATH + bad_string)
|
||||
request.user = self.user
|
||||
with self.assertRaisesMessage(BadRequest, "Invalid"):
|
||||
available(request, domain=bad_string)
|
||||
response = available(request, domain=bad_string)
|
||||
self.assertFalse(json.loads(response.content)["available"])
|
||||
|
||||
|
||||
class AvailableAPITest(TestCase):
|
||||
|
@ -108,9 +107,3 @@ class AvailableAPITest(TestCase):
|
|||
with less_console_noise():
|
||||
response = self.client.post(API_BASE_PATH + "nonsense")
|
||||
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)
|
||||
or Domain.string_could_be_domain(domain + ".gov")
|
||||
):
|
||||
return JsonResponse({
|
||||
"available": False,
|
||||
"message": DOMAIN_API_MESSAGES["invalid"]
|
||||
})
|
||||
return JsonResponse(
|
||||
{"available": False, "message": DOMAIN_API_MESSAGES["invalid"]}
|
||||
)
|
||||
# a domain is available if it is NOT in the list of current domains
|
||||
if in_domains(domain):
|
||||
return JsonResponse({
|
||||
"available": False,
|
||||
"message": DOMAIN_API_MESSAGES["unavailable"]
|
||||
})
|
||||
return JsonResponse(
|
||||
{"available": False, "message": DOMAIN_API_MESSAGES["unavailable"]}
|
||||
)
|
||||
else:
|
||||
return JsonResponse({
|
||||
"available": True,
|
||||
"message": DOMAIN_API_MESSAGES["success"]
|
||||
})
|
||||
return JsonResponse(
|
||||
{"available": True, "message": DOMAIN_API_MESSAGES["success"]}
|
||||
)
|
||||
|
|
|
@ -416,6 +416,7 @@ CurrentSitesFormSet = forms.formset_factory(
|
|||
formset=BaseCurrentSitesFormSet,
|
||||
)
|
||||
|
||||
|
||||
class AlternativeDomainForm(RegistrarForm):
|
||||
def clean_alternative_domain(self):
|
||||
"""Validation code for domain names."""
|
||||
|
@ -423,19 +424,23 @@ class AlternativeDomainForm(RegistrarForm):
|
|||
requested = self.cleaned_data.get("alternative_domain", None)
|
||||
validated = Domain.validate(requested, blank_ok=True)
|
||||
except errors.ExtraDotsError:
|
||||
raise forms.ValidationError(code="extra_dots")
|
||||
raise forms.ValidationError(
|
||||
DOMAIN_API_MESSAGES["extra_dots"], code="extra_dots"
|
||||
)
|
||||
except errors.DomainUnavailableError:
|
||||
raise forms.ValidationError(code="unavailable")
|
||||
raise forms.ValidationError(
|
||||
DOMAIN_API_MESSAGES["unavailable"], code="unavailable"
|
||||
)
|
||||
except ValueError:
|
||||
raise forms.ValidationError(code="invalid")
|
||||
raise forms.ValidationError(DOMAIN_API_MESSAGES["invalid"], code="invalid")
|
||||
return validated
|
||||
|
||||
alternative_domain = forms.CharField(
|
||||
required=False,
|
||||
label="Alternative domain",
|
||||
error_messages=DOMAIN_API_MESSAGES
|
||||
)
|
||||
|
||||
|
||||
class BaseAlternativeDomainFormSet(RegistrarFormSet):
|
||||
JOIN = "alternative_domains"
|
||||
|
||||
|
@ -508,19 +513,22 @@ class DotGovDomainForm(RegistrarForm):
|
|||
requested = self.cleaned_data.get("requested_domain", None)
|
||||
validated = Domain.validate(requested)
|
||||
except errors.BlankValueError:
|
||||
raise forms.ValidationError(code="required")
|
||||
raise forms.ValidationError(
|
||||
DOMAIN_API_MESSAGES["required"], code="required"
|
||||
)
|
||||
except errors.ExtraDotsError:
|
||||
raise forms.ValidationError(code="extra_dots")
|
||||
raise forms.ValidationError(
|
||||
DOMAIN_API_MESSAGES["extra_dots"], code="extra_dots"
|
||||
)
|
||||
except errors.DomainUnavailableError:
|
||||
raise forms.ValidationError(code="unavailable")
|
||||
raise forms.ValidationError(
|
||||
DOMAIN_API_MESSAGES["unavailable"], code="unavailable"
|
||||
)
|
||||
except ValueError:
|
||||
raise forms.ValidationError(code="invalid")
|
||||
raise forms.ValidationError(DOMAIN_API_MESSAGES["invalid"], code="invalid")
|
||||
return validated
|
||||
|
||||
requested_domain = forms.CharField(
|
||||
label="What .gov domain do you want?",
|
||||
error_messages=DOMAIN_API_MESSAGES
|
||||
)
|
||||
requested_domain = forms.CharField(label="What .gov domain do you want?")
|
||||
|
||||
|
||||
class PurposeForm(RegistrarForm):
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
|
||||
{% block form_fields %}
|
||||
{% csrf_token %}
|
||||
{% with add_label_class="usa-sr-only" attr_maxlength=500 %}
|
||||
{% input_with_errors forms.0.anything_else %}
|
||||
{% endwith %}
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
|
||||
{% block form_fields %}
|
||||
{% csrf_token %}
|
||||
<fieldset class="usa-fieldset">
|
||||
<legend class="usa-sr-only">
|
||||
Who is the authorizing official for your organization?
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
{% extends 'application_form.html' %}
|
||||
{% load static %}
|
||||
{% load field_helpers %}
|
||||
{% load static field_helpers %}
|
||||
|
||||
{% block form_instructions %}
|
||||
<p>Enter your organization’s public website, if you have one. For example,
|
||||
|
@ -9,7 +8,6 @@
|
|||
|
||||
|
||||
{% block form_fields %}
|
||||
{% csrf_token %}
|
||||
{{ forms.0.management_form }}
|
||||
|
||||
{% for form in forms.0 %}
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
|
||||
{% block form_fields %}
|
||||
{% csrf_token %}
|
||||
<fieldset class="usa-fieldset">
|
||||
<legend class="usa-sr-only">
|
||||
What is the name and mailing address of your organization?
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
|
||||
{% block form_fields %}
|
||||
{% csrf_token %}
|
||||
{% with add_class="usa-radio__input--tile" %}
|
||||
{% input_with_errors forms.0.is_election_board %}
|
||||
{% endwith %}
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
|
||||
{% block form_fields %}
|
||||
{% csrf_token %}
|
||||
{% with add_class="usa-radio__input--tile" %}
|
||||
{% input_with_errors forms.0.federal_type %}
|
||||
{% endwith %}
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
|
||||
{% block form_fields %}
|
||||
{% csrf_token %}
|
||||
{% with add_class="usa-radio__input--tile" %}
|
||||
{% input_with_errors forms.0.organization_type %}
|
||||
{% endwith %}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
{% extends 'application_form.html' %}
|
||||
{% load static %}
|
||||
{% load field_helpers %}
|
||||
{% load static field_helpers %}
|
||||
|
||||
{% block form_instructions %}
|
||||
<p>We’d like to contact other employees with administrative or technical
|
||||
|
@ -12,7 +11,6 @@
|
|||
|
||||
|
||||
{% block form_fields %}
|
||||
{% csrf_token %}
|
||||
{{ forms.0.management_form }}
|
||||
{# forms.0 is a formset and this iterates over its forms #}
|
||||
{% for form in forms.0.forms %}
|
||||
|
@ -21,8 +19,6 @@
|
|||
<h2>Contact {{ forloop.counter }}</h2>
|
||||
</legend>
|
||||
|
||||
{% if form.is_bound %}HAS INITIAL DATA{% else %}NO INITIAL DATA{% endif %}
|
||||
|
||||
{% input_with_errors form.first_name %}
|
||||
|
||||
{% input_with_errors form.middle_name %}
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
|
||||
{% block form_fields %}
|
||||
{% csrf_token %}
|
||||
{% with attr_maxlength=500 %}
|
||||
{% input_with_errors forms.0.purpose %}
|
||||
{% endwith %}
|
||||
|
|
|
@ -183,7 +183,6 @@
|
|||
|
||||
|
||||
{% block form_fields %}
|
||||
{% csrf_token %}
|
||||
<fieldset class="usa-fieldset">
|
||||
<legend>
|
||||
<h2>Acknowledgement of .gov domain requirements</h2>
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
{% load static url_helpers %}
|
||||
|
||||
{% block form_fields %}
|
||||
{% csrf_token %}
|
||||
|
||||
{% for step in steps.all|slice:":-1" %}
|
||||
<section class="review__step margin-top-205">
|
||||
<hr />
|
||||
|
|
|
@ -10,6 +10,5 @@
|
|||
|
||||
|
||||
{% block form_fields %}
|
||||
{% csrf_token %}
|
||||
{% input_with_errors forms.0.security_email %}
|
||||
{% endblock %}
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
|
||||
{% block form_fields %}
|
||||
{% csrf_token %}
|
||||
{% input_with_errors forms.0.tribe_name %}
|
||||
<fieldset class="usa-fieldset">
|
||||
<legend class="usa-legend">
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
|
||||
{% block form_fields %}
|
||||
{% csrf_token %}
|
||||
{% with attr_maxlength=500 %}
|
||||
{% input_with_errors forms.0.type_of_work %}
|
||||
{% input_with_errors forms.0.more_organization_information %}
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
|
||||
{% block form_fields %}
|
||||
{% csrf_token %}
|
||||
<fieldset class="usa-fieldset">
|
||||
<legend class="usa-sr-only">
|
||||
Your contact information
|
||||
|
|
|
@ -7,7 +7,6 @@ Edit your User Profile
|
|||
{% block content %}
|
||||
<main id="main-content" class="grid-container">
|
||||
<form class="usa-form usa-form--large" method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
<fieldset class="usa-fieldset">
|
||||
<legend class="usa-legend usa-legend--large">Your profile</legend>
|
||||
<p>
|
||||
|
|
|
@ -35,6 +35,11 @@ def input_with_errors(context, field=None): # noqa: C901
|
|||
{% endwith %}
|
||||
{% 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["field"] = field
|
||||
|
@ -54,6 +59,12 @@ def input_with_errors(context, field=None): # noqa: C901
|
|||
classes.append(attrs.pop("class"))
|
||||
|
||||
# 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():
|
||||
if key.startswith("attr_"):
|
||||
attr_name = re.sub("_", "-", key[5:])
|
||||
|
|
|
@ -219,7 +219,11 @@ class ApplicationWizard(LoginRequiredMixin, TemplateView):
|
|||
return render(request, self.template_name, context)
|
||||
|
||||
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)
|
||||
flattened = [form for lst in nested for form in lst]
|
||||
return flattened
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue