Cleanup context and template logic

This commit is contained in:
zandercymatics 2024-05-21 15:00:03 -06:00
parent 47de6f17a7
commit 84febbbde3
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
4 changed files with 44 additions and 69 deletions

View file

@ -8,41 +8,12 @@
{% include "includes/gov_extended_logo.html" with logo_clickable=False %}
{% endblock %}
{% block content %}
<div class="grid-container">
<div class="grid-row grid-gap">
<div class="tablet:grid-col">
<main id="main-content" class="grid-container">
{# messages block is under the back breadcrumb link #}
{% if messages %}
{% for message in messages %}
<div class="usa-alert usa-alert--{{ message.tags }} usa-alert--slim margin-bottom-3">
<div class="usa-alert__body">
{{ message }}
</div>
</div>
{% endfor %}
{% endif %}
{% include "includes/form_errors.html" with form=form %}
{% if confirm_changes and not going_to_specific_page %}
<a href="{% url 'home' %}" 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>
<p class="margin-left-05 margin-top-0 margin-bottom-0 line-height-sans-1">
Back to manage your domains
</p>
</a>
{% endif %}
{% include "includes/finish_profile_form.html" with form=form %}
</main>
</div>
{# Add the new form #}
{% block content_bottom %}
{% include "includes/finish_profile_form.html" with form=form %}
</div>
</div>
{% endblock content %}
</main>
{% endblock content_bottom %}
{% block footer %}
{% include "includes/footer.html" %}

View file

@ -51,10 +51,12 @@
{% endwith %}
</div>
{# This field doesn't have the readonly button but it has common design elements from it #}
{% with show_readonly=True group_classes="usa-form-readonly padding-top-2 bold-usa-label" %}
{% with target_blank="true" sublabel_text=email_sublabel_text add_class="display-none" %}
{% input_with_errors form.email %}
{% public_site_url "help/account-management/#get-help-with-login.gov" as login_help_url %}
{% with link_href=login_help_url show_readonly=True group_classes="usa-form-readonly padding-top-2 bold-usa-label" add_class="display-none"%}
{% with sublabel_text="We recommend using your work email for your .gov account. If the wrong email is displayed below, youll need to update your Login.gov account and log back in. Get help with your Login.gov account." %}
{% with link_text="Get help with your Login.gov account" target_blank=True do_not_show_max_chars=True %}
{% input_with_errors form.email %}
{% endwith %}
{% endwith %}
{% endwith %}

View file

@ -8,16 +8,6 @@ Edit your User Profile |
{% block content %}
<main id="main-content" class="grid-container">
<div class="grid-col desktop:grid-offset-2 desktop:grid-col-8">
<a href="{% url 'home' %}" 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>
<p class="margin-left-05 margin-top-0 margin-bottom-0 line-height-sans-1">
Go to manage your domains
</p>
</a>
{# messages block is under the back breadcrumb link #}
{% if messages %}
{% for message in messages %}
<div class="usa-alert usa-alert--{{ message.tags }} usa-alert--slim margin-bottom-3">
@ -28,7 +18,23 @@ Edit your User Profile |
{% endfor %}
{% endif %}
{% include "includes/form_errors.html" with form=form %}
{% include "includes/profile_form.html" with form=form %}
{% if show_back_button %}
<a href="{% url 'home' %}" 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>
<p class="margin-left-05 margin-top-0 margin-bottom-0 line-height-sans-1">
{{ profile_back_button_text }}
</p>
</a>
{% endif %}
{% endblock content %}
{% block content_bottom %}
{% include "includes/profile_form.html" with form=form %}
</div>
</main>
{% endblock content %}
{% endblock %}

View file

@ -56,6 +56,11 @@ class UserProfileView(UserProfilePermissionView, FormMixin):
context = super().get_context_data(**kwargs)
# This is a django waffle flag which toggles features based off of the "flag" table
context["has_profile_feature_flag"] = flag_is_active(self.request, "profile_feature")
# The text for the back button on this page
context["profile_back_button_text"] = "Go to manage your domains"
context["show_back_button"] = True
return context
def get_success_url(self):
@ -104,44 +109,35 @@ class FinishProfileSetupView(UserProfileView):
Enums for each type of redirection. Enforces behaviour on `get_redirect_url()`.
- HOME: We want to redirect to reverse("home")
- BACK_TO_SELF: We want to redirect back to reverse("finish-user-profile-setup")
- BACK_TO_SELF: We want to redirect back to this page
- TO_SPECIFIC_PAGE: We want to redirect to the page specified in the queryparam "redirect"
- COMPLETE_SETUP: Indicates that we want to navigate BACK_TO_SELF, but the subsequent
redirect after the next POST should be either HOME or TO_SPECIFIC_PAGE
"""
HOME = "home"
TO_SPECIFIC_PAGE = "domain_request"
BACK_TO_SELF = "back_to_self"
COMPLETE_SETUP = "complete_setup"
TO_SPECIFIC_PAGE = "domain_request"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["email_sublabel_text"] = self._email_sublabel_text()
# Hide the back button by default
context["show_back_button"] = False
if self.redirect_type == self.RedirectType.COMPLETE_SETUP:
context["confirm_changes"] = True
if "redirect_viewname" in self.session:
context["going_to_specific_page"] = True
context["redirect_button_text"] = "Continue to your request"
if "redirect_viewname" not in self.session:
context["show_back_button"] = True
else:
context["going_to_specific_page"] = True
context["redirect_button_text"] = "Continue to your request"
return context
def _email_sublabel_text(self):
"""Returns the lengthy sublabel for the email field"""
help_url = public_site_url("help/account-management/#get-help-with-login.gov")
return mark_safe(
"We recommend using your work email for your .gov account. "
"If the wrong email is displayed below, youll need to update your Login.gov account "
f'and log back in. <a class="usa-link" href={help_url}>Get help with your Login.gov account.</a>'
) # nosec
def get_success_message(self, cleaned_data):
"""Content of the returned success message"""
return "Your profile has been successfully updated."
@method_decorator(csrf_protect)
def dispatch(self, request, *args, **kwargs):
"""