Remove formtools

Move the ApplicationWizard from under forms/ into
views/ where each page of the application is now its
own view.
This commit is contained in:
Seamus Johnston 2022-12-28 10:19:34 -06:00
parent b45c335257
commit 9886367dd6
No known key found for this signature in database
GPG key ID: 2F21225985069105
38 changed files with 876 additions and 490 deletions

View file

@ -2,5 +2,6 @@
max-line-length = 88
max-complexity = 10
extend-ignore = E203
per-file-ignores = __init__.py:F401,F403
# migrations are auto-generated and often break rules
exclude=registrar/migrations/*

View file

@ -17,7 +17,6 @@ oic = "*"
pyjwkest = "*"
psycopg2-binary = "*"
whitenoise = "*"
django-formtools = "*"
django-widget-tweaks = "*"
cachetools = "*"
requests = "*"

View file

@ -364,11 +364,13 @@ LOGGING = {
"django": {
"handlers": ["console"],
"level": "INFO",
"propagate": False,
},
# Django's template processor
"django.template": {
"handlers": ["console"],
"level": "INFO",
"propagate": False,
},
# Django's runserver
"django.server": {
@ -386,16 +388,19 @@ LOGGING = {
"oic": {
"handlers": ["console"],
"level": "INFO",
"propagate": False,
},
# Django wrapper for OpenID Connect
"djangooidc": {
"handlers": ["console"],
"level": "INFO",
"propagate": False,
},
# Our app!
"registrar": {
"handlers": ["console"],
"level": "DEBUG",
"propagate": False,
},
},
# root logger catches anything, unless

View file

@ -9,30 +9,62 @@ from django.contrib import admin
from django.urls import include, path
from django.views.generic import RedirectView
from registrar.views import health, index, profile, whoami
from registrar.forms import ApplicationWizard, WIZARD_CONDITIONS
from registrar import views
from registrar.views.application import Step
from registrar.views.utility import always_404
from api.views import available
APPLICATION_URL_NAME = "application_step"
application_wizard = ApplicationWizard.as_view(
url_name=APPLICATION_URL_NAME,
done_step_name="finished",
condition_dict=WIZARD_CONDITIONS,
application_urls = (
[
path("", views.ApplicationWizard.as_view(), name=""),
# dynamically generate the other paths
*[
path(f"{step}/", view.as_view(), name=step)
for step, view in [
# add/remove steps here
(Step.ORGANIZATION_TYPE, views.OrganizationType),
(Step.ORGANIZATION_FEDERAL, views.OrganizationFederal),
(Step.ORGANIZATION_ELECTION, views.OrganizationElection),
(Step.ORGANIZATION_CONTACT, views.OrganizationContact),
(Step.AUTHORIZING_OFFICIAL, views.AuthorizingOfficial),
(Step.CURRENT_SITES, views.CurrentSites),
(Step.DOTGOV_DOMAIN, views.DotgovDomain),
(Step.PURPOSE, views.Purpose),
(Step.YOUR_CONTACT, views.YourContact),
(Step.OTHER_CONTACTS, views.OtherContacts),
(Step.SECURITY_EMAIL, views.SecurityEmail),
(Step.ANYTHING_ELSE, views.AnythingElse),
(Step.REQUIREMENTS, views.Requirements),
(Step.REVIEW, views.Review),
]
],
path("finished/", views.Finished.as_view(), name="finished"),
],
views.ApplicationWizard.URL_NAMESPACE,
)
urlpatterns = [
path("", index.index, name="home"),
path("whoami/", whoami.whoami, name="whoami"),
path("", views.index, name="home"),
path("whoami/", views.whoami, name="whoami"),
path("admin/", admin.site.urls),
path("application/<id>/edit/", application_wizard, name="edit-application"),
path("health/", health.health),
path("edit_profile/", profile.edit_profile, name="edit-profile"),
path(
"application/<id>/edit/",
views.ApplicationWizard.as_view(),
name=views.ApplicationWizard.EDIT_URL_NAME,
),
path("health/", views.health),
path("edit_profile/", views.edit_profile, name="edit-profile"),
path("openid/", include("djangooidc.urls")),
path("register/", application_wizard, name="application"),
path("register/<step>/", application_wizard, name=APPLICATION_URL_NAME),
path("register/", include(application_urls)),
path("api/v1/available/<domain>", available, name="available"),
path(
"todo",
lambda r: always_404(r, "We forgot to include this link, sorry."),
name="todo",
),
]
if not settings.DEBUG:
urlpatterns += [
# redirect to login.gov

View file

@ -1,4 +1,2 @@
from .edit_profile import EditProfileForm
from .application_wizard import ApplicationWizard, WIZARD_CONDITIONS
__all__ = ["EditProfileForm", "ApplicationWizard", "WIZARD_CONDITIONS"]
from .edit_profile import *
from .application_wizard import *

View file

@ -1,27 +1,22 @@
"""Forms Wizard for creating a new domain application."""
from __future__ import annotations # allows forward references in annotations
import logging
from typing import Union
from django import forms
from django.shortcuts import render
from django.contrib.auth.mixins import LoginRequiredMixin
from django.urls import resolve
from formtools.wizard.views import NamedUrlSessionWizardView # type: ignore
from formtools.wizard.storage.session import SessionStorage # type: ignore
from registrar.models import Contact, DomainApplication, Domain
logger = logging.getLogger(__name__)
class RegistrarForm(forms.Form):
"""Subclass used to remove the default colon suffix from all fields."""
"""
A common set of methods and configuration.
The registrar's domain application is several pages of "steps".
Each step is an HTML form containing one or more Django "forms".
Subclass this class to create new forms.
"""
def __init__(self, *args, **kwargs):
kwargs.setdefault("label_suffix", "")
@ -39,10 +34,14 @@ class RegistrarForm(forms.Form):
setattr(obj, name, value)
obj.save()
def from_database(self, obj: DomainApplication | Contact):
@classmethod
def from_database(cls, obj: DomainApplication | Contact | None):
"""Initializes this form's fields with values gotten from `obj`."""
for name in self.declared_fields.keys():
self.initial[name] = getattr(obj, name) # type: ignore
if obj is None:
return {}
return {
name: getattr(obj, name) for name in cls.declared_fields.keys()
} # type: ignore
class OrganizationTypeForm(RegistrarForm):
@ -112,11 +111,11 @@ class AuthorizingOfficialForm(RegistrarForm):
obj.authorizing_official = contact
obj.save()
def from_database(self, obj):
@classmethod
def from_database(cls, obj):
"""Initializes this form's fields with values gotten from `obj`."""
contact = getattr(obj, "authorizing_official", None)
if contact is not None:
super().from_database(contact)
return super().from_database(contact)
first_name = forms.CharField(label="First name/given name")
middle_name = forms.CharField(
@ -140,11 +139,14 @@ class CurrentSitesForm(RegistrarForm):
# TODO: ability to update existing records
obj.current_websites.create(website=normalized)
def from_database(self, obj):
@classmethod
def from_database(cls, obj):
"""Initializes this form's fields with values gotten from `obj`."""
current_website = obj.current_websites.first()
if current_website is not None:
self.initial["current_site"] = current_website.website
return {"current_site": current_website.website}
else:
return {}
current_site = forms.CharField(
required=False,
@ -179,15 +181,19 @@ class DotGovDomainForm(RegistrarForm):
# TODO: ability to update existing records
obj.alternative_domains.create(website=normalized)
def from_database(self, obj):
@classmethod
def from_database(cls, obj):
"""Initializes this form's fields with values gotten from `obj`."""
values = {}
requested_domain = getattr(obj, "requested_domain", None)
if requested_domain is not None:
self.initial["requested_domain"] = requested_domain.sld
values["requested_domain"] = requested_domain.sld
alternative_domain = obj.alternative_domains.first()
if alternative_domain is not None:
self.initial["alternative_domain"] = alternative_domain.sld
values["alternative_domain"] = alternative_domain.sld
return values
requested_domain = forms.CharField(label="What .gov domain do you want?")
alternative_domain = forms.CharField(
@ -215,11 +221,11 @@ class YourContactForm(RegistrarForm):
obj.submitter = contact
obj.save()
def from_database(self, obj):
@classmethod
def from_database(cls, obj):
"""Initializes this form's fields with values gotten from `obj`."""
contact = getattr(obj, "submitter", None)
if contact is not None:
super().from_database(contact)
return super().from_database(contact)
first_name = forms.CharField(label="First name/given name")
middle_name = forms.CharField(
@ -248,11 +254,11 @@ class OtherContactsForm(RegistrarForm):
super().to_database(contact)
obj.other_contacts.add(contact)
def from_database(self, obj):
@classmethod
def from_database(cls, obj):
"""Initializes this form's fields with values gotten from `obj`."""
other_contacts = obj.other_contacts.first()
if other_contacts is not None:
super().from_database(other_contacts)
return super().from_database(other_contacts)
first_name = forms.CharField(label="First name/given name")
middle_name = forms.CharField(
@ -287,255 +293,3 @@ class RequirementsForm(RegistrarForm):
"and operating .gov domains."
)
)
class ReviewForm(RegistrarForm):
"""
Empty class for the review page.
It gets included as part of the form, but does not have any form fields itself.
"""
def to_database(self, _):
"""This form has no data. Do nothing."""
pass
pass
class Step:
"""Names for each page of the application wizard."""
ORGANIZATION_TYPE = "organization_type"
ORGANIZATION_FEDERAL = "organization_federal"
ORGANIZATION_ELECTION = "organization_election"
ORGANIZATION_CONTACT = "organization_contact"
AUTHORIZING_OFFICIAL = "authorizing_official"
CURRENT_SITES = "current_sites"
DOTGOV_DOMAIN = "dotgov_domain"
PURPOSE = "purpose"
YOUR_CONTACT = "your_contact"
OTHER_CONTACTS = "other_contacts"
SECURITY_EMAIL = "security_email"
ANYTHING_ELSE = "anything_else"
REQUIREMENTS = "requirements"
REVIEW = "review"
# List of forms in our wizard.
# Each entry is a tuple of a name and a form subclass
FORMS = [
(Step.ORGANIZATION_TYPE, OrganizationTypeForm),
(Step.ORGANIZATION_FEDERAL, OrganizationFederalForm),
(Step.ORGANIZATION_ELECTION, OrganizationElectionForm),
(Step.ORGANIZATION_CONTACT, OrganizationContactForm),
(Step.AUTHORIZING_OFFICIAL, AuthorizingOfficialForm),
(Step.CURRENT_SITES, CurrentSitesForm),
(Step.DOTGOV_DOMAIN, DotGovDomainForm),
(Step.PURPOSE, PurposeForm),
(Step.YOUR_CONTACT, YourContactForm),
(Step.OTHER_CONTACTS, OtherContactsForm),
(Step.SECURITY_EMAIL, SecurityEmailForm),
(Step.ANYTHING_ELSE, AnythingElseForm),
(Step.REQUIREMENTS, RequirementsForm),
(Step.REVIEW, ReviewForm),
]
# Dict to match up the right template with the right step.
TEMPLATES = {
Step.ORGANIZATION_TYPE: "application_org_type.html",
Step.ORGANIZATION_FEDERAL: "application_org_federal.html",
Step.ORGANIZATION_ELECTION: "application_org_election.html",
Step.ORGANIZATION_CONTACT: "application_org_contact.html",
Step.AUTHORIZING_OFFICIAL: "application_authorizing_official.html",
Step.CURRENT_SITES: "application_current_sites.html",
Step.DOTGOV_DOMAIN: "application_dotgov_domain.html",
Step.PURPOSE: "application_purpose.html",
Step.YOUR_CONTACT: "application_your_contact.html",
Step.OTHER_CONTACTS: "application_other_contacts.html",
Step.SECURITY_EMAIL: "application_security_email.html",
Step.ANYTHING_ELSE: "application_anything_else.html",
Step.REQUIREMENTS: "application_requirements.html",
Step.REVIEW: "application_review.html",
}
# We need to pass our page titles as context to the templates
TITLES = {
Step.ORGANIZATION_TYPE: "Type of organization",
Step.ORGANIZATION_FEDERAL: "Type of organization — Federal",
Step.ORGANIZATION_ELECTION: "Type of organization — Election board",
Step.ORGANIZATION_CONTACT: "Organization name and mailing address",
Step.AUTHORIZING_OFFICIAL: "Authorizing official",
Step.CURRENT_SITES: "Organization website",
Step.DOTGOV_DOMAIN: ".gov domain",
Step.PURPOSE: "Purpose of your domain",
Step.YOUR_CONTACT: "Your contact information",
Step.OTHER_CONTACTS: "Other contacts for your domain",
Step.SECURITY_EMAIL: "Security email for public use",
Step.ANYTHING_ELSE: "Anything else we should know?",
Step.REQUIREMENTS: "Requirements for registration and operation of .gov domains",
Step.REVIEW: "Review and submit your domain request",
}
# We can use a dictionary with step names and callables that return booleans
# to show or hide particular steps based on the state of the process.
WIZARD_CONDITIONS = {
"organization_federal": DomainApplication.show_organization_federal,
"organization_election": DomainApplication.show_organization_election,
}
class TrackingStorage(SessionStorage):
"""Storage subclass that keeps track of what the current_step has been."""
def _set_current_step(self, step):
super()._set_current_step(step)
step_history = self.extra_data.setdefault("step_history", [])
# can't serialize a set, so keep list entries unique
if step not in step_history:
step_history.append(step)
class ApplicationWizard(LoginRequiredMixin, NamedUrlSessionWizardView):
"""Multi-page form ("wizard") for new domain applications.
This sets up a sequence of forms that gather information for new
domain applications. Each form in the sequence has its own URL and
the progress through the form is stored in the Django session (thus
"NamedUrlSessionWizardView").
Caution: due to the redirect performed by using NamedUrlSessionWizardView,
many methods, such as `process_step`, are called TWICE per request. For
this reason, methods in this class need to be idempotent.
"""
form_list = FORMS
storage_name = "registrar.forms.application_wizard.TrackingStorage"
def get_template_names(self):
"""Template for the current step.
The return is a singleton list.
"""
return [TEMPLATES[self.steps.current]]
def _is_federal(self) -> Union[bool, None]:
"""Return whether this application is from a federal agency.
Returns True if we know that this application is from a federal
agency, False if we know that it is not and None if there isn't an
answer yet for that question.
"""
return self.get_application_object().is_federal()
def get_context_data(self, form, **kwargs):
"""Add title information to the context for all steps."""
context = super().get_context_data(form=form, **kwargs)
context["form_titles"] = TITLES
# Add information about which steps should be unlocked
# TODO: sometimes the first step doesn't get added to the step history
# so add it here
context["visited"] = self.storage.extra_data.get("step_history", []) + [
self.steps.first
]
if self.steps.current == Step.ORGANIZATION_CONTACT:
context["is_federal"] = self._is_federal()
if self.steps.current == Step.REVIEW:
context["step_cls"] = Step
application = self.get_application_object()
context["application"] = application
return context
def get_application_object(self) -> DomainApplication:
"""
Attempt to match the current wizard with a DomainApplication.
Will create an application if none exists.
"""
if "application_id" in self.storage.extra_data:
id = self.storage.extra_data["application_id"]
try:
return DomainApplication.objects.get(
creator=self.request.user,
pk=id,
)
except DomainApplication.DoesNotExist:
logger.debug("Application id %s did not have a DomainApplication" % id)
application = DomainApplication.objects.create(creator=self.request.user)
self.storage.extra_data["application_id"] = application.id
return application
def form_to_database(self, form: RegistrarForm) -> DomainApplication:
"""
Unpack the form responses onto the model object properties.
Saves the application to the database.
"""
application = self.get_application_object()
if form is not None and hasattr(form, "to_database"):
form.to_database(application)
return application
def process_step(self, form):
"""
Hook called on every POST request, if the form is valid.
Do not manipulate the form data here.
"""
# save progress
self.form_to_database(form=form)
return self.get_form_step_data(form)
def get_form(self, step=None, data=None, files=None):
"""This method constructs the form for a given step."""
form = super().get_form(step, data, files)
# restore from database, but only if a record has already
# been associated with this wizard instance
if "application_id" in self.storage.extra_data:
application = self.get_application_object()
form.from_database(application)
return form
def post(self, *args, **kwargs):
"""This method handles POST requests."""
step = self.steps.current
# always call super() first, to do important pre-processing
rendered = super().post(*args, **kwargs)
# if user opted to save their progress,
# return them to the page they were already on
button = self.request.POST.get("submit_button", None)
if button == "save":
return self.render_goto_step(step)
# otherwise, proceed as normal
return rendered
def get(self, *args, **kwargs):
"""This method handles GET requests."""
current_url = resolve(self.request.path_info).url_name
# always call super(), it handles important redirect logic
rendered = super().get(*args, **kwargs)
# if user visited via an "edit" url, associate the id of the
# application they are trying to edit to this wizard instance
if current_url == "edit-application" and "id" in kwargs:
self.storage.extra_data["application_id"] = kwargs["id"]
return rendered
def done(self, form_list, form_dict, **kwargs):
"""Called when the data for every form is submitted and validated."""
application = self.get_application_object()
application.submit() # change the status to submitted
application.save()
logger.debug("Application object saved: %s", application.id)
return render(
self.request, "application_done.html", {"application_id": application.id}
)

View file

@ -1,5 +1,5 @@
from __future__ import annotations
from typing import TYPE_CHECKING, Union
from typing import Union
from django.apps import apps
from django.db import models
@ -7,9 +7,6 @@ from django_fsm import FSMField, transition # type: ignore
from .utility.time_stamped_model import TimeStampedModel
if TYPE_CHECKING:
from ..forms.application_wizard import ApplicationWizard
class DomainApplication(TimeStampedModel):
@ -460,30 +457,17 @@ class DomainApplication(TimeStampedModel):
# during the application flow. They are policies about the application so
# they appear here.
@staticmethod
def _get_organization_type(wizard: ApplicationWizard) -> Union[str, None]:
"""Extract the answer to the organization type question from the wizard."""
# using the step data from the storage is a workaround for this
# bug in django-formtools version 2.4
# https://github.com/jazzband/django-formtools/issues/220
type_data = wizard.storage.get_step_data("organization_type")
if type_data:
return type_data.get("organization_type-organization_type")
return None
@staticmethod
def show_organization_federal(wizard: ApplicationWizard) -> bool:
def show_organization_federal(self) -> bool:
"""Show this step if the answer to the first question was "federal"."""
user_choice = DomainApplication._get_organization_type(wizard)
user_choice = self.organization_type
return user_choice == DomainApplication.OrganizationChoices.FEDERAL
@staticmethod
def show_organization_election(wizard: ApplicationWizard) -> bool:
def show_organization_election(self) -> bool:
"""Show this step if the answer to the first question implies it.
This shows for answers that aren't "Federal" or "Interstate".
"""
user_choice = DomainApplication._get_organization_type(wizard)
user_choice = self.organization_type
excluded = [
DomainApplication.OrganizationChoices.FEDERAL,
DomainApplication.OrganizationChoices.INTERSTATE,

View file

@ -6,14 +6,13 @@
<p id="instructions">Is there anything else we should know about your domain request?</p>
<form id="step__{{wizard.steps.current}}" class="usa-form usa-form--large" method="post">
<form id="step__{{steps.current}}" class="usa-form usa-form--large" method="post">
<div class="usa-form-group">
{{ wizard.management_form }}
{% csrf_token %}
<div class="usa-character-count">
{{ wizard.form.anything_else|add_label_class:"usa-label usa-sr-only" }}
{{ wizard.form.anything_else|add_class:"usa-textarea usa-character-count__field"|attr:"aria-describedby:instructions"|attr:"maxlength=500" }}
{{ forms.0.anything_else|add_label_class:"usa-label usa-sr-only" }}
{{ forms.0.anything_else|add_class:"usa-textarea usa-character-count__field"|attr:"aria-describedby:instructions"|attr:"maxlength=500" }}
<span class="usa-character-count__message" id="with-hint-textarea-info with-hint-textarea-hint"> You can enter up to 500 characters </span>
</div>
</div>

View file

@ -8,7 +8,7 @@
<h2>Who is the authorizing official for your organization?</h2>
<div id="instructions">
<p>Your authorizing official is the person within your organization who can authorize your domain request. This is generally the highest ranking or highest elected official in your organization. Read more about <a href="#">who can serve as an authorizing official</a>.
<p>Your authorizing official is the person within your organization who can authorize your domain request. This is generally the highest ranking or highest elected official in your organization. Read more about <a href="{% url 'todo' %}">who can serve as an authorizing official</a>.
</p>
<div class="ao-example">
@ -20,31 +20,30 @@
<p>All fields are required unless they are marked optional.</p>
<form class="usa-form usa-form--large" id="step__{{wizard.steps.current}}" method="post">
{{ wizard.management_form }}
<form class="usa-form usa-form--large" id="step__{{steps.current}}" method="post">
{% csrf_token %}
<fieldset class="usa-fieldset">
<legend class="usa-sr-only">
Who is the authorizing official for your organization?
</legend>
{{ wizard.form.first_name|add_label_class:"usa-label" }}
{{ wizard.form.first_name|add_class:"usa-input"}}
{{ forms.0.first_name|add_label_class:"usa-label" }}
{{ forms.0.first_name|add_class:"usa-input"}}
{{ wizard.form.middle_name|add_label_class:"usa-label" }}
{{ wizard.form.middle_name|add_class:"usa-input"}}
{{ forms.0.middle_name|add_label_class:"usa-label" }}
{{ forms.0.middle_name|add_class:"usa-input"}}
{{ wizard.form.last_name|add_label_class:"usa-label" }}
{{ wizard.form.last_name|add_class:"usa-input"}}
{{ forms.0.last_name|add_label_class:"usa-label" }}
{{ forms.0.last_name|add_class:"usa-input"}}
{{ wizard.form.title|add_label_class:"usa-label" }}
{{ wizard.form.title|add_class:"usa-input"}}
{{ forms.0.title|add_label_class:"usa-label" }}
{{ forms.0.title|add_class:"usa-input"}}
{{ wizard.form.email|add_label_class:"usa-label" }}
{{ wizard.form.email|add_class:"usa-input"}}
{{ forms.0.email|add_label_class:"usa-label" }}
{{ forms.0.email|add_class:"usa-input"}}
{{ wizard.form.phone|add_label_class:"usa-label" }}
{{ wizard.form.phone|add_class:"usa-input usa-input--medium" }}
{{ forms.0.phone|add_label_class:"usa-label" }}
{{ forms.0.phone|add_class:"usa-input usa-input--medium" }}
</fieldset>

View file

@ -5,12 +5,11 @@
{% block form_content %}
<form class="usa-form usa-form--large" id="step__{{wizard.steps.current}}" method="post">
{{ wizard.management_form }}
<form class="usa-form usa-form--large" id="step__{{steps.current}}" method="post">
{% csrf_token %}
{{ wizard.form.current_site|add_label_class:"usa-label" }}
{{ wizard.form.current_site|add_class:"usa-input" }}
{{ forms.0.current_site|add_label_class:"usa-label" }}
{{ forms.0.current_site|add_class:"usa-input" }}
{{ block.super }}

View file

@ -19,7 +19,7 @@ your authorizing official, and any contacts you added.</p>
meets our naming requirements.
</li>
<li> You can <a href="/application/{{ application_id }}"><del>check the
<li> You can <a href="{% url 'todo' %}"><del>check the
status</del></a> of your request at any time.
</li>
@ -32,9 +32,9 @@ your authorizing official, and any contacts you added.</p>
<p>Before your domain can be used we'll need information about your
domain name servers. If you have this information you can enter it now.
If you don't have it, that's okay. You can enter it later on the
<a href="/domains"><del>manage your domains page</del></a>.
<a href="{% url 'todo' %}"><del>manage your domains page</del></a>.
</p>
<p><a href="/application/{{ application_id }}#nameservers" class="usa-button">Enter DNS name servers</a></p>
<p><a href="{% url 'todo' %}" class="usa-button">Enter DNS name servers</a></p>
{% endblock %}

View file

@ -3,7 +3,7 @@
{% load widget_tweaks static%}
{% block form_content %}
<p> Before requesting a .gov domain, <a href="#">please make sure it meets our naming requirements.</a> Your domain name must:
<p> Before requesting a .gov domain, <a href="{% url 'todo' %}">please make sure it meets our naming requirements.</a> Your domain name must:
<ul class="usa-list">
<li>Be available </li>
<li>Be unique </li>
@ -21,16 +21,15 @@
{% include "includes/domain_example__city.html" %}
</div>
<form id="step__{{wizard.steps.current}}" class="usa-form usa-form--large" method="post">
<form id="step__{{steps.current}}" class="usa-form usa-form--large" method="post">
<h2> What .gov domain do you want? </h2>
<p class="domain_instructions"> After you enter your domain, well make sure its available and that it meets some of our naming requirements. If your domain passes these initial checks, well verify that it meets all of our requirements once you complete and submit the rest of this form. </p>
{{ wizard.management_form }}
{% csrf_token %}
{{ wizard.form.requested_domain|add_label_class:"usa-label" }}
{{ forms.0.requested_domain|add_label_class:"usa-label" }}
<div class="display-flex flex-align-center">
<span class="padding-top-05 padding-right-2px">www.</span>
{{ wizard.form.requested_domain|add_class:"usa-input"|attr:"aria-describedby:domain_instructions" }}
{{ forms.0.requested_domain|add_class:"usa-input"|attr:"aria-describedby:domain_instructions" }}
<span class="padding-top-05 padding-left-2px">.gov </span>
</div>
<button type="button" class="usa-button">Check availability </button>
@ -38,10 +37,10 @@
<h2>Alternative domains</h2>
<div>
{{ wizard.form.alternative_domain|add_label_class:"usa-label" }}
{{ forms.0.alternative_domain|add_label_class:"usa-label" }}
<div class="display-flex flex-align-center">
<span class="padding-top-05 padding-right-2px">www.</span>
{{ wizard.form.alternative_domain|add_class:"usa-input" }}
{{ forms.0.alternative_domain|add_class:"usa-input" }}
<span class="padding-top-05 padding-left-2px">.gov </span>
</div>

View file

@ -1,7 +1,7 @@
{% extends 'base.html' %}
{% load static widget_tweaks %}
{% load static widget_tweaks namespaced_urls %}
{% block title %}Apply for a .gov domain {{form_titles|get_item:wizard.steps.current}}{% endblock %}
{% block title %}Apply for a .gov domain {{form_titles|get_item:steps.current}}{% endblock %}
{% block content %}
<div class="grid-container">
<div class="grid-row grid-gap">
@ -10,17 +10,17 @@
</div>
<div class="grid-col-9">
<main id="main-content" class="grid-container register-form-step">
{% if wizard.steps.prev %}
<a href="{% url wizard.url_name step=wizard.steps.prev %}" class="breadcrumb__back">
{% if steps.prev %}
<a href="{% namespaced_url 'application' steps.prev %}" class="breadcrumb__back">
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img">
<use xlink:href="{%static 'img/sprite.svg'%}#arrow_back"></use>
</svg><span class="margin-left-05">Previous step </span>
</a>
{% endif %}
<h1> {{form_titles|get_item:wizard.steps.current}} </h1>
<h1> {{form_titles|get_item:steps.current}} </h1>
{% block form_content %}
<div class="stepnav">
{% if wizard.steps.next %}
{% if steps.next %}
<button
type="submit"
name="submit_button"

View file

@ -16,32 +16,31 @@
<p>All fields are required unless they are marked optional.</p>
</div>
<form id="step__{{wizard.steps.current}}" class="usa-form usa-form--large" method="post">
{{ wizard.management_form }}
<form id="step__{{steps.current}}" class="usa-form usa-form--large" method="post">
{% csrf_token %}
<fieldset class="usa-fieldset">
<legend class="usa-sr-only">What is the name and mailing address of your organization?</legend>
{% if is_federal %}
{{ wizard.form.federal_agency|add_label_class:"usa-label" }}
{{ wizard.form.federal_agency|add_class:"usa-select" }}
{{ forms.0.federal_agency|add_label_class:"usa-label" }}
{{ forms.0.federal_agency|add_class:"usa-select" }}
{% endif %}
{{ wizard.form.organization_name|add_label_class:"usa-label" }}
{{ wizard.form.organization_name|add_class:"usa-input" }}
{{ wizard.form.address_line1|add_label_class:"usa-label" }}
{{ wizard.form.address_line1|add_class:"usa-input" }}
{{ wizard.form.address_line2|add_label_class:"usa-label" }}
{{ wizard.form.address_line2|add_class:"usa-input" }}
{{ wizard.form.city|add_label_class:"usa-label" }}
{{ wizard.form.city|add_class:"usa-input" }}
{{ wizard.form.state_territory|add_label_class:"usa-label" }}
{{ wizard.form.state_territory|add_class:"usa-select" }}
{{ wizard.form.zipcode|add_label_class:"usa-label" }}
{{ wizard.form.zipcode|add_class:"usa-input usa-input--small" }}
{{ wizard.form.urbanization|add_label_class:"usa-label" }}
{{ wizard.form.urbanization|add_class:"usa-input usa-input--small" }}
{{ forms.0.organization_name|add_label_class:"usa-label" }}
{{ forms.0.organization_name|add_class:"usa-input" }}
{{ forms.0.address_line1|add_label_class:"usa-label" }}
{{ forms.0.address_line1|add_class:"usa-input" }}
{{ forms.0.address_line2|add_label_class:"usa-label" }}
{{ forms.0.address_line2|add_class:"usa-input" }}
{{ forms.0.city|add_label_class:"usa-label" }}
{{ forms.0.city|add_class:"usa-input" }}
{{ forms.0.state_territory|add_label_class:"usa-label" }}
{{ forms.0.state_territory|add_class:"usa-select" }}
{{ forms.0.zipcode|add_label_class:"usa-label" }}
{{ forms.0.zipcode|add_class:"usa-input usa-input--small" }}
{{ forms.0.urbanization|add_label_class:"usa-label" }}
{{ forms.0.urbanization|add_class:"usa-input usa-input--small" }}
</fieldset>

View file

@ -5,14 +5,13 @@
{% block form_content %}
<form id="step__{{wizard.steps.current}}" class="usa-form usa-form--large" method="post">
{{ wizard.management_form }}
<form id="step__{{steps.current}}" class="usa-form usa-form--large" method="post">
{% csrf_token %}
<fieldset id="election_board__fieldset" class="usa-fieldset">
<legend>
<h2 class="margin-bottom-05">Is your organization an election office?</h2>
</legend>
{% radio_buttons_by_value wizard.form.is_election_board as choices %}
{% radio_buttons_by_value forms.0.is_election_board as choices %}
{% for choice in choices.values %}
{% include "includes/radio_button.html" with choice=choice tile="true" %}
{% endfor %}

View file

@ -5,14 +5,13 @@
{% block form_content %}
<form id="step__{{wizard.steps.current}}" class="usa-form usa-form--large" method="post">
{{ wizard.management_form }}
<form id="step__{{steps.current}}" class="usa-form usa-form--large" method="post">
{% csrf_token %}
<fieldset id="federal_type__fieldset" class="usa-fieldset">
<legend>
<h2 class="margin-bottom-5">Which federal branch is your organization in?</h2>
</legend>
{% radio_buttons_by_value wizard.form.federal_type as choices %}
{% radio_buttons_by_value forms.0.federal_type as choices %}
{% for choice in choices.values %}
{% include "includes/radio_button.html" with choice=choice tile="true" %}
{% endfor %}

View file

@ -5,17 +5,16 @@
{% block form_content %}
<form id="step__{{wizard.steps.current}}" class="usa-form usa-form--large" method="post">
{{ wizard.management_form }}
<form id="step__{{steps.current}}" class="usa-form usa-form--large" method="post">
{% csrf_token %}
{% radio_buttons_by_value wizard.form.organization_type as choices %}
{% radio_buttons_by_value forms.0.organization_type as choices %}
<fieldset id="organization_type__fieldset" class="usa-fieldset">
<legend class="usa-legend">
<h2> What kind of U.S.-based government organization do you represent?</h2>
</legend>
{{ wizard.form.organization_type.errors }}
{{ forms.0.organization_type.errors }}
{% for choice in choices.values %}
{% include "includes/radio_button.html" with choice=choice tile="true" %}
{% endfor %}

View file

@ -8,31 +8,30 @@
<p id="instructions">Wed like to contact other employees with administrative or technical responsibilities in your organization. For example, they could be involved in managing your organization or its technical infrastructure. This information will help us assess your eligibility and understand the purpose of the .gov domain. These contacts should be in addition to you and your authorizing official. </p>
<p>All fields are required unless they are marked optional.</p>
<form class="usa-form usa-form--large" id="step__{{wizard.steps.current}}" method="post">
{{ wizard.management_form }}
<form class="usa-form usa-form--large" id="step__{{steps.current}}" method="post">
{% csrf_token %}
<fieldset class="usa-fieldset">
<legend>
<h2 class="margin-bottom-05"> Contact 2 </h2>
</legend>
{{ wizard.form.first_name|add_label_class:"usa-label" }}
{{ wizard.form.first_name|add_class:"usa-input"|attr:"aria-describedby:instructions" }}
{{ forms.0.first_name|add_label_class:"usa-label" }}
{{ forms.0.first_name|add_class:"usa-input"|attr:"aria-describedby:instructions" }}
{{ wizard.form.middle_name|add_label_class:"usa-label" }}
{{ wizard.form.middle_name|add_class:"usa-input"|attr:"aria-describedby:instructions" }}
{{ forms.0.middle_name|add_label_class:"usa-label" }}
{{ forms.0.middle_name|add_class:"usa-input"|attr:"aria-describedby:instructions" }}
{{ wizard.form.last_name|add_label_class:"usa-label" }}
{{ wizard.form.last_name|add_class:"usa-input"|attr:"aria-describedby:instructions" }}
{{ forms.0.last_name|add_label_class:"usa-label" }}
{{ forms.0.last_name|add_class:"usa-input"|attr:"aria-describedby:instructions" }}
{{ wizard.form.title|add_label_class:"usa-label" }}
{{ wizard.form.title|add_class:"usa-input"|attr:"aria-describedby:instructions" }}
{{ forms.0.title|add_label_class:"usa-label" }}
{{ forms.0.title|add_class:"usa-input"|attr:"aria-describedby:instructions" }}
{{ wizard.form.email|add_label_class:"usa-label" }}
{{ wizard.form.email|add_class:"usa-input"|attr:"aria-describedby:instructions" }}
{{ forms.0.email|add_label_class:"usa-label" }}
{{ forms.0.email|add_class:"usa-input"|attr:"aria-describedby:instructions" }}
{{ wizard.form.phone|add_label_class:"usa-label" }}
{{ wizard.form.phone|add_class:"usa-input usa-input--medium"|attr:"aria-describedby:instructions" }}
{{ forms.0.phone|add_label_class:"usa-label" }}
{{ forms.0.phone|add_class:"usa-input usa-input--medium"|attr:"aria-describedby:instructions" }}
</fieldset>
<div>

View file

@ -6,16 +6,15 @@
<p id="instructions">.Gov domain names are intended for use on the internet. They should be registered with an intent to deploy services, not simply to reserve a name. .Gov domains should not be registered for primarily internal use.</p>
<p id="instructions">Describe the reason for your domain request. Explain how you plan to use this domain. Will you use it for a website and/or email? Are you moving your website from another top-level domain (like .com or .org)? Read about <a href="#">activities that are prohibited on .gov domains.</a></p>
<p id="instructions">Describe the reason for your domain request. Explain how you plan to use this domain. Will you use it for a website and/or email? Are you moving your website from another top-level domain (like .com or .org)? Read about <a href="{% url 'todo' %}">activities that are prohibited on .gov domains.</a></p>
<form id="step__{{wizard.steps.current}}" class="usa-form usa-form--large" method="post">
<form id="step__{{steps.current}}" class="usa-form usa-form--large" method="post">
<div class="usa-form-group">
{{ wizard.management_form }}
{% csrf_token %}
<div class="usa-character-count">
{{ wizard.form.purpose|add_label_class:"usa-label usa-sr-only" }}
{{ wizard.form.purpose|add_class:"usa-textarea usa-character-count__field"|attr:"aria-describedby:instructions"|attr:"maxlength=500" }}
{{ forms.0.purpose|add_label_class:"usa-label usa-sr-only" }}
{{ forms.0.purpose|add_class:"usa-textarea usa-character-count__field"|attr:"aria-describedby:instructions"|attr:"maxlength=500" }}
<span class="usa-character-count__message" id="with-hint-textarea-info with-hint-textarea-hint"> You can enter up to 500 characters </span>
</div>
</div>

View file

@ -127,14 +127,13 @@
<h2>Acknowledgement of .gov domain requirements</h2>
<form id="step__{{wizard.steps.current}}" class="usa-form usa-form--large" method="post">
<form id="step__{{steps.current}}" class="usa-form usa-form--large" method="post">
<div class="usa-form-group">
{{ wizard.management_form }}
{% csrf_token %}
<div class="usa-checkbox">
{{ wizard.form.is_policy_acknowledged|add_class:"usa-checkbox__input"}}
{{ wizard.form.is_policy_acknowledged|add_label_class:"usa-checkbox__label" }}
{{ forms.0.is_policy_acknowledged|add_class:"usa-checkbox__input"}}
{{ forms.0.is_policy_acknowledged|add_label_class:"usa-checkbox__label" }}
</div>
</div>

View file

@ -1,44 +1,43 @@
<!-- Test page -->
{% extends 'application_form.html' %}
{% load static widget_tweaks %}
{% load static widget_tweaks namespaced_urls %}
{% block form_content %}
<form id="step__{{wizard.steps.current}}" class="usa-form usa-form--large" method="post">
{{ wizard.management_form }}
<form id="step__{{steps.current}}" class="usa-form usa-form--large" method="post">
{% csrf_token %}
{% for step in wizard.steps.all|slice:":-1" %}
{% for step in steps.all|slice:":-1" %}
<section class="review__step margin-top-205">
<hr />
<div class="review__step__title display-flex flex-justify">
<div class="review__step__value">
<div class="review__step__name">{{ form_titles|get_item:step }}</div>
<div>
{% if step == step_cls.ORGANIZATION_TYPE %}
{% if step == Step.ORGANIZATION_TYPE %}
{{ application.get_organization_type_display|default:"Incomplete" }}
{% endif %}
{% if step == step_cls.ORGANIZATION_FEDERAL %}
{% if step == Step.ORGANIZATION_FEDERAL %}
{{ application.get_federal_type_display|default:"Incomplete" }}
{% endif %}
{% if step == step_cls.ORGANIZATION_ELECTION %}
{% if step == Step.ORGANIZATION_ELECTION %}
{{ application.is_election_board|yesno:"Yes,No,Incomplete" }}
{% endif %}
{% if step == step_cls.ORGANIZATION_CONTACT %}
{% if step == Step.ORGANIZATION_CONTACT %}
{% if application.organization_name %}
{% include "includes/organization_address.html" with organization=application %}
{% else %}
Incomplete
{% endif %}
{% endif %}
{% if step == step_cls.AUTHORIZING_OFFICIAL %}
{% if step == Step.AUTHORIZING_OFFICIAL %}
{% if application.authorizing_official %}
{% include "includes/contact.html" with contact=application.authorizing_official %}
{% else %}
Incomplete
{% endif %}
{% endif %}
{% if step == step_cls.CURRENT_SITES %}
{% if step == Step.CURRENT_SITES %}
<ul class="add-list-reset">
{% for site in application.current_websites.all %}
<li>{{ site.website }}</li>
@ -47,7 +46,7 @@
{% endfor %}
</ul>
{% endif %}
{% if step == step_cls.DOTGOV_DOMAIN %}
{% if step == Step.DOTGOV_DOMAIN %}
<ul class="add-list-reset">
<li>{{ application.requested_domain.name|default:"Incomplete" }}</li>
{% for site in application.alternative_domains.all %}
@ -55,37 +54,37 @@
{% endfor %}
</ul>
{% endif %}
{% if step == step_cls.PURPOSE %}
{% if step == Step.PURPOSE %}
{{ application.purpose|default:"Incomplete" }}
{% endif %}
{% if step == step_cls.YOUR_CONTACT %}
{% if step == Step.YOUR_CONTACT %}
{% if application.submitter %}
{% include "includes/contact.html" with contact=application.submitter %}
{% else %}
Incomplete
{% endif %}
{% endif %}
{% if step == step_cls.OTHER_CONTACTS %}
{% if step == Step.OTHER_CONTACTS %}
{% for other in application.other_contacts.all %}
{% include "includes/contact.html" with contact=other %}
{% empty %}
None
{% endfor %}
{% endif %}
{% if step == step_cls.SECURITY_EMAIL %}
{% if step == Step.SECURITY_EMAIL %}
{{ application.security_email|default:"None" }}
{% endif %}
{% if step == step_cls.ANYTHING_ELSE %}
{% if step == Step.ANYTHING_ELSE %}
{{ application.anything_else|default:"No" }}
{% endif %}
{% if step == step_cls.REQUIREMENTS %}
{% if step == Step.REQUIREMENTS %}
{{ application.is_policy_acknowledged|yesno:"Agree,Do not agree,Do not agree" }}
{% endif %}
</div>
</div>
<a
aria-describedby="review_step_title__{{step}}"
href="{% url wizard.url_name step=step %}"
href="{% namespaced_url 'application' step %}"
>Edit<span class="sr-only"> {{ form_titles|get_item:step }}</span></a>
</div>
</section>

View file

@ -7,12 +7,11 @@
<p id="instructions"> We strongly recommend that you provide a security email. This email will allow the public to report observed or suspected security issues on your domain. <strong> Security emails are made public.</strong> We recommend using an alias, like security@&lt;domain.gov&gt;.</p>
<form class="usa-form usa-form--large" id="step__{{wizard.steps.current}}" method="post">
{{ wizard.management_form }}
<form class="usa-form usa-form--large" id="step__{{steps.current}}" method="post">
{% csrf_token %}
{{ wizard.form.security_email|add_label_class:"usa-label" }}
{{ wizard.form.security_email|add_class:"usa-input"|attr:"aria-describedby:instructions" }}
{{ forms.0.security_email|add_label_class:"usa-label" }}
{{ forms.0.security_email|add_class:"usa-input"|attr:"aria-describedby:instructions" }}
{{ block.super }}

View file

@ -1,12 +1,13 @@
{% load static %}
{% load static namespaced_urls %}
<div class="margin-bottom-4 tablet:margin-bottom-0">
<nav aria-label="Form steps,">
<ul class="usa-sidenav">
{% for this_step in wizard.steps.all %}
{% for this_step in steps.all %}
{% if this_step in visited %}
<li class="usa-sidenav__item">
<a href="{% url wizard.url_name step=this_step %}"
{% if this_step == wizard.steps.current %}class="usa-current"{% endif%}>
<a href="{% namespaced_url 'application' this_step %}"
{% if this_step == steps.current %}class="usa-current"{% endif%}>
{{ form_titles|get_item:this_step }}
</a>
{% else %}

View file

@ -15,31 +15,30 @@
<p>All fields are required unless they are marked optional.</p>
<form class="usa-form usa-form--large" id="step__{{wizard.steps.current}}" method="post">
{{ wizard.management_form }}
<form class="usa-form usa-form--large" id="step__{{steps.current}}" method="post">
{% csrf_token %}
<fieldset class="usa-fieldset">
<legend class="usa-sr-only">
Your contact information
</legend>
{{ wizard.form.first_name|add_label_class:"usa-label" }}
{{ wizard.form.first_name|add_class:"usa-input"|attr:"aria-describedby:instructions" }}
{{ forms.0.first_name|add_label_class:"usa-label" }}
{{ forms.0.first_name|add_class:"usa-input"|attr:"aria-describedby:instructions" }}
{{ wizard.form.middle_name|add_label_class:"usa-label" }}
{{ wizard.form.middle_name|add_class:"usa-input"|attr:"aria-describedby:instructions" }}
{{ forms.0.middle_name|add_label_class:"usa-label" }}
{{ forms.0.middle_name|add_class:"usa-input"|attr:"aria-describedby:instructions" }}
{{ wizard.form.last_name|add_label_class:"usa-label" }}
{{ wizard.form.last_name|add_class:"usa-input"|attr:"aria-describedby:instructions" }}
{{ forms.0.last_name|add_label_class:"usa-label" }}
{{ forms.0.last_name|add_class:"usa-input"|attr:"aria-describedby:instructions" }}
{{ wizard.form.title|add_label_class:"usa-label" }}
{{ wizard.form.title|add_class:"usa-input"|attr:"aria-describedby:instructions" }}
{{ forms.0.title|add_label_class:"usa-label" }}
{{ forms.0.title|add_class:"usa-input"|attr:"aria-describedby:instructions" }}
{{ wizard.form.email|add_label_class:"usa-label" }}
{{ wizard.form.email|add_class:"usa-input"|attr:"aria-describedby:instructions" }}
{{ forms.0.email|add_label_class:"usa-label" }}
{{ forms.0.email|add_class:"usa-input"|attr:"aria-describedby:instructions" }}
{{ wizard.form.phone|add_label_class:"usa-label" }}
{{ wizard.form.phone|add_class:"usa-input usa-input--medium"|attr:"aria-describedby:instructions" }}
{{ forms.0.phone|add_label_class:"usa-label" }}
{{ forms.0.phone|add_class:"usa-input usa-input--medium"|attr:"aria-describedby:instructions" }}
</fieldset>

View file

@ -129,7 +129,7 @@
{% block logo %}
<div class="usa-logo" id="extended-logo">
<em class="usa-logo__text">
<a href="/" title="Home" aria-label="Home">
<a href="{% url 'home' %}" title="Home" aria-label="Home">
{% block site_name %}Home{% endblock %}
</a>
</em>
@ -145,14 +145,14 @@
<ul class="usa-nav__primary usa-accordion">
<li class="usa-nav__primary-item">
{% if user.is_authenticated %}
<a href="/whoami"><span>{{ user.email }}</span></a>
<a href="{% url 'whoami' %}"><span>{{ user.email }}</span></a>
</li>
<li class="usa-nav__primary-item display-flex flex-align-center">
<span class="text-base"> | </span>
<a href="/openid/logout"><span class="text-primary">Sign out</span></a>
<a href="{% url 'logout' %}"><span class="text-primary">Sign out</span></a>
</li>
{% else %}
<a href="/openid/login"><span>Sign in</span></a>
<a href="{% url 'login' %}"><span>Sign in</span></a>
{% endif %}
</li>
</ul>

View file

@ -44,7 +44,7 @@
</table>
{% endif %}
<p><a href="{% url 'application' %}" class="usa-button">Apply</a></p>
<p><a href="{% url 'application:' %}" class="usa-button">Apply</a></p>
<p><a href="{% url 'edit-profile' %}">Edit profile</a></p>

View file

@ -94,7 +94,7 @@
>
</li>
<li class="usa-identifier__required-links-item">
<a href="TODO" class="usa-identifier__required-link usa-link"
<a href="{% url 'todo' %}" class="usa-identifier__required-link usa-link"
>Vulnerability disclosure policy</a
>
</li>

View file

@ -6,6 +6,6 @@
<main id="main-content" class="grid-container">
<p> Hello {{ user.last_name|default:"No last name given" }}, {{ user.first_name|default:"No first name given" }} &lt;{{ user.email }}&gt;! </p>
<p><a href="/openid/logout">Click here to log out</a></p>
<p><a href="{% url 'logout' %}">Click here to log out</a></p>
</main>
{% endblock %}

View file

@ -0,0 +1,10 @@
from django import template
from django.urls import reverse
register = template.Library()
@register.simple_tag
def namespaced_url(namespace, name="", **kwargs):
"""Get a URL, given its Django namespace and name."""
return reverse(f"{namespace}:{name}", kwargs=kwargs)

View file

@ -8,7 +8,7 @@ from django.contrib.auth import get_user_model
from django_webtest import WebTest # type: ignore
from registrar.models import DomainApplication, Domain, Contact, Website
from registrar.forms.application_wizard import TITLES, Step
from registrar.views.application import ApplicationWizard
from .common import less_console_noise
@ -101,6 +101,7 @@ class DomainApplicationTests(TestWithUser, WebTest):
def setUp(self):
super().setUp()
self.app.set_user(self.user.username)
self.TITLES = ApplicationWizard.TITLES
def tearDown(self):
# delete any applications we made so that users can be deleted
@ -109,7 +110,7 @@ class DomainApplicationTests(TestWithUser, WebTest):
def test_application_form_empty_submit(self):
# 302 redirect to the first form
page = self.app.get(reverse("application")).follow()
page = self.app.get(reverse("application:")).follow()
# submitting should get back the same page if the required field is empty
result = page.form.submit()
self.assertIn(
@ -123,9 +124,9 @@ class DomainApplicationTests(TestWithUser, WebTest):
"""
num_pages_tested = 0
SKIPPED_PAGES = 1 # elections
num_pages = len(TITLES) - SKIPPED_PAGES
num_pages = len(self.TITLES) - SKIPPED_PAGES
type_page = self.app.get(reverse("application")).follow()
type_page = self.app.get(reverse("application:")).follow()
# django-webtest does not handle cookie-based sessions well because it keeps
# resetting the session key on each new request, thus destroying the concept
# of a "session". We are going to do it manually, saving the session ID here
@ -511,7 +512,8 @@ class DomainApplicationTests(TestWithUser, WebTest):
# final submission results in a redirect to the "finished" URL
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
review_result = review_form.submit()
with less_console_noise():
review_result = review_form.submit()
self.assertEquals(review_result.status_code, 302)
self.assertEquals(review_result["Location"], "/register/finished/")
@ -529,7 +531,7 @@ class DomainApplicationTests(TestWithUser, WebTest):
def test_application_form_conditional_federal(self):
"""Federal branch question is shown for federal organizations."""
type_page = self.app.get(reverse("application")).follow()
type_page = self.app.get(reverse("application:")).follow()
# django-webtest does not handle cookie-based sessions well because it keeps
# resetting the session key on each new request, thus destroying the concept
# of a "session". We are going to do it manually, saving the session ID here
@ -539,8 +541,8 @@ class DomainApplicationTests(TestWithUser, WebTest):
# ---- TYPE PAGE ----
# the conditional step titles shouldn't appear initially
self.assertNotContains(type_page, TITLES["organization_federal"])
self.assertNotContains(type_page, TITLES["organization_election"])
self.assertNotContains(type_page, self.TITLES["organization_federal"])
self.assertNotContains(type_page, self.TITLES["organization_election"])
type_form = type_page.form
type_form["organization_type-organization_type"] = "federal"
@ -557,8 +559,8 @@ class DomainApplicationTests(TestWithUser, WebTest):
# but the step label for the elections page should not appear
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
federal_page = type_result.follow()
self.assertContains(federal_page, TITLES["organization_federal"])
self.assertNotContains(federal_page, TITLES["organization_election"])
self.assertContains(federal_page, self.TITLES["organization_federal"])
self.assertNotContains(federal_page, self.TITLES["organization_election"])
# continuing on in the flow we need to see top-level agency on the
# contact page
@ -575,7 +577,7 @@ class DomainApplicationTests(TestWithUser, WebTest):
def test_application_form_conditional_elections(self):
"""Election question is shown for other organizations."""
type_page = self.app.get(reverse("application")).follow()
type_page = self.app.get(reverse("application:")).follow()
# django-webtest does not handle cookie-based sessions well because it keeps
# resetting the session key on each new request, thus destroying the concept
# of a "session". We are going to do it manually, saving the session ID here
@ -585,8 +587,8 @@ class DomainApplicationTests(TestWithUser, WebTest):
# ---- TYPE PAGE ----
# the conditional step titles shouldn't appear initially
self.assertNotContains(type_page, TITLES["organization_federal"])
self.assertNotContains(type_page, TITLES["organization_election"])
self.assertNotContains(type_page, self.TITLES["organization_federal"])
self.assertNotContains(type_page, self.TITLES["organization_election"])
type_form = type_page.form
type_form["organization_type-organization_type"] = "county"
@ -602,8 +604,8 @@ class DomainApplicationTests(TestWithUser, WebTest):
# but the step label for the elections page should not appear
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
election_page = type_result.follow()
self.assertContains(election_page, TITLES["organization_election"])
self.assertNotContains(election_page, TITLES["organization_federal"])
self.assertContains(election_page, self.TITLES["organization_election"])
self.assertNotContains(election_page, self.TITLES["organization_federal"])
# continuing on in the flow we need to NOT see top-level agency on the
# contact page
@ -622,7 +624,7 @@ class DomainApplicationTests(TestWithUser, WebTest):
def test_application_form_section_skipping(self):
"""Can skip forward and back in sections"""
type_page = self.app.get(reverse("application")).follow()
type_page = self.app.get(reverse("application:")).follow()
# django-webtest does not handle cookie-based sessions well because it keeps
# resetting the session key on each new request, thus destroying the concept
# of a "session". We are going to do it manually, saving the session ID here
@ -640,7 +642,7 @@ class DomainApplicationTests(TestWithUser, WebTest):
# Now on federal type page, click back to the organization type
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
new_page = federal_page.click(TITLES[Step.ORGANIZATION_TYPE], index=0)
new_page = federal_page.click(str(self.TITLES["organization_type"]), index=0)
# Should be a link to the organization_federal page
self.assertGreater(
@ -708,7 +710,7 @@ class DomainApplicationTests(TestWithUser, WebTest):
# -- the best that can/should be done here is to ensure the correct values
# are being passed to the templating engine
url = reverse("application_step", kwargs={"step": "organization_type"})
url = reverse("application:organization_type")
response = self.client.get(url, follow=True)
self.assertContains(response, "<input>")
# choices = response.context['wizard']['form']['organization_type'].subwidgets
@ -716,62 +718,62 @@ class DomainApplicationTests(TestWithUser, WebTest):
# checked = radio.data["selected"]
# self.assertTrue(checked)
# url = reverse("application_step", kwargs={"step": "organization_federal"})
# url = reverse("application:organization_federal")
# self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
# page = self.app.get(url)
# self.assertNotContains(page, "VALUE")
# url = reverse("application_step", kwargs={"step": "organization_contact"})
# url = reverse("application:organization_contact")
# self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
# page = self.app.get(url)
# self.assertNotContains(page, "VALUE")
# url = reverse("application_step", kwargs={"step": "authorizing_official"})
# url = reverse("application:authorizing_official")
# self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
# page = self.app.get(url)
# self.assertNotContains(page, "VALUE")
# url = reverse("application_step", kwargs={"step": "current_sites"})
# url = reverse("application:current_sites")
# self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
# page = self.app.get(url)
# self.assertNotContains(page, "VALUE")
# url = reverse("application_step", kwargs={"step": "dotgov_domain"})
# url = reverse("application:dotgov_domain")
# self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
# page = self.app.get(url)
# self.assertNotContains(page, "VALUE")
# url = reverse("application_step", kwargs={"step": "purpose"})
# url = reverse("application:purpose")
# self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
# page = self.app.get(url)
# self.assertNotContains(page, "VALUE")
# url = reverse("application_step", kwargs={"step": "your_contact"})
# url = reverse("application:your_contact")
# self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
# page = self.app.get(url)
# self.assertNotContains(page, "VALUE")
# url = reverse("application_step", kwargs={"step": "other_contacts"})
# url = reverse("application:other_contacts")
# self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
# page = self.app.get(url)
# self.assertNotContains(page, "VALUE")
# url = reverse("application_step", kwargs={"step": "other_contacts"})
# url = reverse("application:other_contacts")
# self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
# page = self.app.get(url)
# self.assertNotContains(page, "VALUE")
# url = reverse("application_step", kwargs={"step": "security_email"})
# url = reverse("application:security_email")
# self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
# page = self.app.get(url)
# self.assertNotContains(page, "VALUE")
# url = reverse("application_step", kwargs={"step": "anything_else"})
# url = reverse("application:anything_else")
# self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
# page = self.app.get(url)
# self.assertNotContains(page, "VALUE")
# url = reverse("application_step", kwargs={"step": "requirements"})
# url = reverse("application:requirements")
# self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
# page = self.app.get(url)
# self.assertNotContains(page, "VALUE")

View file

@ -0,0 +1 @@
from .str_enum import *

View file

@ -0,0 +1,43 @@
from enum import Enum, EnumMeta
class StrEnumMeta(EnumMeta):
"""A metaclass for creating a hybrid between a namedtuple and an Enum."""
def keys(cls):
return list(cls.__members__.keys())
def items(cls):
return {m: v.value for m, v in cls.__members__.items()}
def values(cls):
return list(cls)
def __contains__(cls, member):
"""Allow strings to match against member values."""
if isinstance(member, str):
return any(x == member for x in cls)
return super().__contains__(member)
def __getitem__(cls, member):
"""Allow member values to be accessed by index."""
if isinstance(member, int):
return list(cls)[member]
return super().__getitem__(member).value
def __iter__(cls):
for item in super().__iter__():
yield item.value
class StrEnum(str, Enum, metaclass=StrEnumMeta):
"""
Hybrid namedtuple and Enum.
Creates an iterable which can use dotted access notation,
but which is declared in class form like an Enum.
"""
def __str__(self):
"""Use value when cast to str."""
return str(self.value)

View file

@ -0,0 +1,5 @@
from .application import *
from .health import *
from .index import *
from .profile import *
from .whoami import *

View file

@ -0,0 +1,421 @@
import logging
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import Http404
from django.shortcuts import redirect, render
from django.urls import resolve, reverse
from django.utils.translation import gettext_lazy as _
from django.views.generic import TemplateView
from registrar.forms import application_wizard as forms
from registrar.models import DomainApplication
from registrar.utility import StrEnum
from registrar.views.utility import StepsHelper
logger = logging.getLogger(__name__)
class Step(StrEnum):
"""Names for each page of the application wizard."""
ORGANIZATION_TYPE = "organization_type"
ORGANIZATION_FEDERAL = "organization_federal"
ORGANIZATION_ELECTION = "organization_election"
ORGANIZATION_CONTACT = "organization_contact"
AUTHORIZING_OFFICIAL = "authorizing_official"
CURRENT_SITES = "current_sites"
DOTGOV_DOMAIN = "dotgov_domain"
PURPOSE = "purpose"
YOUR_CONTACT = "your_contact"
OTHER_CONTACTS = "other_contacts"
SECURITY_EMAIL = "security_email"
ANYTHING_ELSE = "anything_else"
REQUIREMENTS = "requirements"
REVIEW = "review"
class ApplicationWizard(LoginRequiredMixin, TemplateView):
"""
A common set of methods and configuration.
The registrar's domain application is several pages of "steps".
Together, these steps constitute a "wizard".
This base class sets up a shared state (stored in the user's session)
between pages of the application and provides common methods for
processing form data.
Views for each step should inherit from this base class.
Any method not marked as internal can be overridden in a subclass,
although not without consulting the base implementation, first.
"""
# uniquely namespace the wizard in urls.py
# (this is not seen _in_ urls, only for Django's internal naming)
# NB: this is included here for reference. Do not change it without
# also changing the many places it is hardcoded in the HTML templates
URL_NAMESPACE = "application"
# name for accessing /application/<id>/edit
EDIT_URL_NAME = "edit-application"
# We need to pass our human-readable step titles as context to the templates.
TITLES = {
Step.ORGANIZATION_TYPE: _("Type of organization"),
Step.ORGANIZATION_FEDERAL: _("Type of organization — Federal"),
Step.ORGANIZATION_ELECTION: _("Type of organization — Election board"),
Step.ORGANIZATION_CONTACT: _("Organization name and mailing address"),
Step.AUTHORIZING_OFFICIAL: _("Authorizing official"),
Step.CURRENT_SITES: _("Organization website"),
Step.DOTGOV_DOMAIN: _(".gov domain"),
Step.PURPOSE: _("Purpose of your domain"),
Step.YOUR_CONTACT: _("Your contact information"),
Step.OTHER_CONTACTS: _("Other contacts for your domain"),
Step.SECURITY_EMAIL: _("Security email for public use"),
Step.ANYTHING_ELSE: _("Anything else we should know?"),
Step.REQUIREMENTS: _(
"Requirements for registration and operation of .gov domains"
),
Step.REVIEW: _("Review and submit your domain request"),
}
# We can use a dictionary with step names and callables that return booleans
# to show or hide particular steps based on the state of the process.
WIZARD_CONDITIONS = {
Step.ORGANIZATION_FEDERAL: lambda w: w.from_model(
"show_organization_federal", False
),
Step.ORGANIZATION_ELECTION: lambda w: w.from_model(
"show_organization_election", False
),
}
def __init__(self):
super().__init__()
self.steps = StepsHelper(self)
self._application = None # for caching
@property
def prefix(self):
"""Namespace the wizard to avoid clashes in session variable names."""
# this is a string literal but can be made dynamic if we'd like
# users to have multiple applications open for editing simultaneously
return "wizard_application"
@property
def application(self) -> DomainApplication:
"""
Attempt to match the current wizard with a DomainApplication.
Will create an application if none exists.
"""
if self._application:
return self._application
if self.has_pk():
id = self.storage["application_id"]
try:
self._application = DomainApplication.objects.get(
creator=self.request.user, # type: ignore
pk=id,
)
return self._application
except DomainApplication.DoesNotExist:
logger.debug("Application id %s did not have a DomainApplication" % id)
self._application = DomainApplication.objects.create(
creator=self.request.user, # type: ignore
)
self.storage["application_id"] = self._application.id
return self._application
@property
def storage(self):
# marking session as modified on every access
# so that updates to nested keys are always saved
self.request.session.modified = True
if self.prefix not in self.request.session:
self.request.session[self.prefix] = {}
return self.request.session[self.prefix]
@storage.setter
def storage(self, value):
self.request.session[self.prefix] = value
self.request.session.modified = True
@storage.deleter
def storage(self):
del self.request.session[self.prefix]
self.request.session.modified = True
def done(self):
"""Called when the user clicks the submit button, if all forms are valid."""
self.application.submit() # change the status to submitted
self.application.save()
logger.debug("Application object saved: %s", self.application.id)
return redirect(reverse(f"{self.URL_NAMESPACE}:finished"))
def from_model(self, attribute: str, default, *args, **kwargs):
"""
Get a attribute from the database model, if it exists.
If it is a callable, call it with any given `args` and `kwargs`.
This method exists so that we can avoid needlessly creating a record
in the database before the wizard has been saved.
"""
if self.has_pk():
if hasattr(self.application, attribute):
attr = getattr(self.application, attribute)
if callable(attr):
return attr(*args, **kwargs)
else:
return attr
else:
raise AttributeError("Model has no attribute %s" % str(attribute))
else:
return default
def get(self, request, *args, **kwargs):
"""This method handles GET requests."""
current_url = resolve(request.path_info).url_name
# if user visited via an "edit" url, associate the id of the
# application they are trying to edit to this wizard instance
if current_url == self.EDIT_URL_NAME and "id" in kwargs:
self.storage["application_id"] = kwargs["id"]
# if accessing this class directly, redirect to the first step
if self.__class__ == ApplicationWizard:
return self.goto(self.steps.first)
self.steps.current = current_url
context = self.get_context_data()
context["forms"] = self.get_forms()
return render(request, self.template_name, context)
def get_all_forms(self) -> list:
"""Calls `get_forms` for all steps and returns a flat list."""
nested = (self.get_forms(step=step, use_db=True) for step in self.steps)
flattened = [form for lst in nested for form in lst]
return flattened
def get_forms(self, step=None, use_post=False, use_db=False, files=None):
"""
This method constructs the forms for a given step.
The form's initial data will always be gotten from the database,
via the form's `from_database` classmethod.
The form's bound data will be gotten from POST if `use_post` is True,
and from the database if `use_db` is True (provided that record exists).
An empty form will be provided if neither of those are true.
"""
kwargs = {
"files": files,
"prefix": self.steps.current,
}
if step is None:
forms = self.forms
else:
url = reverse(f"{self.URL_NAMESPACE}:{step}")
forms = resolve(url).func.view_class.forms
instantiated = []
for form in forms:
data = form.from_database(self.application) if self.has_pk() else None
kwargs["initial"] = data
if use_post:
kwargs["data"] = self.request.POST
elif use_db:
kwargs["data"] = data
else:
kwargs["data"] = None
instantiated.append(form(**kwargs))
return instantiated
def get_context_data(self):
"""Define context for access on all wizard pages."""
return {
"form_titles": self.TITLES,
"steps": self.steps,
# Add information about which steps should be unlocked
"visited": self.storage.get("step_history", []),
}
def get_step_list(self) -> list:
"""Dynamically generated list of steps in the form wizard."""
step_list = []
for step in Step:
condition = self.WIZARD_CONDITIONS.get(step, True)
if callable(condition):
condition = condition(self)
if condition:
step_list.append(step)
return step_list
def goto(self, step):
self.steps.current = step
return redirect(reverse(f"{self.URL_NAMESPACE}:{step}"))
def goto_next_step(self):
"""Redirects to the next step."""
next = self.steps.next
if next:
self.steps.current = next
return self.goto(next)
else:
raise Http404()
def has_pk(self):
"""Does this wizard know about a DomainApplication database record?"""
return "application_id" in self.storage
def is_valid(self, forms: list = None) -> bool:
"""Returns True if all forms in the wizard are valid."""
forms = forms if forms is not None else self.get_all_forms()
are_valid = (form.is_valid() for form in forms)
return all(are_valid)
def post(self, request, *args, **kwargs):
"""This method handles POST requests."""
# if accessing this class directly, redirect to the first step
if self.__class__ == ApplicationWizard:
return self.goto(self.steps.first)
forms = self.get_forms(use_post=True)
if self.is_valid(forms):
# always save progress
self.save(forms)
else:
# unless there are errors
context = self.get_context_data()
context["forms"] = forms
return render(request, self.template_name, context)
# if user opted to save their progress,
# return them to the page they were already on
button = request.POST.get("submit_button", None)
if button == "save":
return self.goto(self.steps.current)
# otherwise, proceed as normal
return self.goto_next_step()
def save(self, forms: list):
"""
Unpack the form responses onto the model object properties.
Saves the application to the database.
"""
for form in forms:
if form is not None and hasattr(form, "to_database"):
form.to_database(self.application)
class OrganizationType(ApplicationWizard):
template_name = "application_org_type.html"
forms = [forms.OrganizationTypeForm]
class OrganizationFederal(ApplicationWizard):
template_name = "application_org_federal.html"
forms = [forms.OrganizationFederalForm]
class OrganizationElection(ApplicationWizard):
template_name = "application_org_election.html"
forms = [forms.OrganizationElectionForm]
class OrganizationContact(ApplicationWizard):
template_name = "application_org_contact.html"
forms = [forms.OrganizationContactForm]
def get_context_data(self):
context = super().get_context_data()
context["is_federal"] = self.application.is_federal()
return context
class AuthorizingOfficial(ApplicationWizard):
template_name = "application_authorizing_official.html"
forms = [forms.AuthorizingOfficialForm]
class CurrentSites(ApplicationWizard):
template_name = "application_current_sites.html"
forms = [forms.CurrentSitesForm]
class DotgovDomain(ApplicationWizard):
template_name = "application_dotgov_domain.html"
forms = [forms.DotGovDomainForm]
class Purpose(ApplicationWizard):
template_name = "application_purpose.html"
forms = [forms.PurposeForm]
class YourContact(ApplicationWizard):
template_name = "application_your_contact.html"
forms = [forms.YourContactForm]
class OtherContacts(ApplicationWizard):
template_name = "application_other_contacts.html"
forms = [forms.OtherContactsForm]
class SecurityEmail(ApplicationWizard):
template_name = "application_security_email.html"
forms = [forms.SecurityEmailForm]
class AnythingElse(ApplicationWizard):
template_name = "application_anything_else.html"
forms = [forms.AnythingElseForm]
class Requirements(ApplicationWizard):
template_name = "application_requirements.html"
forms = [forms.RequirementsForm]
class Review(ApplicationWizard):
template_name = "application_review.html"
forms = [] # type: ignore
def get_context_data(self):
context = super().get_context_data()
context["Step"] = Step.__members__
context["application"] = self.application
return context
def goto_next_step(self):
return self.done()
# TODO: validate before saving, show errors
# forms = self.get_all_forms()
# if self.is_valid(forms):
# return self.done()
# else:
# # TODO: errors to let users know why this isn't working
# return self.goto(self.steps.current)
class Finished(ApplicationWizard):
template_name = "application_done.html"
forms = [] # type: ignore
def get(self, request, *args, **kwargs):
context = self.get_context_data()
context["application_id"] = self.application.id
# clean up this wizard session, because we are done with it
del self.storage
return render(self.request, self.template_name, context)

View file

@ -2,7 +2,7 @@ from django.shortcuts import redirect, render
from django.contrib.auth.decorators import login_required
from django.contrib import messages
from ..forms import EditProfileForm
from registrar.forms import EditProfileForm
@login_required

View file

@ -0,0 +1,2 @@
from .steps_helper import StepsHelper
from .always_404 import always_404

View file

@ -0,0 +1,6 @@
from django.http import Http404
def always_404(_, reason=None):
"""Helpful view which always returns 404."""
raise Http404(reason)

View file

@ -0,0 +1,136 @@
import logging
from django.urls import resolve
logger = logging.getLogger(__name__)
class StepsHelper:
"""
Helps with form steps in a form wizard.
Code adapted from
https://github.com/jazzband/django-formtools/blob/master/formtools/wizard/views.py
LICENSE FOR THIS CLASS
Copyright (c) Django Software Foundation and individual contributors.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of django-formtools nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
def __init__(self, wizard):
self._wizard = wizard
def __dir__(self):
return self.all
def __len__(self):
return self.count
def __repr__(self):
return "<StepsHelper for %s (steps: %s)>" % (self._wizard, self.all)
def __getitem__(self, step):
return self.all[step]
@property
def all(self):
"""Returns the names of all steps."""
return self._wizard.get_step_list()
@property
def count(self):
"""Returns the total number of steps/forms in this the wizard."""
return len(self.all)
@property
def current(self):
"""
Returns the current step. If no current step is stored in the
storage backend, the first step will be returned.
"""
step = getattr(self._wizard.storage, "current_step", None)
if step is None:
current_url = resolve(self._wizard.request.path_info).url_name
step = current_url if current_url in self.all else self.first
self._wizard.storage["current_step"] = step
return step
@current.setter
def current(self, step: str):
"""Sets the current step. Updates step history."""
if step in self.all:
self._wizard.storage["current_step"] = step
else:
logger.debug("Invalid step name %s given to StepHelper" % str(step))
self._wizard.storage["current_step"] = self.first
# can't serialize a set, so keep list entries unique
if step not in self.history:
self.history.append(step)
@property
def first(self):
"""Returns the name of the first step."""
return self.all[0]
@property
def last(self):
"""Returns the name of the last step."""
return self.all[-1]
@property
def next(self):
"""Returns the next step."""
steps = self.all
index = steps.index(self.current) + 1
if index < self.count:
return steps[index]
return None
@property
def prev(self):
"""Returns the previous step."""
steps = self.all
key = steps.index(self.current) - 1
if key >= 0:
return steps[key]
return None
@property
def index(self):
"""Returns the index for the current step."""
steps = self.all
if self.current in steps:
return steps.index(self)
return None
@property
def history(self):
"""Returns the list of already visited steps."""
return self._wizard.storage.setdefault("step_history", [])