mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-22 18:56:15 +02:00
Attempt at adding ANDI in via Middleware
This commit is contained in:
parent
9dcf44832b
commit
f1f1ea34ef
2 changed files with 16 additions and 0 deletions
|
@ -190,6 +190,7 @@ MIDDLEWARE = [
|
|||
"waffle.middleware.WaffleMiddleware",
|
||||
"registrar.registrar_middleware.CheckUserProfileMiddleware",
|
||||
"registrar.registrar_middleware.CheckPortfolioMiddleware",
|
||||
"registrar.registrar_middleware.ANDIMiddleware",
|
||||
]
|
||||
|
||||
# application object used by Django’s built-in servers (e.g. `runserver`)
|
||||
|
|
|
@ -8,6 +8,7 @@ from django.urls import reverse
|
|||
from django.http import HttpResponseRedirect
|
||||
from registrar.models.user import User
|
||||
from waffle.decorators import flag_is_active
|
||||
from django.utils.deprecation import MiddlewareMixin
|
||||
|
||||
from registrar.models.utility.generic_helper import replace_url_queryparams
|
||||
|
||||
|
@ -157,3 +158,17 @@ class CheckPortfolioMiddleware:
|
|||
return HttpResponseRedirect(portfolio_redirect)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
class ANDIMiddleware(MiddlewareMixin):
|
||||
def process_response(self, request, response):
|
||||
# Check if the response content type is HTML
|
||||
if "text/html" in response.get("Content-Type", ""):
|
||||
andi_script = """
|
||||
<script src="https://www.ssa.gov/accessibility/andi/andi.js"></script>
|
||||
"""
|
||||
# Inject the ANDI script before the closing </body> tag
|
||||
content = response.content.decode("utf-8")
|
||||
content = content.replace("</body>", f"{andi_script}</body>")
|
||||
response.content = content.encode("utf-8")
|
||||
return response
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue