From 9e1628aa842d94d236e939179081e09917485d9d Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Thu, 6 Feb 2025 14:48:21 -0700 Subject: [PATCH 1/3] Add proper breadcrumb --- src/registrar/admin.py | 38 +++++++++++++++++++- src/registrar/config/urls.py | 6 ---- src/registrar/templates/admin/analytics.html | 15 +++++++- src/registrar/templates/admin/app_list.html | 2 +- 4 files changed, 52 insertions(+), 9 deletions(-) diff --git a/src/registrar/admin.py b/src/registrar/admin.py index 928ead442..5c0e8ab22 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -33,6 +33,7 @@ from registrar.utility.email_invitations import ( send_portfolio_admin_addition_emails, send_portfolio_invitation_email, ) +from registrar.views.report_views import AnalyticsView from registrar.views.utility.invitation_helper import ( get_org_membership, get_requested_user, @@ -43,7 +44,7 @@ from django.contrib import admin, messages from django.contrib.auth.admin import UserAdmin as BaseUserAdmin from django.contrib.auth.models import Group from django.contrib.contenttypes.models import ContentType -from django.urls import reverse +from django.urls import path, reverse from epplibwrapper.errors import ErrorCode, RegistryError from registrar.models.user_domain_role import UserDomainRole from waffle.admin import FlagAdmin @@ -4450,3 +4451,38 @@ admin.site.register(models.WaffleFlag, WaffleFlagAdmin) # Unregister Switch and Sample from the waffle library admin.site.unregister(Switch) admin.site.unregister(Sample) + +# ----------------------------------------------------------------------------- +# Monkey Patch: Extend Django Admin URLs to include our Analytics dashboard. +# ----------------------------------------------------------------------------- +def get_custom_admin_urls(original_get_urls): + """ + Wrap the original admin site's get_urls() method to include a custom URL for the + Analytics dashboard. By doing this, the dashboard will be integrated into the admin + navigation with the correct context (breadcrumbs, header, etc.) and will behave like + a admin page. + """ + def get_urls(): + # Retrieve the default admin URL patterns. + urls = original_get_urls() + + # Define our custom URL for the Analytics dashboard. + # The admin_view wrapper applies admin-specific authorization and context. + custom_urls = [ + path( + "dashboard/", + admin.site.admin_view(AnalyticsView.as_view()), + name="analytics-dashboard" + ) + ] + + # Prepend our custom URLs to the admin URL patterns. + # This way, when navigating the admin, the analytics dashboard is available + # via its own integrated URL. + return custom_urls + urls + + return get_urls + +# Apply the monkey patch to the admin site's get_urls method. +# This ensures that our custom URL for the Analytics dashboard is added. +admin.site.get_urls = get_custom_admin_urls(admin.site.get_urls) diff --git a/src/registrar/config/urls.py b/src/registrar/config/urls.py index eb095c5ca..e31e1d74b 100644 --- a/src/registrar/config/urls.py +++ b/src/registrar/config/urls.py @@ -17,7 +17,6 @@ from registrar.views.report_views import ( ExportDataRequestsGrowth, ExportDataType, ExportDataUnmanagedDomains, - AnalyticsView, ExportDomainRequestDataFull, ExportDataTypeUser, ExportMembersPortfolio, @@ -212,11 +211,6 @@ urlpatterns = [ ExportDataUnmanagedDomains.as_view(), name="export_unmanaged_domains", ), - path( - "admin/analytics/", - AnalyticsView.as_view(), - name="analytics", - ), path("admin/registrar/user//transfer/", TransferUserView.as_view(), name="transfer_user"), path( "admin/api/get-senior-official-from-federal-agency-json/", diff --git a/src/registrar/templates/admin/analytics.html b/src/registrar/templates/admin/analytics.html index 7c1a09c78..280178ea3 100644 --- a/src/registrar/templates/admin/analytics.html +++ b/src/registrar/templates/admin/analytics.html @@ -1,8 +1,21 @@ {% extends "admin/base_site.html" %} {% load static %} +{% load i18n %} {% block content_title %}

Registrar Analytics

{% endblock %} +{% block breadcrumbs %} +{% comment %} +Overrides the breadcrumb styles found in this file: +https://github.com/django/django/blob/main/django/contrib/admin/templates/admin/base.html +{% endcomment %} + +{% endblock %} + {% block content %}
@@ -112,7 +125,7 @@
  • -
  • -