Skip to content

Commit

Permalink
Merge pull request #2610 from cisagov/nl/2518-suborg-domainrequest-di…
Browse files Browse the repository at this point in the history
…splay

Issue #2518: Suborganization shows all related domains/requests [cb]
  • Loading branch information
CocoByte authored Aug 19, 2024
2 parents eb56239 + efc7836 commit 21ecf77
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/registrar/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -3142,12 +3143,32 @@ 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)
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

Expand Down
36 changes: 36 additions & 0 deletions src/registrar/templates/django/admin/suborg_change_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{% extends 'django/admin/email_clipboard_change_form.html' %}
{% load i18n static %}

{% block after_related_objects %}
<div class="module aligned padding-3">
<h2>Associated requests and domains</h2>
<div class="grid-row grid-gap mobile:padding-x-1 desktop:padding-x-4">
<div class="mobile:grid-col-12 tablet:grid-col-6 desktop:grid-col-4">
<h3>Domain requests</h3>
<ul class="margin-0 padding-0">
{% for domain_request in domain_requests %}
<li>
<a href="{% url 'admin:registrar_domainrequest_change' domain_request.pk %}">
{{ domain_request.requested_domain }}
</a>
({{ domain_request.status }})
</li>
{% endfor %}
</ul>
</div>
<div class="mobile:grid-col-12 tablet:grid-col-6 desktop:grid-col-4">
<h3>Domains</h3>
<ul class="margin-0 padding-0">
{% for domain in domains %}
<li>
<a href="{% url 'admin:registrar_domain_change' domain.pk %}">
{{ domain.name }}
</a>
({{ domain.state }})
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
{% endblock %}

0 comments on commit 21ecf77

Please sign in to comment.