mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-13 04:59:59 +02:00
Fixed annotations and sort
This commit is contained in:
parent
34ba850277
commit
e75c027738
2 changed files with 94 additions and 41 deletions
|
@ -63,8 +63,8 @@ class CsvReportsTest(MockDbForSharedTests):
|
||||||
fake_open = mock_open()
|
fake_open = mock_open()
|
||||||
expected_file_content = [
|
expected_file_content = [
|
||||||
call("Domain name,Domain type,Agency,Organization name,City,State,Security contact email\r\n"),
|
call("Domain name,Domain type,Agency,Organization name,City,State,Security contact email\r\n"),
|
||||||
call("cdomain11.gov,Federal - Executive,183,,,,(blank)\r\n"),
|
call("cdomain11.gov,Federal - Executive,WorldWarICentennialCommission,,,,(blank)\r\n"),
|
||||||
call("cdomain1.gov,Federal - Executive,183,,,,(blank)\r\n"),
|
call("cdomain1.gov,Federal - Executive,WorldWarICentennialCommission,,,,(blank)\r\n"),
|
||||||
call("adomain10.gov,Federal,8,,,,(blank)\r\n"),
|
call("adomain10.gov,Federal,8,,,,(blank)\r\n"),
|
||||||
call("ddomain3.gov,Federal,8,,,,(blank)\r\n"),
|
call("ddomain3.gov,Federal,8,,,,(blank)\r\n"),
|
||||||
]
|
]
|
||||||
|
@ -85,8 +85,8 @@ class CsvReportsTest(MockDbForSharedTests):
|
||||||
fake_open = mock_open()
|
fake_open = mock_open()
|
||||||
expected_file_content = [
|
expected_file_content = [
|
||||||
call("Domain name,Domain type,Agency,Organization name,City,State,Security contact email\r\n"),
|
call("Domain name,Domain type,Agency,Organization name,City,State,Security contact email\r\n"),
|
||||||
call("cdomain11.gov,Federal - Executive,183,,,,(blank)\r\n"),
|
call("cdomain11.gov,Federal - Executive,WorldWarICentennialCommission,,,,(blank)\r\n"),
|
||||||
call("cdomain1.gov,Federal - Executive,183,,,,(blank)\r\n"),
|
call("cdomain1.gov,Federal - Executive,WorldWarICentennialCommission,,,,(blank)\r\n"),
|
||||||
call("adomain10.gov,Federal,8,,,,(blank)\r\n"),
|
call("adomain10.gov,Federal,8,,,,(blank)\r\n"),
|
||||||
call("ddomain3.gov,Federal,8,,,,(blank)\r\n"),
|
call("ddomain3.gov,Federal,8,,,,(blank)\r\n"),
|
||||||
call("zdomain12.gov,Interstate,,,,,(blank)\r\n"),
|
call("zdomain12.gov,Interstate,,,,,(blank)\r\n"),
|
||||||
|
@ -245,17 +245,17 @@ class ExportDataTest(MockDbForIndividualTests, MockEppLib):
|
||||||
expected_content = (
|
expected_content = (
|
||||||
"Domain name,Status,First ready on,Expiration date,Domain type,Agency,Organization name,City,State,SO,"
|
"Domain name,Status,First ready on,Expiration date,Domain type,Agency,Organization name,City,State,SO,"
|
||||||
"SO email,Security contact email,Domain managers,Invited domain managers\n"
|
"SO email,Security contact email,Domain managers,Invited domain managers\n"
|
||||||
"cdomain11.gov,Ready,2024-04-02,(blank),Federal - Executive,188,,,, ,,(blank),meoward@rocks.com,\n"
|
"cdomain11.gov,Ready,2024-04-02,(blank),Federal - Executive,WorldWarICentennialCommission,,,, ,,(blank),meoward@rocks.com,\n"
|
||||||
"defaultsecurity.gov,Ready,2023-11-01,(blank),Federal - Executive,188,,,, ,,(blank),"
|
"defaultsecurity.gov,Ready,2023-11-01,(blank),Federal - Executive,WorldWarICentennialCommission,,,, ,,(blank),"
|
||||||
'"big_lebowski@dude.co, info@example.com, meoward@rocks.com",woofwardthethird@rocks.com\n'
|
'"big_lebowski@dude.co, info@example.com, meoward@rocks.com",woofwardthethird@rocks.com\n'
|
||||||
"adomain10.gov,Ready,2024-04-03,(blank),Federal,189,,,, ,,(blank),,squeaker@rocks.com\n"
|
"adomain10.gov,Ready,2024-04-03,(blank),Federal,ArmedForcesRetirementHome,,,, ,,(blank),,squeaker@rocks.com\n"
|
||||||
"bdomain4.gov,Unknown,(blank),(blank),Federal,189,,,, ,,(blank),,\n"
|
"bdomain4.gov,Unknown,(blank),(blank),Federal,ArmedForcesRetirementHome,,,, ,,(blank),,\n"
|
||||||
"bdomain5.gov,Deleted,(blank),(blank),Federal,189,,,, ,,(blank),,\n"
|
"bdomain5.gov,Deleted,(blank),(blank),Federal,ArmedForcesRetirementHome,,,, ,,(blank),,\n"
|
||||||
"bdomain6.gov,Deleted,(blank),(blank),Federal,189,,,, ,,(blank),,\n"
|
"bdomain6.gov,Deleted,(blank),(blank),Federal,ArmedForcesRetirementHome,,,, ,,(blank),,\n"
|
||||||
"ddomain3.gov,On hold,(blank),2023-11-15,Federal,189,,,, ,,security@mail.gov,,\n"
|
"ddomain3.gov,On hold,(blank),2023-11-15,Federal,ArmedForcesRetirementHome,,,, ,,security@mail.gov,,\n"
|
||||||
"sdomain8.gov,Deleted,(blank),(blank),Federal,189,,,, ,,(blank),,\n"
|
"sdomain8.gov,Deleted,(blank),(blank),Federal,ArmedForcesRetirementHome,,,, ,,(blank),,\n"
|
||||||
"xdomain7.gov,Deleted,(blank),(blank),Federal,189,,,, ,,(blank),,\n"
|
"xdomain7.gov,Deleted,(blank),(blank),Federal,ArmedForcesRetirementHome,,,, ,,(blank),,\n"
|
||||||
"zdomain9.gov,Deleted,(blank),(blank),Federal,189,,,, ,,(blank),,\n"
|
"zdomain9.gov,Deleted,(blank),(blank),Federal,ArmedForcesRetirementHome,,,, ,,(blank),,\n"
|
||||||
"adomain2.gov,Dns needed,(blank),(blank),Interstate,,,,, ,,(blank),meoward@rocks.com,squeaker@rocks.com\n"
|
"adomain2.gov,Dns needed,(blank),(blank),Interstate,,,,, ,,(blank),meoward@rocks.com,squeaker@rocks.com\n"
|
||||||
"zdomain12.gov,Ready,2024-04-02,(blank),Interstate,,,,, ,,(blank),meoward@rocks.com,\n"
|
"zdomain12.gov,Ready,2024-04-02,(blank),Interstate,,,,, ,,(blank),meoward@rocks.com,\n"
|
||||||
)
|
)
|
||||||
|
@ -302,7 +302,7 @@ class ExportDataTest(MockDbForIndividualTests, MockEppLib):
|
||||||
"Domain name,Status,First ready on,Expiration date,Domain type,Agency,Organization name,"
|
"Domain name,Status,First ready on,Expiration date,Domain type,Agency,Organization name,"
|
||||||
"City,State,SO,SO email,"
|
"City,State,SO,SO email,"
|
||||||
"Security contact email,Domain managers,Invited domain managers\n"
|
"Security contact email,Domain managers,Invited domain managers\n"
|
||||||
"defaultsecurity.gov,Ready,2023-11-01,(blank),Federal - Executive,190,,,, ,,(blank),"
|
"defaultsecurity.gov,Ready,2023-11-01,(blank),Federal - Executive,WorldWarICentennialCommission,,,, ,,(blank),"
|
||||||
'"big_lebowski@dude.co, info@example.com, meoward@rocks.com",woofwardthethird@rocks.com\n'
|
'"big_lebowski@dude.co, info@example.com, meoward@rocks.com",woofwardthethird@rocks.com\n'
|
||||||
"adomain2.gov,Dns needed,(blank),(blank),Interstate,,,,, ,,(blank),"
|
"adomain2.gov,Dns needed,(blank),(blank),Interstate,,,,, ,,(blank),"
|
||||||
'"info@example.com, meoward@rocks.com",squeaker@rocks.com\n'
|
'"info@example.com, meoward@rocks.com",squeaker@rocks.com\n'
|
||||||
|
@ -481,10 +481,10 @@ class ExportDataTest(MockDbForIndividualTests, MockEppLib):
|
||||||
# sorted alphabetially by domain name
|
# sorted alphabetially by domain name
|
||||||
expected_content = (
|
expected_content = (
|
||||||
"Domain name,Domain type,Agency,Organization name,City,State,Security contact email\n"
|
"Domain name,Domain type,Agency,Organization name,City,State,Security contact email\n"
|
||||||
"cdomain11.gov,Federal - Executive,186,,,,(blank)\n"
|
"cdomain11.gov,Federal - Executive,WorldWarICentennialCommission,,,,(blank)\n"
|
||||||
"defaultsecurity.gov,Federal - Executive,186,,,,(blank)\n"
|
"defaultsecurity.gov,Federal - Executive,WorldWarICentennialCommission,,,,(blank)\n"
|
||||||
"adomain10.gov,Federal,187,,,,(blank)\n"
|
"adomain10.gov,Federal,WorldWarICentennialCommission,,,,(blank)\n"
|
||||||
"ddomain3.gov,Federal,187,,,,security@mail.gov\n"
|
"ddomain3.gov,Federal,WorldWarICentennialCommission,,,,security@mail.gov\n"
|
||||||
"zdomain12.gov,Interstate,,,,,(blank)\n"
|
"zdomain12.gov,Interstate,,,,,(blank)\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -524,8 +524,8 @@ class ExportDataTest(MockDbForIndividualTests, MockEppLib):
|
||||||
"Domain name,Domain type,Agency,Organization name,City,State,Security contact email\n"
|
"Domain name,Domain type,Agency,Organization name,City,State,Security contact email\n"
|
||||||
"cdomain11.gov,Federal - Executive,184,,,,(blank)\n"
|
"cdomain11.gov,Federal - Executive,184,,,,(blank)\n"
|
||||||
"defaultsecurity.gov,Federal - Executive,184,,,,(blank)\n"
|
"defaultsecurity.gov,Federal - Executive,184,,,,(blank)\n"
|
||||||
"adomain10.gov,Federal,185,,,,(blank)\n"
|
"adomain10.gov,Federal,WorldWarICentennialCommission,,,,(blank)\n"
|
||||||
"ddomain3.gov,Federal,185,,,,security@mail.gov\n"
|
"ddomain3.gov,Federal,WorldWarICentennialCommission,,,,security@mail.gov\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Normalize line endings and remove commas,
|
# Normalize line endings and remove commas,
|
||||||
|
|
|
@ -302,16 +302,31 @@ class DomainExport(BaseExport):
|
||||||
"""
|
"""
|
||||||
Get a dict of computed fields.
|
Get a dict of computed fields.
|
||||||
"""
|
"""
|
||||||
# NOTE: These computed fields imitate @Property functions in the Domain model where needed.
|
# NOTE: These computed fields imitate @Property functions in the Domain model and Portfolio model where needed.
|
||||||
# This is for performance purposes. Since we are working with dictionary values and not
|
# This is for performance purposes. Since we are working with dictionary values and not
|
||||||
# model objects as we export data, trying to reinstate model objects in order to grab @property
|
# model objects as we export data, trying to reinstate model objects in order to grab @property
|
||||||
# values negatively impacts performance. Therefore, we will follow best practice and use annotations
|
# values negatively impacts performance. Therefore, we will follow best practice and use annotations
|
||||||
return {
|
return {
|
||||||
|
"converted_generic_org_type": Case(
|
||||||
|
# When portfolio is present, use its value instead
|
||||||
|
When(portfolio__isnull=False, then=F("portfolio__organization_type")),
|
||||||
|
# Otherwise, return the natively assigned value
|
||||||
|
default=F("organization_type"),
|
||||||
|
output_field=CharField(),
|
||||||
|
),
|
||||||
"converted_federal_agency": Case(
|
"converted_federal_agency": Case(
|
||||||
# When portfolio is present, use its value instead
|
# When portfolio is present, use its value instead
|
||||||
When(portfolio__isnull=False, then=F("portfolio__federal_agency")),
|
When(portfolio__isnull=False, then=F("portfolio__federal_agency__agency")),
|
||||||
# Otherwise, return the natively assigned value
|
# Otherwise, return the natively assigned value
|
||||||
default=F("federal_agency"),
|
default=F("federal_agency__agency"),
|
||||||
|
output_field=CharField(),
|
||||||
|
),
|
||||||
|
"converted_federal_type": Case(
|
||||||
|
# When portfolio is present, use its value instead
|
||||||
|
# NOTE: this is an @Property funciton in portfolio.
|
||||||
|
When(Q(portfolio__isnull=False) & Q(portfolio__federal_agency__isnull=False), then=F("portfolio__federal_agency__federal_type")),
|
||||||
|
# Otherwise, return the natively assigned value
|
||||||
|
default=F("federal_type"),
|
||||||
output_field=CharField(),
|
output_field=CharField(),
|
||||||
),
|
),
|
||||||
"converted_organization_name": Case(
|
"converted_organization_name": Case(
|
||||||
|
@ -475,9 +490,9 @@ class DomainExport(BaseExport):
|
||||||
first_ready_on = "(blank)"
|
first_ready_on = "(blank)"
|
||||||
|
|
||||||
# organization_type has organization_type AND is_election
|
# organization_type has organization_type AND is_election
|
||||||
domain_org_type = model.get("converted_generic_org_type") or model.get("organization_type")
|
domain_org_type = model.get("converted_generic_org_type")
|
||||||
human_readable_domain_org_type = DomainRequest.OrgChoicesElectionOffice.get_org_label(domain_org_type)
|
human_readable_domain_org_type = DomainRequest.OrgChoicesElectionOffice.get_org_label(domain_org_type)
|
||||||
domain_federal_type = model.get("federal_type")
|
domain_federal_type = model.get("converted_federal_type")
|
||||||
human_readable_domain_federal_type = BranchChoices.get_branch_label(domain_federal_type)
|
human_readable_domain_federal_type = BranchChoices.get_branch_label(domain_federal_type)
|
||||||
domain_type = human_readable_domain_org_type
|
domain_type = human_readable_domain_org_type
|
||||||
if domain_federal_type and domain_org_type == DomainRequest.OrgChoicesElectionOffice.FEDERAL:
|
if domain_federal_type and domain_org_type == DomainRequest.OrgChoicesElectionOffice.FEDERAL:
|
||||||
|
@ -624,6 +639,14 @@ class DomainDataType(DomainExport):
|
||||||
"Invited domain managers",
|
"Invited domain managers",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_annotations_for_sort(cls, delimiter=", "):
|
||||||
|
"""
|
||||||
|
Get a dict of annotations to make available for sorting.
|
||||||
|
"""
|
||||||
|
return cls.get_computed_fields()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_sort_fields(cls):
|
def get_sort_fields(cls):
|
||||||
"""
|
"""
|
||||||
|
@ -631,9 +654,9 @@ class DomainDataType(DomainExport):
|
||||||
"""
|
"""
|
||||||
# Coalesce is used to replace federal_type of None with ZZZZZ
|
# Coalesce is used to replace federal_type of None with ZZZZZ
|
||||||
return [
|
return [
|
||||||
"organization_type",
|
"converted_generic_org_type",
|
||||||
Coalesce("federal_type", Value("ZZZZZ")),
|
Coalesce("converted_federal_type", Value("ZZZZZ")),
|
||||||
"federal_agency",
|
"converted_federal_agency",
|
||||||
"domain__name",
|
"domain__name",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -779,7 +802,7 @@ class DomainRequestsDataType:
|
||||||
cls.safe_get(getattr(request, "region_field", None)),
|
cls.safe_get(getattr(request, "region_field", None)),
|
||||||
request.status,
|
request.status,
|
||||||
cls.safe_get(getattr(request, "election_office", None)),
|
cls.safe_get(getattr(request, "election_office", None)),
|
||||||
request.federal_type,
|
request.converted_federal_type,
|
||||||
cls.safe_get(getattr(request, "domain_type", None)),
|
cls.safe_get(getattr(request, "domain_type", None)),
|
||||||
cls.safe_get(getattr(request, "additional_details", None)),
|
cls.safe_get(getattr(request, "additional_details", None)),
|
||||||
cls.safe_get(getattr(request, "creator_approved_domains_count", None)),
|
cls.safe_get(getattr(request, "creator_approved_domains_count", None)),
|
||||||
|
@ -830,6 +853,13 @@ class DomainDataFull(DomainExport):
|
||||||
"Security contact email",
|
"Security contact email",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_annotations_for_sort(cls, delimiter=", "):
|
||||||
|
"""
|
||||||
|
Get a dict of annotations to make available for sorting.
|
||||||
|
"""
|
||||||
|
return cls.get_computed_fields()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_sort_fields(cls):
|
def get_sort_fields(cls):
|
||||||
"""
|
"""
|
||||||
|
@ -837,9 +867,9 @@ class DomainDataFull(DomainExport):
|
||||||
"""
|
"""
|
||||||
# Coalesce is used to replace federal_type of None with ZZZZZ
|
# Coalesce is used to replace federal_type of None with ZZZZZ
|
||||||
return [
|
return [
|
||||||
"organization_type",
|
"converted_generic_org_type",
|
||||||
Coalesce("federal_type", Value("ZZZZZ")),
|
Coalesce("converted_federal_type", Value("ZZZZZ")),
|
||||||
"federal_agency",
|
"converted_federal_agency",
|
||||||
"domain__name",
|
"domain__name",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -910,6 +940,14 @@ class DomainDataFederal(DomainExport):
|
||||||
"Security contact email",
|
"Security contact email",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_annotations_for_sort(cls, delimiter=", "):
|
||||||
|
"""
|
||||||
|
Get a dict of annotations to make available for sorting.
|
||||||
|
"""
|
||||||
|
return cls.get_computed_fields()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_sort_fields(cls):
|
def get_sort_fields(cls):
|
||||||
"""
|
"""
|
||||||
|
@ -917,9 +955,9 @@ class DomainDataFederal(DomainExport):
|
||||||
"""
|
"""
|
||||||
# Coalesce is used to replace federal_type of None with ZZZZZ
|
# Coalesce is used to replace federal_type of None with ZZZZZ
|
||||||
return [
|
return [
|
||||||
"organization_type",
|
"converted_generic_org_type",
|
||||||
Coalesce("federal_type", Value("ZZZZZ")),
|
Coalesce("converted_federal_type", Value("ZZZZZ")),
|
||||||
"federal_agency",
|
"converted_federal_agency",
|
||||||
"domain__name",
|
"domain__name",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1340,16 +1378,31 @@ class DomainRequestExport(BaseExport):
|
||||||
"""
|
"""
|
||||||
Get a dict of computed fields.
|
Get a dict of computed fields.
|
||||||
"""
|
"""
|
||||||
# NOTE: These computed fields imitate @Property functions in the Domain model where needed.
|
# NOTE: These computed fields imitate @Property functions in the Domain model and Portfolio model where needed.
|
||||||
# This is for performance purposes. Since we are working with dictionary values and not
|
# This is for performance purposes. Since we are working with dictionary values and not
|
||||||
# model objects as we export data, trying to reinstate model objects in order to grab @property
|
# model objects as we export data, trying to reinstate model objects in order to grab @property
|
||||||
# values negatively impacts performance. Therefore, we will follow best practice and use annotations
|
# values negatively impacts performance. Therefore, we will follow best practice and use annotations
|
||||||
return {
|
return {
|
||||||
|
"converted_generic_org_type": Case(
|
||||||
|
# When portfolio is present, use its value instead
|
||||||
|
When(portfolio__isnull=False, then=F("portfolio__organization_type")),
|
||||||
|
# Otherwise, return the natively assigned value
|
||||||
|
default=F("organization_type"),
|
||||||
|
output_field=CharField(),
|
||||||
|
),
|
||||||
"converted_federal_agency": Case(
|
"converted_federal_agency": Case(
|
||||||
# When portfolio is present, use its value instead
|
# When portfolio is present, use its value instead
|
||||||
When(portfolio__isnull=False, then=F("portfolio__federal_agency")),
|
When(portfolio__isnull=False, then=F("portfolio__federal_agency__agency")),
|
||||||
# Otherwise, return the natively assigned value
|
# Otherwise, return the natively assigned value
|
||||||
default=F("federal_agency"),
|
default=F("federal_agency__agency"),
|
||||||
|
output_field=CharField(),
|
||||||
|
),
|
||||||
|
"converted_federal_type": Case(
|
||||||
|
# When portfolio is present, use its value instead
|
||||||
|
# NOTE: this is an @Property funciton in portfolio.
|
||||||
|
When(Q(portfolio__isnull=False) & Q(portfolio__federal_agency__isnull=False), then=F("portfolio__federal_agency__federal_type")),
|
||||||
|
# Otherwise, return the natively assigned value
|
||||||
|
default=F("federal_type"),
|
||||||
output_field=CharField(),
|
output_field=CharField(),
|
||||||
),
|
),
|
||||||
"converted_organization_name": Case(
|
"converted_organization_name": Case(
|
||||||
|
@ -1488,11 +1541,11 @@ class DomainRequestExport(BaseExport):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Handle the federal_type field. Defaults to the wrong format.
|
# Handle the federal_type field. Defaults to the wrong format.
|
||||||
federal_type = model.get("federal_type")
|
federal_type = model.get("converted_federal_type")
|
||||||
human_readable_federal_type = BranchChoices.get_branch_label(federal_type) if federal_type else None
|
human_readable_federal_type = BranchChoices.get_branch_label(federal_type) if federal_type else None
|
||||||
|
|
||||||
# Handle the org_type field
|
# Handle the org_type field
|
||||||
org_type = model.get("converted_generic_org_type") or model.get("organization_type")
|
org_type = model.get("converted_generic_org_type")
|
||||||
human_readable_org_type = DomainRequest.OrganizationChoices.get_org_label(org_type) if org_type else None
|
human_readable_org_type = DomainRequest.OrganizationChoices.get_org_label(org_type) if org_type else None
|
||||||
|
|
||||||
# Handle the status field. Defaults to the wrong format.
|
# Handle the status field. Defaults to the wrong format.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue