From 9c230fcfa7cb5d6378373f7b46ce58a32bb200d8 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Tue, 21 May 2024 15:13:39 -0600 Subject: [PATCH] Cleanup --- src/registrar/registrar_middleware.py | 2 +- src/registrar/views/user_profile.py | 20 +++++++------------- src/registrar/views/utility/mixins.py | 2 -- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/registrar/registrar_middleware.py b/src/registrar/registrar_middleware.py index 8485f25e6..eb5ec7df0 100644 --- a/src/registrar/registrar_middleware.py +++ b/src/registrar/registrar_middleware.py @@ -26,7 +26,7 @@ class CheckUserProfileMiddleware: return response def process_view(self, request, view_func, view_args, view_kwargs): - """Runs pre-processing logic for each view. Checks for the + """Runs pre-processing logic for each view. Checks for the finished_setup flag on the current user. If they haven't done so, then we redirect them to the finish setup page.""" # Check that the user is "opted-in" to the profile feature flag diff --git a/src/registrar/views/user_profile.py b/src/registrar/views/user_profile.py index e0a4283ff..d65de1660 100644 --- a/src/registrar/views/user_profile.py +++ b/src/registrar/views/user_profile.py @@ -16,9 +16,7 @@ from registrar.models import ( from registrar.views.utility.permission_views import UserProfilePermissionView from waffle.decorators import flag_is_active, waffle_flag -from registrar.templatetags.url_helpers import public_site_url from registrar.models.utility.generic_helper import replace_url_queryparams -from django.utils.safestring import mark_safe from django.utils.decorators import method_decorator from django.views.decorators.csrf import csrf_protect @@ -102,8 +100,6 @@ class FinishProfileSetupView(UserProfileView): form_class = FinishSetupProfileForm model = Contact - redirect_type = None - class RedirectType(Enum): """ Enums for each type of redirection. Enforces behaviour on `get_redirect_url()`. @@ -120,6 +116,9 @@ class FinishProfileSetupView(UserProfileView): BACK_TO_SELF = "back_to_self" COMPLETE_SETUP = "complete_setup" + redirect_type = None + all_redirect_types = [r.value for r in RedirectType] + def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) @@ -153,9 +152,7 @@ class FinishProfileSetupView(UserProfileView): # Update redirect type based on the query parameter if present redirect_type = request.GET.get("redirect", self.RedirectType.BACK_TO_SELF.value) - - all_redirect_types = [r.value for r in self.RedirectType] - if redirect_type in all_redirect_types: + if redirect_type in self.all_redirect_types: self.redirect_type = self.RedirectType(redirect_type) else: # If the redirect type is undefined, then we assume that @@ -178,11 +175,8 @@ class FinishProfileSetupView(UserProfileView): # Logic for when the 'Save' button is clicked self.redirect_type = self.RedirectType.COMPLETE_SETUP elif "contact_setup_submit_button" in request.POST: - if "redirect_viewname" in self.session: - self.redirect_type = self.RedirectType.TO_SPECIFIC_PAGE - else: - self.redirect_type = self.RedirectType.HOME - + specific_redirect = "redirect_viewname" in self.session + self.redirect_type = self.RedirectType.TO_SPECIFIC_PAGE if specific_redirect else self.RedirectType.HOME return self.form_valid(form) else: return self.form_invalid(form) @@ -211,7 +205,7 @@ class FinishProfileSetupView(UserProfileView): base_url = "" try: if self.redirect_type in self_redirect: - base_url = reverse("finish-user-profile-setup", kwargs={"pk": self.object.pk}) + base_url = reverse("finish-user-profile-setup") elif self.redirect_type == self.RedirectType.TO_SPECIFIC_PAGE: # We only allow this session value to use viewnames, # because this restricts what can be redirected to. diff --git a/src/registrar/views/utility/mixins.py b/src/registrar/views/utility/mixins.py index da5606d52..0b8a7605a 100644 --- a/src/registrar/views/utility/mixins.py +++ b/src/registrar/views/utility/mixins.py @@ -8,8 +8,6 @@ from registrar.models import ( DomainInvitation, DomainInformation, UserDomainRole, - Contact, - User, ) import logging