From 469a4bda879c5440ec11f587e42f5b02dcdc80b7 Mon Sep 17 00:00:00 2001 From: CocoByte Date: Fri, 16 Aug 2024 15:44:37 -0600 Subject: [PATCH 1/3] Added domains and domain request section to suborgs --- src/registrar/admin.py | 23 ++++++++++++ .../django/admin/suborg_change_form.html | 36 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/registrar/templates/django/admin/suborg_change_form.html diff --git a/src/registrar/admin.py b/src/registrar/admin.py index 423c0a01b7..b3ce636013 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -9,6 +9,7 @@ from django.http import HttpResponseRedirect from django.shortcuts import redirect from django_fsm import get_available_FIELD_transitions, FSMField +from registrar.models.domain_information import DomainInformation from registrar.models.utility.portfolio_helper import UserPortfolioPermissionChoices, UserPortfolioRoleChoices from waffle.decorators import flag_is_active from django.contrib import admin, messages @@ -3142,12 +3143,34 @@ class DomainGroupAdmin(ListHeaderAdmin, ImportExportModelAdmin): class SuborganizationAdmin(ListHeaderAdmin, ImportExportModelAdmin): + list_display = ["name", "portfolio"] autocomplete_fields = [ "portfolio", ] search_fields = ["name"] + change_form_template = "django/admin/suborg_change_form.html" + def change_view(self, request, object_id, form_url="", extra_context=None): + """Add suborg's related domains and requests to context""" + obj = self.get_object(request, object_id) + + # ---- Domain Requests + # domain_requests = DomainRequest.objects.filter(sub_organization=obj).exclude( + # Q(status=DomainRequest.DomainRequestStatus.STARTED) | Q(status=DomainRequest.DomainRequestStatus.WITHDRAWN) + # ) + domain_requests = DomainRequest.objects.filter(sub_organization=obj) + sort_by = request.GET.get("sort_by", "requested_domain__name") + domain_requests = domain_requests.order_by(sort_by) + + # ---- Domains + domain_infos = DomainInformation.objects.filter(sub_organization=obj) + domain_ids = domain_infos.values_list("domain", flat=True) + domains = Domain.objects.filter(id__in=domain_ids).exclude(state=Domain.State.DELETED) + + extra_context = {"domain_requests": domain_requests, "domains": domains} + return super().change_view(request, object_id, form_url, extra_context) + admin.site.unregister(LogEntry) # Unregister the default registration diff --git a/src/registrar/templates/django/admin/suborg_change_form.html b/src/registrar/templates/django/admin/suborg_change_form.html new file mode 100644 index 0000000000..005d67aecd --- /dev/null +++ b/src/registrar/templates/django/admin/suborg_change_form.html @@ -0,0 +1,36 @@ +{% extends 'django/admin/email_clipboard_change_form.html' %} +{% load i18n static %} + +{% block after_related_objects %} +
+

Associated requests and domains

+
+
+

Domain requests

+ +
+
+

Domains

+ +
+
+
+{% endblock %} From b83cc5a980bea05559a52fc20447567053bdf820 Mon Sep 17 00:00:00 2001 From: CocoByte Date: Fri, 16 Aug 2024 15:45:01 -0600 Subject: [PATCH 2/3] removed commented out code --- src/registrar/admin.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/registrar/admin.py b/src/registrar/admin.py index b3ce636013..bb3c09ae9a 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -3156,9 +3156,6 @@ def change_view(self, request, object_id, form_url="", extra_context=None): obj = self.get_object(request, object_id) # ---- Domain Requests - # domain_requests = DomainRequest.objects.filter(sub_organization=obj).exclude( - # Q(status=DomainRequest.DomainRequestStatus.STARTED) | Q(status=DomainRequest.DomainRequestStatus.WITHDRAWN) - # ) domain_requests = DomainRequest.objects.filter(sub_organization=obj) sort_by = request.GET.get("sort_by", "requested_domain__name") domain_requests = domain_requests.order_by(sort_by) From efc78361975ef22d90144f0ab3c7f007470641a5 Mon Sep 17 00:00:00 2001 From: CocoByte Date: Fri, 16 Aug 2024 16:06:37 -0600 Subject: [PATCH 3/3] linted --- src/registrar/admin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/registrar/admin.py b/src/registrar/admin.py index bb3c09ae9a..3ad5e3ea0f 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -3151,6 +3151,7 @@ class SuborganizationAdmin(ListHeaderAdmin, ImportExportModelAdmin): search_fields = ["name"] change_form_template = "django/admin/suborg_change_form.html" + def change_view(self, request, object_id, form_url="", extra_context=None): """Add suborg's related domains and requests to context""" obj = self.get_object(request, object_id)