mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-23 19:20:47 +02:00
updated tests, linted some
This commit is contained in:
parent
2d5da90286
commit
e23a2ee0ba
4 changed files with 90 additions and 30 deletions
|
@ -238,15 +238,11 @@ class DomainRequestAdminForm(forms.ModelForm):
|
||||||
"current_websites": NoAutocompleteFilteredSelectMultiple("current_websites", False),
|
"current_websites": NoAutocompleteFilteredSelectMultiple("current_websites", False),
|
||||||
"alternative_domains": NoAutocompleteFilteredSelectMultiple("alternative_domains", False),
|
"alternative_domains": NoAutocompleteFilteredSelectMultiple("alternative_domains", False),
|
||||||
"other_contacts": NoAutocompleteFilteredSelectMultiple("other_contacts", False),
|
"other_contacts": NoAutocompleteFilteredSelectMultiple("other_contacts", False),
|
||||||
'portfolio': AutocompleteSelectWithPlaceholder(
|
"portfolio": AutocompleteSelectWithPlaceholder(
|
||||||
DomainRequest._meta.get_field('portfolio'),
|
DomainRequest._meta.get_field("portfolio"), admin.site, attrs={"data-placeholder": "---------"}
|
||||||
admin.site,
|
|
||||||
attrs={'data-placeholder': '---------'}
|
|
||||||
),
|
),
|
||||||
'sub_organization': AutocompleteSelectWithPlaceholder(
|
"sub_organization": AutocompleteSelectWithPlaceholder(
|
||||||
DomainRequest._meta.get_field('sub_organization'),
|
DomainRequest._meta.get_field("sub_organization"), admin.site, attrs={"data-placeholder": "---------"}
|
||||||
admin.site,
|
|
||||||
attrs={'data-placeholder': '---------'}
|
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
labels = {
|
labels = {
|
||||||
|
@ -1740,40 +1736,68 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
custom_election_board.admin_order_field = "is_election_board" # type: ignore
|
custom_election_board.admin_order_field = "is_election_board" # type: ignore
|
||||||
custom_election_board.short_description = "Election office" # type: ignore
|
custom_election_board.short_description = "Election office" # type: ignore
|
||||||
|
|
||||||
|
|
||||||
# Define methods to display fields from the related portfolio
|
# Define methods to display fields from the related portfolio
|
||||||
def portfolio_senior_official(self, obj) -> Optional[SeniorOfficial]:
|
def portfolio_senior_official(self, obj) -> Optional[SeniorOfficial]:
|
||||||
return obj.portfolio.senior_official if obj.portfolio and obj.portfolio.senior_official else None
|
return obj.portfolio.senior_official if obj.portfolio and obj.portfolio.senior_official else None
|
||||||
|
|
||||||
portfolio_senior_official.short_description = "Senior official"
|
portfolio_senior_official.short_description = "Senior official"
|
||||||
|
|
||||||
def portfolio_organization_type(self, obj):
|
def portfolio_organization_type(self, obj):
|
||||||
return DomainRequest.OrganizationChoices.get_org_label(obj.portfolio.organization_type) if obj.portfolio and obj.portfolio.organization_type else "-"
|
return (
|
||||||
|
DomainRequest.OrganizationChoices.get_org_label(obj.portfolio.organization_type)
|
||||||
|
if obj.portfolio and obj.portfolio.organization_type
|
||||||
|
else "-"
|
||||||
|
)
|
||||||
|
|
||||||
portfolio_organization_type.short_description = "Organization type"
|
portfolio_organization_type.short_description = "Organization type"
|
||||||
|
|
||||||
def portfolio_federal_type(self, obj):
|
def portfolio_federal_type(self, obj):
|
||||||
return BranchChoices.get_branch_label(obj.portfolio.federal_type) if obj.portfolio and obj.portfolio.federal_type else "-"
|
return (
|
||||||
|
BranchChoices.get_branch_label(obj.portfolio.federal_type)
|
||||||
|
if obj.portfolio and obj.portfolio.federal_type
|
||||||
|
else "-"
|
||||||
|
)
|
||||||
|
|
||||||
portfolio_federal_type.short_description = "Federal type"
|
portfolio_federal_type.short_description = "Federal type"
|
||||||
|
|
||||||
def portfolio_organization_name(self, obj):
|
def portfolio_organization_name(self, obj):
|
||||||
return obj.portfolio.organization_name if obj.portfolio else ""
|
return obj.portfolio.organization_name if obj.portfolio else ""
|
||||||
|
|
||||||
portfolio_organization_name.short_description = "Organization name"
|
portfolio_organization_name.short_description = "Organization name"
|
||||||
|
|
||||||
def portfolio_federal_agency(self, obj):
|
def portfolio_federal_agency(self, obj):
|
||||||
return obj.portfolio.federal_agency if obj.portfolio else ""
|
return obj.portfolio.federal_agency if obj.portfolio else ""
|
||||||
|
|
||||||
portfolio_federal_agency.short_description = "Federal agency"
|
portfolio_federal_agency.short_description = "Federal agency"
|
||||||
|
|
||||||
def portfolio_state_territory(self, obj):
|
def portfolio_state_territory(self, obj):
|
||||||
return obj.portfolio.state_territory if obj.portfolio else ""
|
return obj.portfolio.state_territory if obj.portfolio else ""
|
||||||
|
|
||||||
portfolio_state_territory.short_description = "State, territory, or military post"
|
portfolio_state_territory.short_description = "State, territory, or military post"
|
||||||
|
|
||||||
def portfolio_address_line1(self, obj):
|
def portfolio_address_line1(self, obj):
|
||||||
return obj.portfolio.address_line1 if obj.portfolio else ""
|
return obj.portfolio.address_line1 if obj.portfolio else ""
|
||||||
|
|
||||||
portfolio_address_line1.short_description = "Address line 1"
|
portfolio_address_line1.short_description = "Address line 1"
|
||||||
|
|
||||||
def portfolio_address_line2(self, obj):
|
def portfolio_address_line2(self, obj):
|
||||||
return obj.portfolio.address_line2 if obj.portfolio else ""
|
return obj.portfolio.address_line2 if obj.portfolio else ""
|
||||||
|
|
||||||
portfolio_address_line2.short_description = "Address line 2"
|
portfolio_address_line2.short_description = "Address line 2"
|
||||||
|
|
||||||
def portfolio_city(self, obj):
|
def portfolio_city(self, obj):
|
||||||
return obj.portfolio.city if obj.portfolio else ""
|
return obj.portfolio.city if obj.portfolio else ""
|
||||||
|
|
||||||
portfolio_city.short_description = "City"
|
portfolio_city.short_description = "City"
|
||||||
|
|
||||||
def portfolio_zipcode(self, obj):
|
def portfolio_zipcode(self, obj):
|
||||||
return obj.portfolio.zipcode if obj.portfolio else ""
|
return obj.portfolio.zipcode if obj.portfolio else ""
|
||||||
|
|
||||||
portfolio_zipcode.short_description = "Zip code"
|
portfolio_zipcode.short_description = "Zip code"
|
||||||
|
|
||||||
def portfolio_urbanization(self, obj):
|
def portfolio_urbanization(self, obj):
|
||||||
return obj.portfolio.urbanization if obj.portfolio else ""
|
return obj.portfolio.urbanization if obj.portfolio else ""
|
||||||
|
|
||||||
portfolio_urbanization.short_description = "Urbanization"
|
portfolio_urbanization.short_description = "Urbanization"
|
||||||
|
|
||||||
# This is just a placeholder. This field will be populated in the detail_table_fieldset view.
|
# This is just a placeholder. This field will be populated in the detail_table_fieldset view.
|
||||||
|
@ -1830,7 +1854,7 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
"suborganization_state_territory",
|
"suborganization_state_territory",
|
||||||
"creator",
|
"creator",
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
),
|
),
|
||||||
(".gov domain", {"fields": ["requested_domain", "alternative_domains"]}),
|
(".gov domain", {"fields": ["requested_domain", "alternative_domains"]}),
|
||||||
(
|
(
|
||||||
|
@ -1903,7 +1927,7 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
"portfolio_organization_type",
|
"portfolio_organization_type",
|
||||||
"portfolio_federal_type",
|
"portfolio_federal_type",
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"Organization name and mailing address",
|
"Organization name and mailing address",
|
||||||
|
|
|
@ -1526,7 +1526,7 @@ class TestDomainRequestAdmin(MockEppLib):
|
||||||
self.test_helper.assert_response_contains_distinct_values(response, expected_other_employees_fields)
|
self.test_helper.assert_response_contains_distinct_values(response, expected_other_employees_fields)
|
||||||
|
|
||||||
# Test for the copy link
|
# Test for the copy link
|
||||||
self.assertContains(response, "copy-to-clipboard", count=4)
|
self.assertContains(response, "copy-to-clipboard", count=5)
|
||||||
|
|
||||||
# Test that Creator counts display properly
|
# Test that Creator counts display properly
|
||||||
self.assertNotContains(response, "Approved domains")
|
self.assertNotContains(response, "Approved domains")
|
||||||
|
@ -1626,6 +1626,17 @@ class TestDomainRequestAdmin(MockEppLib):
|
||||||
readonly_fields = self.admin.get_readonly_fields(request, domain_request)
|
readonly_fields = self.admin.get_readonly_fields(request, domain_request)
|
||||||
|
|
||||||
expected_fields = [
|
expected_fields = [
|
||||||
|
"portfolio_senior_official",
|
||||||
|
"portfolio_organization_type",
|
||||||
|
"portfolio_federal_type",
|
||||||
|
"portfolio_organization_name",
|
||||||
|
"portfolio_federal_agency",
|
||||||
|
"portfolio_state_territory",
|
||||||
|
"portfolio_address_line1",
|
||||||
|
"portfolio_address_line2",
|
||||||
|
"portfolio_city",
|
||||||
|
"portfolio_zipcode",
|
||||||
|
"portfolio_urbanization",
|
||||||
"other_contacts",
|
"other_contacts",
|
||||||
"current_websites",
|
"current_websites",
|
||||||
"alternative_domains",
|
"alternative_domains",
|
||||||
|
@ -1691,6 +1702,17 @@ class TestDomainRequestAdmin(MockEppLib):
|
||||||
readonly_fields = self.admin.get_readonly_fields(request)
|
readonly_fields = self.admin.get_readonly_fields(request)
|
||||||
self.maxDiff = None
|
self.maxDiff = None
|
||||||
expected_fields = [
|
expected_fields = [
|
||||||
|
"portfolio_senior_official",
|
||||||
|
"portfolio_organization_type",
|
||||||
|
"portfolio_federal_type",
|
||||||
|
"portfolio_organization_name",
|
||||||
|
"portfolio_federal_agency",
|
||||||
|
"portfolio_state_territory",
|
||||||
|
"portfolio_address_line1",
|
||||||
|
"portfolio_address_line2",
|
||||||
|
"portfolio_city",
|
||||||
|
"portfolio_zipcode",
|
||||||
|
"portfolio_urbanization",
|
||||||
"other_contacts",
|
"other_contacts",
|
||||||
"current_websites",
|
"current_websites",
|
||||||
"alternative_domains",
|
"alternative_domains",
|
||||||
|
@ -1723,6 +1745,17 @@ class TestDomainRequestAdmin(MockEppLib):
|
||||||
readonly_fields = self.admin.get_readonly_fields(request)
|
readonly_fields = self.admin.get_readonly_fields(request)
|
||||||
|
|
||||||
expected_fields = [
|
expected_fields = [
|
||||||
|
"portfolio_senior_official",
|
||||||
|
"portfolio_organization_type",
|
||||||
|
"portfolio_federal_type",
|
||||||
|
"portfolio_organization_name",
|
||||||
|
"portfolio_federal_agency",
|
||||||
|
"portfolio_state_territory",
|
||||||
|
"portfolio_address_line1",
|
||||||
|
"portfolio_address_line2",
|
||||||
|
"portfolio_city",
|
||||||
|
"portfolio_zipcode",
|
||||||
|
"portfolio_urbanization",
|
||||||
"other_contacts",
|
"other_contacts",
|
||||||
"current_websites",
|
"current_websites",
|
||||||
"alternative_domains",
|
"alternative_domains",
|
||||||
|
|
|
@ -95,12 +95,14 @@ def get_field_links_as_list(
|
||||||
else:
|
else:
|
||||||
links = "".join(links)
|
links = "".join(links)
|
||||||
return format_html(f'<ul class="add-list-reset">{links}</ul>') if links else msg_for_none
|
return format_html(f'<ul class="add-list-reset">{links}</ul>') if links else msg_for_none
|
||||||
|
|
||||||
|
|
||||||
class AutocompleteSelectWithPlaceholder(AutocompleteSelect):
|
class AutocompleteSelectWithPlaceholder(AutocompleteSelect):
|
||||||
"""Override of the default autoselect element. This is because by default,
|
"""Override of the default autoselect element. This is because by default,
|
||||||
the autocomplete element clears data-placeholder"""
|
the autocomplete element clears data-placeholder"""
|
||||||
|
|
||||||
def build_attrs(self, base_attrs, extra_attrs=None):
|
def build_attrs(self, base_attrs, extra_attrs=None):
|
||||||
attrs = super().build_attrs(base_attrs, extra_attrs=extra_attrs)
|
attrs = super().build_attrs(base_attrs, extra_attrs=extra_attrs)
|
||||||
if 'data-placeholder' in base_attrs:
|
if "data-placeholder" in base_attrs:
|
||||||
attrs['data-placeholder'] = base_attrs['data-placeholder']
|
attrs["data-placeholder"] = base_attrs["data-placeholder"]
|
||||||
return attrs
|
return attrs
|
||||||
|
|
|
@ -6,7 +6,6 @@ from django.contrib.admin.views.decorators import staff_member_required
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from registrar.utility.admin_helpers import get_action_needed_reason_default_email, get_rejection_reason_default_email
|
from registrar.utility.admin_helpers import get_action_needed_reason_default_email, get_rejection_reason_default_email
|
||||||
from registrar.models.portfolio import Portfolio
|
from registrar.models.portfolio import Portfolio
|
||||||
from registrar.models.domain_request import DomainRequest
|
|
||||||
from registrar.utility.constants import BranchChoices
|
from registrar.utility.constants import BranchChoices
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -63,16 +62,21 @@ def get_portfolio_json(request):
|
||||||
portfolio_dict["id"] = portfolio.id
|
portfolio_dict["id"] = portfolio.id
|
||||||
|
|
||||||
# map portfolio federal type
|
# map portfolio federal type
|
||||||
portfolio_dict["federal_type"] = BranchChoices.get_branch_label(portfolio.federal_type) if portfolio.federal_type else "-"
|
portfolio_dict["federal_type"] = (
|
||||||
|
BranchChoices.get_branch_label(portfolio.federal_type) if portfolio.federal_type else "-"
|
||||||
|
)
|
||||||
|
|
||||||
# map portfolio organization type
|
# map portfolio organization type
|
||||||
portfolio_dict["organization_type"] = DomainRequest.OrganizationChoices.get_org_label(portfolio.organization_type) if portfolio.organization_type else "-"
|
portfolio_dict["organization_type"] = (
|
||||||
|
DomainRequest.OrganizationChoices.get_org_label(portfolio.organization_type)
|
||||||
|
if portfolio.organization_type
|
||||||
|
else "-"
|
||||||
|
)
|
||||||
|
|
||||||
# Add senior official information if it exists
|
# Add senior official information if it exists
|
||||||
if portfolio.senior_official:
|
if portfolio.senior_official:
|
||||||
senior_official = model_to_dict(
|
senior_official = model_to_dict(
|
||||||
portfolio.senior_official,
|
portfolio.senior_official, fields=["id", "first_name", "last_name", "title", "phone", "email"]
|
||||||
fields=["id", "first_name", "last_name", "title", "phone", "email"]
|
|
||||||
)
|
)
|
||||||
# The phone number field isn't json serializable, so we
|
# The phone number field isn't json serializable, so we
|
||||||
# convert this to a string first if it exists.
|
# convert this to a string first if it exists.
|
||||||
|
@ -84,13 +88,10 @@ def get_portfolio_json(request):
|
||||||
|
|
||||||
# Add federal agency information if it exists
|
# Add federal agency information if it exists
|
||||||
if portfolio.federal_agency:
|
if portfolio.federal_agency:
|
||||||
federal_agency = model_to_dict(
|
federal_agency = model_to_dict(portfolio.federal_agency, fields=["agency", "id"])
|
||||||
portfolio.federal_agency,
|
|
||||||
fields=["agency", "id"]
|
|
||||||
)
|
|
||||||
portfolio_dict["federal_agency"] = federal_agency
|
portfolio_dict["federal_agency"] = federal_agency
|
||||||
else:
|
else:
|
||||||
portfolio_dict["federal_agency"] = '-'
|
portfolio_dict["federal_agency"] = "-"
|
||||||
|
|
||||||
return JsonResponse(portfolio_dict)
|
return JsonResponse(portfolio_dict)
|
||||||
|
|
||||||
|
@ -115,7 +116,7 @@ def get_suborganization_list_json(request):
|
||||||
# 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")
|
||||||
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}})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue