mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-13 21:19:42 +02:00
Add link
This commit is contained in:
parent
bf1d5fad47
commit
a5a0c136df
4 changed files with 68 additions and 11 deletions
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
from urllib.parse import urlparse, urlunparse, urlencode
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -266,3 +268,29 @@ class CreateOrUpdateOrganizationTypeHelper:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def replace_url_queryparams(url_to_modify: str, query_params: dict[Any, list]):
|
||||||
|
"""
|
||||||
|
Replaces the query parameters of a given URL.
|
||||||
|
Because this replaces them, this can be used to either add, delete, or modify.
|
||||||
|
Args:
|
||||||
|
url_to_modify (str): The URL whose query parameters need to be modified.
|
||||||
|
query_params (dict): Dictionary of query parameters to use.
|
||||||
|
Returns:
|
||||||
|
str: The modified URL with the updated query parameters.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Ensure each key in query_params maps to a single value, not a list
|
||||||
|
query_params = {k: v[0] if isinstance(v, list) else v for k, v in query_params.items()}
|
||||||
|
|
||||||
|
# Split the URL into parts
|
||||||
|
url_parts = list(urlparse(url_to_modify))
|
||||||
|
|
||||||
|
# Modify the query param bit
|
||||||
|
url_parts[4] = urlencode(query_params)
|
||||||
|
|
||||||
|
# Reassemble the URL
|
||||||
|
new_url = urlunparse(url_parts)
|
||||||
|
|
||||||
|
return new_url
|
|
@ -16,7 +16,7 @@
|
||||||
completing your domain request might take around 15 minutes.</p>
|
completing your domain request might take around 15 minutes.</p>
|
||||||
{% if has_profile_feature_flag %}
|
{% if has_profile_feature_flag %}
|
||||||
<h2>How we’ll reach you</h2>
|
<h2>How we’ll reach you</h2>
|
||||||
<p>While reviewing your domain request, we may need to reach out with questions. We’ll also email you when we complete our review If the contact information below is not correct, visit <a href="" target="_blank" class="usa-link">your profile</a> to make updates.</p>
|
<p>While reviewing your domain request, we may need to reach out with questions. We’ll also email you when we complete our review If the contact information below is not correct, visit <a href="{% url 'user-profile' %}?return_to_request=True" class="usa-link">your profile</a> to make updates.</p>
|
||||||
{% include "includes/profile_information.html" with user=user%}
|
{% include "includes/profile_information.html" with user=user%}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
|
@ -10,14 +10,19 @@ Edit your User Profile |
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<main id="main-content" class="grid-container">
|
<main id="main-content" class="grid-container">
|
||||||
<div class="grid-col desktop:grid-offset-2 desktop:grid-col-8">
|
<div class="grid-col desktop:grid-offset-2 desktop:grid-col-8">
|
||||||
<a href="{% url 'home' %}" class="breadcrumb__back">
|
<a href="{% if not return_to_request %}{% url 'home' %}{% else %}{% url 'domain-request:' %}{% endif %}" class="breadcrumb__back">
|
||||||
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img">
|
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img">
|
||||||
<use xlink:href="{% static 'img/sprite.svg' %}#arrow_back"></use>
|
<use xlink:href="{% static 'img/sprite.svg' %}#arrow_back"></use>
|
||||||
</svg>
|
</svg>
|
||||||
|
{% if not return_to_request %}
|
||||||
<p class="margin-left-05 margin-top-0 margin-bottom-0 line-height-sans-1">
|
<p class="margin-left-05 margin-top-0 margin-bottom-0 line-height-sans-1">
|
||||||
Back to manage your domains
|
Back to manage your domains
|
||||||
</p>
|
</p>
|
||||||
|
{% else %}
|
||||||
|
<p class="margin-left-05 margin-top-0 margin-bottom-0 line-height-sans-1">
|
||||||
|
Go back to your domain request
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
</a>
|
</a>
|
||||||
{# messages block is under the back breadcrumb link #}
|
{# messages block is under the back breadcrumb link #}
|
||||||
{% if messages %}
|
{% if messages %}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from urllib.parse import parse_qs, unquote, urlencode
|
||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.views.generic.edit import FormMixin
|
from django.views.generic.edit import FormMixin
|
||||||
|
@ -11,6 +12,7 @@ from django.urls import reverse
|
||||||
from registrar.models import (
|
from registrar.models import (
|
||||||
Contact,
|
Contact,
|
||||||
)
|
)
|
||||||
|
from registrar.models.utility.generic_helper import replace_url_queryparams
|
||||||
from registrar.views.utility.permission_views import UserProfilePermissionView
|
from registrar.views.utility.permission_views import UserProfilePermissionView
|
||||||
from waffle.decorators import flag_is_active, waffle_flag
|
from waffle.decorators import flag_is_active, waffle_flag
|
||||||
|
|
||||||
|
@ -30,13 +32,26 @@ class UserProfileView(UserProfilePermissionView, FormMixin):
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
"""Handle get requests by getting user's contact object and setting object
|
"""Handle get requests by getting user's contact object and setting object
|
||||||
and form to context before rendering."""
|
and form to context before rendering."""
|
||||||
self.object = self.get_object()
|
self._refresh_session_and_object(request)
|
||||||
form = self.form_class(instance=self.object)
|
form = self.form_class(instance=self.object)
|
||||||
context = self.get_context_data(object=self.object, form=form)
|
context = self.get_context_data(object=self.object, form=form)
|
||||||
|
|
||||||
|
return_to_request = request.GET.get("return_to_request")
|
||||||
|
if return_to_request:
|
||||||
|
context["return_to_request"] = True
|
||||||
|
|
||||||
return self.render_to_response(context)
|
return self.render_to_response(context)
|
||||||
|
|
||||||
|
def _refresh_session_and_object(self, request):
|
||||||
|
"""Sets the current session to self.session and the current object to self.object"""
|
||||||
|
self.session = request.session
|
||||||
|
self.object = self.get_object()
|
||||||
|
|
||||||
@waffle_flag("profile_feature") # type: ignore
|
@waffle_flag("profile_feature") # type: ignore
|
||||||
def dispatch(self, request, *args, **kwargs): # type: ignore
|
def dispatch(self, request, *args, **kwargs): # type: ignore
|
||||||
|
# Store the original queryparams to persist them
|
||||||
|
query_params = request.META["QUERY_STRING"]
|
||||||
|
request.session["query_params"] = query_params
|
||||||
return super().dispatch(request, *args, **kwargs)
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
@ -48,11 +63,20 @@ class UserProfileView(UserProfilePermissionView, FormMixin):
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
"""Redirect to the user's profile page."""
|
"""Redirect to the user's profile page."""
|
||||||
return reverse("user-profile")
|
|
||||||
|
query_params = {}
|
||||||
|
if "query_params" in self.session:
|
||||||
|
params = unquote(self.session["query_params"])
|
||||||
|
query_params = parse_qs(params)
|
||||||
|
|
||||||
|
# Preserve queryparams and add them back to the url
|
||||||
|
base_url = reverse("user-profile")
|
||||||
|
new_redirect = replace_url_queryparams(base_url, query_params) if query_params else base_url
|
||||||
|
return new_redirect
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
"""Handle post requests (form submissions)"""
|
"""Handle post requests (form submissions)"""
|
||||||
self.object = self.get_object()
|
self._refresh_session_and_object(request)
|
||||||
form = self.form_class(request.POST, instance=self.object)
|
form = self.form_class(request.POST, instance=self.object)
|
||||||
|
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue