mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-06-10 06:24:45 +02:00
Track visited steps in session storage
This commit is contained in:
parent
ba7c0b9e8d
commit
b2905068b1
2 changed files with 24 additions and 1 deletions
|
@ -12,6 +12,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.urls import resolve
|
from django.urls import resolve
|
||||||
|
|
||||||
from formtools.wizard.views import NamedUrlSessionWizardView # type: ignore
|
from formtools.wizard.views import NamedUrlSessionWizardView # type: ignore
|
||||||
|
from formtools.wizard.storage.session import SessionStorage
|
||||||
|
|
||||||
from registrar.models import Contact, DomainApplication, Domain
|
from registrar.models import Contact, DomainApplication, Domain
|
||||||
|
|
||||||
|
@ -382,6 +383,19 @@ WIZARD_CONDITIONS = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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):
|
class ApplicationWizard(LoginRequiredMixin, NamedUrlSessionWizardView):
|
||||||
|
|
||||||
"""Multi-page form ("wizard") for new domain applications.
|
"""Multi-page form ("wizard") for new domain applications.
|
||||||
|
@ -397,6 +411,7 @@ class ApplicationWizard(LoginRequiredMixin, NamedUrlSessionWizardView):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
form_list = FORMS
|
form_list = FORMS
|
||||||
|
storage_name = "registrar.forms.application_wizard.TrackingStorage"
|
||||||
|
|
||||||
def get_template_names(self):
|
def get_template_names(self):
|
||||||
"""Template for the current step.
|
"""Template for the current step.
|
||||||
|
@ -418,6 +433,14 @@ class ApplicationWizard(LoginRequiredMixin, NamedUrlSessionWizardView):
|
||||||
"""Add title information to the context for all steps."""
|
"""Add title information to the context for all steps."""
|
||||||
context = super().get_context_data(form=form, **kwargs)
|
context = super().get_context_data(form=form, **kwargs)
|
||||||
context["form_titles"] = TITLES
|
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:
|
if self.steps.current == Step.ORGANIZATION_CONTACT:
|
||||||
context["is_federal"] = self._is_federal()
|
context["is_federal"] = self._is_federal()
|
||||||
if self.steps.current == Step.REVIEW:
|
if self.steps.current == Step.REVIEW:
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<nav aria-label="Form steps,">
|
<nav aria-label="Form steps,">
|
||||||
<ul class="usa-sidenav">
|
<ul class="usa-sidenav">
|
||||||
{% for this_step in wizard.steps.all %}
|
{% for this_step in wizard.steps.all %}
|
||||||
{% if forloop.counter <= wizard.steps.step1 %}
|
{% if this_step in visited %}
|
||||||
<li class="usa-sidenav__item">
|
<li class="usa-sidenav__item">
|
||||||
<a href="{% url wizard.url_name step=this_step %}"
|
<a href="{% url wizard.url_name step=this_step %}"
|
||||||
{% if this_step == wizard.steps.current %}class="usa-current"{% endif%}>
|
{% if this_step == wizard.steps.current %}class="usa-current"{% endif%}>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue