mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-24 03:30:50 +02:00
* Correcting sort in Admin: Domains, Portfolios * Adding ordering to Suborganization table * Validated user-facing ordering in Domain Request Suborganization dropdown * Adding test for alphabetization --------- Co-authored-by: CocoByte <nicolle.leclair@gmail.com>
This commit is contained in:
parent
42b53f7b94
commit
a5e96b93bf
5 changed files with 32 additions and 3 deletions
|
@ -0,0 +1,17 @@
|
||||||
|
# Generated by Django 4.2.20 on 2025-06-16 19:58
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("registrar", "0150_remove_domainrequest_eop_stakeholder_first_name_and_more"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name="suborganization",
|
||||||
|
options={"ordering": ["name"]},
|
||||||
|
),
|
||||||
|
]
|
|
@ -192,4 +192,4 @@ class Portfolio(TimeStampedModel):
|
||||||
# == Getters for suborganization == #
|
# == Getters for suborganization == #
|
||||||
def get_suborganizations(self):
|
def get_suborganizations(self):
|
||||||
"""Returns all suborganizations associated with this portfolio"""
|
"""Returns all suborganizations associated with this portfolio"""
|
||||||
return self.portfolio_suborganizations.all()
|
return self.portfolio_suborganizations.all().order_by("name")
|
||||||
|
|
|
@ -9,6 +9,9 @@ class Suborganization(TimeStampedModel):
|
||||||
Suborganization under an organization (portfolio)
|
Suborganization under an organization (portfolio)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ["name"]
|
||||||
|
|
||||||
name = models.CharField(
|
name = models.CharField(
|
||||||
unique=True,
|
unique=True,
|
||||||
max_length=1000,
|
max_length=1000,
|
||||||
|
|
|
@ -9,6 +9,7 @@ from registrar.utility.errors import MissingEmailError
|
||||||
from waffle.testutils import override_flag
|
from waffle.testutils import override_flag
|
||||||
from django_webtest import WebTest # type: ignore
|
from django_webtest import WebTest # type: ignore
|
||||||
from api.tests.common import less_console_noise_decorator
|
from api.tests.common import less_console_noise_decorator
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from registrar.admin import (
|
from registrar.admin import (
|
||||||
DomainAdmin,
|
DomainAdmin,
|
||||||
|
@ -4166,14 +4167,22 @@ class TestPortfolioAdmin(TestCase):
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_suborganizations_display(self):
|
def test_suborganizations_display(self):
|
||||||
"""Tests the custom suborg field which displays all related suborgs"""
|
"""Tests the custom suborg field which displays all related suborgs"""
|
||||||
Suborganization.objects.create(name="Sub1", portfolio=self.portfolio)
|
|
||||||
Suborganization.objects.create(name="Sub2", portfolio=self.portfolio)
|
Suborganization.objects.create(name="Sub2", portfolio=self.portfolio)
|
||||||
|
Suborganization.objects.create(name="Sub1", portfolio=self.portfolio)
|
||||||
|
Suborganization.objects.create(name="Sub5", portfolio=self.portfolio)
|
||||||
|
Suborganization.objects.create(name="Sub3", portfolio=self.portfolio)
|
||||||
|
Suborganization.objects.create(name="Sub4", portfolio=self.portfolio)
|
||||||
|
|
||||||
suborganizations = self.admin.suborganizations(self.portfolio)
|
suborganizations = self.admin.suborganizations(self.portfolio)
|
||||||
self.assertIn("Sub1", suborganizations)
|
self.assertIn("Sub1", suborganizations)
|
||||||
self.assertIn("Sub2", suborganizations)
|
self.assertIn("Sub2", suborganizations)
|
||||||
self.assertIn('<ul class="add-list-reset">', suborganizations)
|
self.assertIn('<ul class="add-list-reset">', suborganizations)
|
||||||
|
|
||||||
|
# Ensuring alphabetical display of Suborgs
|
||||||
|
soup = BeautifulSoup(suborganizations, "html.parser")
|
||||||
|
suborg_names = [li.text for li in soup.find_all("li")]
|
||||||
|
self.assertEqual(suborg_names, ["Sub1", "Sub2", "Sub3", "Sub4", "Sub5"])
|
||||||
|
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_domains_display(self):
|
def test_domains_display(self):
|
||||||
"""Tests the custom domains field which displays all related domains"""
|
"""Tests the custom domains field which displays all related domains"""
|
||||||
|
|
|
@ -92,7 +92,7 @@ def get_suborganization_list_json(request):
|
||||||
return JsonResponse({"error": "Portfolio not found"}, status=404)
|
return JsonResponse({"error": "Portfolio not found"}, status=404)
|
||||||
|
|
||||||
# Add suborganizations related to this portfolio
|
# Add suborganizations related to this portfolio
|
||||||
suborganizations = portfolio.portfolio_suborganizations.all().values("id", "name")
|
suborganizations = portfolio.portfolio_suborganizations.all().values("id", "name").order_by("name")
|
||||||
results = [{"id": sub["id"], "text": sub["name"]} for sub in suborganizations]
|
results = [{"id": sub["id"], "text": sub["name"]} for sub in suborganizations]
|
||||||
return JsonResponse({"results": results, "pagination": {"more": False}})
|
return JsonResponse({"results": results, "pagination": {"more": False}})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue