This commit is contained in:
CocoByte 2024-11-24 23:42:42 -07:00
parent ca8cfda03d
commit 34ba850277
No known key found for this signature in database
GPG key ID: BBFAA2526384C97F
7 changed files with 263 additions and 189 deletions

View file

@ -1,11 +1,10 @@
import csv
from datetime import date
import logging
import copy
from django import forms
from django.db.models import Value, CharField, Q
from django.db.models.functions import Concat, Coalesce
from django.http import HttpResponse, HttpResponseRedirect
from django.http import HttpResponseRedirect
from registrar.models.federal_agency import FederalAgency
from registrar.utility.admin_helpers import (
get_action_needed_reason_default_email,
@ -1457,17 +1456,17 @@ class DomainInformationResource(resources.ModelResource):
# Override exports for these columns in DomainInformation to use converted values. These values
# come from @Property functions, which are not automatically included in the export and which we
# want to use in place of the native fields.
organization_name = fields.Field(attribute='converted_organization_name', column_name='organization_name')
generic_org_type = fields.Field(attribute='converted_generic_org_type', column_name='generic_org_type')
federal_type = fields.Field(attribute='converted_federal_type', column_name='federal_type')
federal_agency = fields.Field(attribute='converted_federal_agency', column_name='federal_agency')
senior_official = fields.Field(attribute='converted_senior_official', column_name='senior_official')
address_line1 = fields.Field(attribute='converted_address_line1', column_name='address_line1')
address_line2 = fields.Field(attribute='converted_address_line2', column_name='address_line2')
city = fields.Field(attribute='converted_city', column_name='city')
state_territory = fields.Field(attribute='converted_state_territory', column_name='state_territory')
zipcode = fields.Field(attribute='converted_zipcode', column_name='zipcode')
urbanization = fields.Field(attribute='converted_urbanization', column_name='urbanization')
organization_name = fields.Field(attribute="converted_organization_name", column_name="organization_name")
generic_org_type = fields.Field(attribute="converted_generic_org_type", column_name="generic_org_type")
federal_type = fields.Field(attribute="converted_federal_type", column_name="federal_type")
federal_agency = fields.Field(attribute="converted_federal_agency", column_name="federal_agency")
senior_official = fields.Field(attribute="converted_senior_official", column_name="senior_official")
address_line1 = fields.Field(attribute="converted_address_line1", column_name="address_line1")
address_line2 = fields.Field(attribute="converted_address_line2", column_name="address_line2")
city = fields.Field(attribute="converted_city", column_name="city")
state_territory = fields.Field(attribute="converted_state_territory", column_name="state_territory")
zipcode = fields.Field(attribute="converted_zipcode", column_name="zipcode")
urbanization = fields.Field(attribute="converted_urbanization", column_name="urbanization")
# Custom getters for the above columns that map to @property functions instead of fields
def dehydrate_organization_name(self, obj):
@ -1504,8 +1503,6 @@ class DomainInformationResource(resources.ModelResource):
return obj.converted_urbanization
class DomainInformationAdmin(ListHeaderAdmin, ImportExportModelAdmin):
"""Customize domain information admin class."""
@ -1515,7 +1512,7 @@ class DomainInformationAdmin(ListHeaderAdmin, ImportExportModelAdmin):
organization in the Domain Information object."""
title = "generic organization"
parameter_name = 'converted_generic_orgs'
parameter_name = "converted_generic_orgs"
def lookups(self, request, model_admin):
converted_generic_orgs = set()
@ -1533,7 +1530,10 @@ class DomainInformationAdmin(ListHeaderAdmin, ImportExportModelAdmin):
return queryset.filter(
# Filter based on the generic org value returned by converted_generic_org_type
id__in=[
domainInfo.id for domainInfo in queryset if domainInfo.converted_generic_org_type and domainInfo.converted_generic_org_type == self.value()
domainInfo.id
for domainInfo in queryset
if domainInfo.converted_generic_org_type
and domainInfo.converted_generic_org_type == self.value()
]
)
return queryset
@ -1709,18 +1709,18 @@ class DomainRequestResource(FsmModelResource):
# Override exports for these columns in DomainInformation to use converted values. These values
# come from @Property functions, which are not automatically included in the export and which we
# want to use in place of the native fields.
organization_name = fields.Field(attribute='converted_organization_name', column_name='organization_name')
generic_org_type = fields.Field(attribute='converted_generic_org_type', column_name='generic_org_type')
federal_type = fields.Field(attribute='converted_federal_type', column_name='federal_type')
federal_agency = fields.Field(attribute='converted_federal_agency', column_name='federal_agency')
senior_official = fields.Field(attribute='converted_senior_official', column_name='senior_official')
address_line1 = fields.Field(attribute='converted_address_line1', column_name='address_line1')
address_line2 = fields.Field(attribute='converted_address_line2', column_name='address_line2')
city = fields.Field(attribute='converted_city', column_name='city')
state_territory = fields.Field(attribute='converted_state_territory', column_name='state_territory')
zipcode = fields.Field(attribute='converted_zipcode', column_name='zipcode')
urbanization = fields.Field(attribute='converted_urbanization', column_name='urbanization')
senior_official = fields.Field(attribute='converted_urbanization', column_name='senior official')
organization_name = fields.Field(attribute="converted_organization_name", column_name="organization_name")
generic_org_type = fields.Field(attribute="converted_generic_org_type", column_name="generic_org_type")
federal_type = fields.Field(attribute="converted_federal_type", column_name="federal_type")
federal_agency = fields.Field(attribute="converted_federal_agency", column_name="federal_agency")
senior_official = fields.Field(attribute="converted_senior_official", column_name="senior_official")
address_line1 = fields.Field(attribute="converted_address_line1", column_name="address_line1")
address_line2 = fields.Field(attribute="converted_address_line2", column_name="address_line2")
city = fields.Field(attribute="converted_city", column_name="city")
state_territory = fields.Field(attribute="converted_state_territory", column_name="state_territory")
zipcode = fields.Field(attribute="converted_zipcode", column_name="zipcode")
urbanization = fields.Field(attribute="converted_urbanization", column_name="urbanization")
senior_official = fields.Field(attribute="converted_urbanization", column_name="senior official")
# Custom getters for the above columns that map to @property functions instead of fields
def dehydrate_organization_name(self, obj):
@ -2698,11 +2698,11 @@ class DomainResource(FsmModelResource):
)
# Custom getters to retrieve the values from @Proprerty methods in DomainInfo
converted_generic_org_type = fields.Field(attribute='converted_generic_org_type', column_name='generic org type')
converted_federal_agency = fields.Field(attribute='converted_federal_agency', column_name='federal agency')
converted_organization_name = fields.Field(attribute='converted_organization_name', column_name='organization name')
converted_city = fields.Field(attribute='converted_city', column_name='city')
converted_state_territory = fields.Field(attribute='converted_state_territory', column_name='state territory')
converted_generic_org_type = fields.Field(attribute="converted_generic_org_type", column_name="generic org type")
converted_federal_agency = fields.Field(attribute="converted_federal_agency", column_name="federal agency")
converted_organization_name = fields.Field(attribute="converted_organization_name", column_name="organization name")
converted_city = fields.Field(attribute="converted_city", column_name="city")
converted_state_territory = fields.Field(attribute="converted_state_territory", column_name="state territory")
def dehydrate_converted_generic_org_type(self, obj):
return obj.domain_info.converted_generic_org_type
@ -2719,6 +2719,7 @@ class DomainResource(FsmModelResource):
def dehydrate_converted_state_territory(self, obj):
return obj.domain_info.converted_state_territory
class DomainAdmin(ListHeaderAdmin, ImportExportModelAdmin):
"""Custom domain admin class to add extra buttons."""
@ -2749,7 +2750,7 @@ class DomainAdmin(ListHeaderAdmin, ImportExportModelAdmin):
organization in the Domain Information object."""
title = "generic organization"
parameter_name = 'converted_generic_orgs'
parameter_name = "converted_generic_orgs"
def lookups(self, request, model_admin):
converted_generic_orgs = set()
@ -2767,7 +2768,10 @@ class DomainAdmin(ListHeaderAdmin, ImportExportModelAdmin):
return queryset.filter(
# Filter based on the generic org value returned by converted_generic_org_type
id__in=[
domain.id for domain in queryset if domain.domain_info.converted_generic_org_type and domain.domain_info.converted_generic_org_type == self.value()
domain.id
for domain in queryset
if domain.domain_info.converted_generic_org_type
and domain.domain_info.converted_generic_org_type == self.value()
]
)
return queryset
@ -2778,7 +2782,7 @@ class DomainAdmin(ListHeaderAdmin, ImportExportModelAdmin):
federal type in the Domain Information object."""
title = "federal type"
parameter_name = 'converted_federal_types'
parameter_name = "converted_federal_types"
def lookups(self, request, model_admin):
converted_federal_types = set()
@ -2797,12 +2801,14 @@ class DomainAdmin(ListHeaderAdmin, ImportExportModelAdmin):
return queryset.filter(
# Filter based on the generic org value returned by converted_generic_org_type
id__in=[
domain.id for domain in queryset if domain.domain_info.converted_federal_type and domain.domain_info.converted_federal_type == self.value()
domain.id
for domain in queryset
if domain.domain_info.converted_federal_type
and domain.domain_info.converted_federal_type == self.value()
]
)
return queryset
def get_queryset(self, request):
"""Custom get_queryset to filter by portfolio if portfolio is in the
request params."""
@ -2853,6 +2859,7 @@ class DomainAdmin(ListHeaderAdmin, ImportExportModelAdmin):
@admin.display(description=_("Generic Org Type"))
def converted_generic_org_type(self, obj):
return obj.domain_info.converted_generic_org_type
converted_generic_org_type.admin_order_field = "domain_info__converted_generic_org_type" # type: ignore
# Use native value for the change form
@ -2863,6 +2870,7 @@ class DomainAdmin(ListHeaderAdmin, ImportExportModelAdmin):
@admin.display(description=_("Federal Agency"))
def converted_federal_agency(self, obj):
return obj.domain_info.converted_federal_agency
converted_federal_agency.admin_order_field = "domain_info__converted_federal_agency" # type: ignore
# Use native value for the change form
@ -2877,6 +2885,7 @@ class DomainAdmin(ListHeaderAdmin, ImportExportModelAdmin):
@admin.display(description=_("Federal Type"))
def converted_federal_type(self, obj):
return obj.domain_info.converted_federal_type
converted_federal_type.admin_order_field = "domain_info__converted_federal_type" # type: ignore
# Use native value for the change form
@ -2888,6 +2897,7 @@ class DomainAdmin(ListHeaderAdmin, ImportExportModelAdmin):
@admin.display(description=_("Organization Name"))
def converted_organization_name(self, obj):
return obj.domain_info.converted_organization_name
converted_organization_name.admin_order_field = "domain_info__converted_organization_name" # type: ignore
# Use native value for the change form
@ -2899,6 +2909,7 @@ class DomainAdmin(ListHeaderAdmin, ImportExportModelAdmin):
@admin.display(description=_("City"))
def converted_city(self, obj):
return obj.domain_info.converted_city
converted_city.admin_order_field = "domain_info__converted_city" # type: ignore
# Use native value for the change form
@ -2910,13 +2921,13 @@ class DomainAdmin(ListHeaderAdmin, ImportExportModelAdmin):
@admin.display(description=_("State / territory"))
def converted_state_territory(self, obj):
return obj.domain_info.converted_state_territory
converted_state_territory.admin_order_field = "domain_info__converted_state_territory" # type: ignore
# Use native value for the change form
def state_territory(self, obj):
return obj.domain_info.state_territory if obj.domain_info else None
def dnssecdata(self, obj):
return "Yes" if obj.dnssecdata else "No"
@ -2948,7 +2959,6 @@ class DomainAdmin(ListHeaderAdmin, ImportExportModelAdmin):
custom_election_board.admin_order_field = "domain_info__is_election_board" # type: ignore
custom_election_board.short_description = "Election office" # type: ignore
# Search
search_fields = ["name"]
search_help_text = "Search by domain name."

View file

@ -493,5 +493,3 @@ class DomainInformation(TimeStampedModel):
if self.portfolio:
return self.portfolio.urbanization
return self.urbanization

View file

@ -63,10 +63,10 @@ class CsvReportsTest(MockDbForSharedTests):
fake_open = mock_open()
expected_file_content = [
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('cdomain1.gov,Federal - Executive,183,,,,(blank)\r\n'),
call('adomain10.gov,Federal,8,,,,(blank)\r\n'),
call('ddomain3.gov,Federal,8,,,,(blank)\r\n'),
call("cdomain11.gov,Federal - Executive,183,,,,(blank)\r\n"),
call("cdomain1.gov,Federal - Executive,183,,,,(blank)\r\n"),
call("adomain10.gov,Federal,8,,,,(blank)\r\n"),
call("ddomain3.gov,Federal,8,,,,(blank)\r\n"),
]
# We don't actually want to write anything for a test case,
# we just want to verify what is being written.
@ -85,11 +85,11 @@ class CsvReportsTest(MockDbForSharedTests):
fake_open = mock_open()
expected_file_content = [
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('cdomain1.gov,Federal - Executive,183,,,,(blank)\r\n'),
call('adomain10.gov,Federal,8,,,,(blank)\r\n'),
call('ddomain3.gov,Federal,8,,,,(blank)\r\n'),
call('zdomain12.gov,Interstate,,,,,(blank)\r\n'),
call("cdomain11.gov,Federal - Executive,183,,,,(blank)\r\n"),
call("cdomain1.gov,Federal - Executive,183,,,,(blank)\r\n"),
call("adomain10.gov,Federal,8,,,,(blank)\r\n"),
call("ddomain3.gov,Federal,8,,,,(blank)\r\n"),
call("zdomain12.gov,Interstate,,,,,(blank)\r\n"),
]
# We don't actually want to write anything for a test case,
# we just want to verify what is being written.
@ -247,7 +247,7 @@ class ExportDataTest(MockDbForIndividualTests, MockEppLib):
"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"
"defaultsecurity.gov,Ready,2023-11-01,(blank),Federal - Executive,188,,,, ,,(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"
"bdomain4.gov,Unknown,(blank),(blank),Federal,189,,,, ,,(blank),,\n"
"bdomain5.gov,Deleted,(blank),(blank),Federal,189,,,, ,,(blank),,\n"
@ -303,9 +303,9 @@ class ExportDataTest(MockDbForIndividualTests, MockEppLib):
"City,State,SO,SO email,"
"Security contact email,Domain managers,Invited domain managers\n"
"defaultsecurity.gov,Ready,2023-11-01,(blank),Federal - Executive,190,,,, ,,(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),"
"\"info@example.com, meoward@rocks.com\",squeaker@rocks.com\n"
'"info@example.com, meoward@rocks.com",squeaker@rocks.com\n'
)
# Normalize line endings and remove commas,
@ -313,8 +313,6 @@ class ExportDataTest(MockDbForIndividualTests, MockEppLib):
csv_content = csv_content.replace(",,", "").replace(",", "").replace(" ", "").replace("\r\n", "\n").strip()
expected_content = expected_content.replace(",,", "").replace(",", "").replace(" ", "").strip()
self.maxDiff = None
self.assertEqual(csv_content, expected_content)

View file

@ -11,11 +11,21 @@ from registrar.models import (
PublicContact,
UserDomainRole,
)
from django.db.models import Case, CharField, Count, DateField, F, ManyToManyField, Q, QuerySet, Value, When, ExpressionWrapper
from django.db.models import (
Case,
CharField,
Count,
DateField,
F,
ManyToManyField,
Q,
QuerySet,
Value,
When,
)
from django.utils import timezone
from django.db.models.functions import Concat, Coalesce
from django.contrib.postgres.aggregates import StringAgg
from registrar.models.user import User
from registrar.models.utility.generic_helper import convert_queryset_to_dict
from registrar.templatetags.custom_filters import get_region
from registrar.utility.constants import BranchChoices
@ -355,12 +365,15 @@ class DomainExport(BaseExport):
),
"converted_so_name": Case(
# When portfolio is present, use that senior official instead
When(portfolio__isnull=False, then=Concat(
When(
portfolio__isnull=False,
then=Concat(
Coalesce(F("portfolio__senior_official__first_name"), Value("")),
Value(" "),
Coalesce(F("portfolio__senior_official__last_name"), Value("")),
output_field=CharField(),
)),
),
),
# Otherwise, return the natively assigned senior official
default=Concat(
Coalesce(F("senior_official__first_name"), Value("")),
@ -479,7 +492,6 @@ class DomainExport(BaseExport):
):
security_contact_email = "(blank)"
# create a dictionary of fields which can be included in output.
# "extra_fields" are precomputed fields (generated in the DB or parsed).
FIELDS = {
@ -510,7 +522,9 @@ class DomainExport(BaseExport):
return domain_infos_to_filter.filter(
# Filter based on the generic org value returned by converted_generic_org_type
id__in=[
domainInfos.id for domainInfos in domain_infos_to_filter if domainInfos.converted_generic_org_type and domainInfos.converted_generic_org_type == org_to_filter_by
domainInfos.id
for domainInfos in domain_infos_to_filter
if domainInfos.converted_generic_org_type and domainInfos.converted_generic_org_type == org_to_filter_by
]
)
@ -523,19 +537,47 @@ class DomainExport(BaseExport):
domain_informations = DomainInformation.objects.all().filter(**filter_condition).distinct()
domains_count = domain_informations.count()
federal = cls.get_filtered_domain_infos_by_org(domain_informations, DomainRequest.OrganizationChoices.FEDERAL).distinct().count()
interstate = cls.get_filtered_domain_infos_by_org(domain_informations, DomainRequest.OrganizationChoices.INTERSTATE).count()
state_or_territory = (
cls.get_filtered_domain_infos_by_org(domain_informations, DomainRequest.OrganizationChoices.STATE_OR_TERRITORY).distinct().count()
federal = (
cls.get_filtered_domain_infos_by_org(domain_informations, DomainRequest.OrganizationChoices.FEDERAL)
.distinct()
.count()
)
interstate = cls.get_filtered_domain_infos_by_org(
domain_informations, DomainRequest.OrganizationChoices.INTERSTATE
).count()
state_or_territory = (
cls.get_filtered_domain_infos_by_org(
domain_informations, DomainRequest.OrganizationChoices.STATE_OR_TERRITORY
)
.distinct()
.count()
)
tribal = (
cls.get_filtered_domain_infos_by_org(domain_informations, DomainRequest.OrganizationChoices.TRIBAL)
.distinct()
.count()
)
county = (
cls.get_filtered_domain_infos_by_org(domain_informations, DomainRequest.OrganizationChoices.COUNTY)
.distinct()
.count()
)
city = (
cls.get_filtered_domain_infos_by_org(domain_informations, DomainRequest.OrganizationChoices.CITY)
.distinct()
.count()
)
tribal = cls.get_filtered_domain_infos_by_org(domain_informations, DomainRequest.OrganizationChoices.TRIBAL).distinct().count()
county = cls.get_filtered_domain_infos_by_org(domain_informations, DomainRequest.OrganizationChoices.COUNTY).distinct().count()
city = cls.get_filtered_domain_infos_by_org(domain_informations, DomainRequest.OrganizationChoices.CITY).distinct().count()
special_district = (
cls.get_filtered_domain_infos_by_org(domain_informations, DomainRequest.OrganizationChoices.SPECIAL_DISTRICT).distinct().count()
cls.get_filtered_domain_infos_by_org(
domain_informations, DomainRequest.OrganizationChoices.SPECIAL_DISTRICT
)
.distinct()
.count()
)
school_district = (
cls.get_filtered_domain_infos_by_org(domain_informations, DomainRequest.OrganizationChoices.SCHOOL_DISTRICT).distinct().count()
cls.get_filtered_domain_infos_by_org(domain_informations, DomainRequest.OrganizationChoices.SCHOOL_DISTRICT)
.distinct()
.count()
)
election_board = domain_informations.filter(is_election_board=True).distinct().count()
@ -632,7 +674,6 @@ class DomainDataType(DomainExport):
"""
return ["permissions"]
@classmethod
def get_related_table_fields(cls):
"""
@ -1287,11 +1328,13 @@ class DomainRequestExport(BaseExport):
return domain_requests_to_filter.filter(
# Filter based on the generic org value returned by converted_generic_org_type
id__in=[
domainRequest.id for domainRequest in domain_requests_to_filter if domainRequest.converted_generic_org_type and domainRequest.converted_generic_org_type == org_to_filter_by
domainRequest.id
for domainRequest in domain_requests_to_filter
if domainRequest.converted_generic_org_type
and domainRequest.converted_generic_org_type == org_to_filter_by
]
)
@classmethod
def get_computed_fields(cls, delimiter=", "):
"""
@ -1360,12 +1403,15 @@ class DomainRequestExport(BaseExport):
),
"converted_so_name": Case(
# When portfolio is present, use that senior official instead
When(portfolio__isnull=False, then=Concat(
When(
portfolio__isnull=False,
then=Concat(
Coalesce(F("portfolio__senior_official__first_name"), Value("")),
Value(" "),
Coalesce(F("portfolio__senior_official__last_name"), Value("")),
output_field=CharField(),
)),
),
),
# Otherwise, return the natively assigned senior official
default=Concat(
Coalesce(F("senior_official__first_name"), Value("")),
@ -1382,19 +1428,43 @@ class DomainRequestExport(BaseExport):
"""Get filtered requests counts sliced by org type and election office."""
requests = DomainRequest.objects.all().filter(**filter_condition).distinct()
requests_count = requests.count()
federal = cls.get_filtered_domain_requests_by_org(requests, DomainRequest.OrganizationChoices.FEDERAL).distinct().count()
interstate = cls.get_filtered_domain_requests_by_org(requests, DomainRequest.OrganizationChoices.INTERSTATE).distinct().count()
state_or_territory = (
cls.get_filtered_domain_requests_by_org(requests, DomainRequest.OrganizationChoices.STATE_OR_TERRITORY).distinct().count()
federal = (
cls.get_filtered_domain_requests_by_org(requests, DomainRequest.OrganizationChoices.FEDERAL)
.distinct()
.count()
)
interstate = (
cls.get_filtered_domain_requests_by_org(requests, DomainRequest.OrganizationChoices.INTERSTATE)
.distinct()
.count()
)
state_or_territory = (
cls.get_filtered_domain_requests_by_org(requests, DomainRequest.OrganizationChoices.STATE_OR_TERRITORY)
.distinct()
.count()
)
tribal = (
cls.get_filtered_domain_requests_by_org(requests, DomainRequest.OrganizationChoices.TRIBAL)
.distinct()
.count()
)
county = (
cls.get_filtered_domain_requests_by_org(requests, DomainRequest.OrganizationChoices.COUNTY)
.distinct()
.count()
)
city = (
cls.get_filtered_domain_requests_by_org(requests, DomainRequest.OrganizationChoices.CITY).distinct().count()
)
tribal = cls.get_filtered_domain_requests_by_org(requests, DomainRequest.OrganizationChoices.TRIBAL).distinct().count()
county = cls.get_filtered_domain_requests_by_org(requests, DomainRequest.OrganizationChoices.COUNTY).distinct().count()
city = cls.get_filtered_domain_requests_by_org(requests, DomainRequest.OrganizationChoices.CITY).distinct().count()
special_district = (
cls.get_filtered_domain_requests_by_org(requests, DomainRequest.OrganizationChoices.SPECIAL_DISTRICT).distinct().count()
cls.get_filtered_domain_requests_by_org(requests, DomainRequest.OrganizationChoices.SPECIAL_DISTRICT)
.distinct()
.count()
)
school_district = (
cls.get_filtered_domain_requests_by_org(requests, DomainRequest.OrganizationChoices.SCHOOL_DISTRICT).distinct().count()
cls.get_filtered_domain_requests_by_org(requests, DomainRequest.OrganizationChoices.SCHOOL_DISTRICT)
.distinct()
.count()
)
election_board = requests.filter(is_election_board=True).distinct().count()
@ -1542,6 +1612,7 @@ class DomainRequestGrowth(DomainRequestExport):
"""
return ["requested_domain__name"]
class DomainRequestDataFull(DomainRequestExport):
"""
Shows all but STARTED requests
@ -1625,11 +1696,14 @@ class DomainRequestDataFull(DomainRequestExport):
computed_fields = super().get_computed_fields()
# Add additional computed fields
computed_fields.update({
computed_fields.update(
{
"creator_approved_domains_count": cls.get_creator_approved_domains_count_query(),
"creator_active_requests_count": cls.get_creator_active_requests_count_query(),
"all_current_websites": StringAgg("current_websites__website", delimiter=delimiter, distinct=True),
"all_alternative_domains": StringAgg("alternative_domains__website", delimiter=delimiter, distinct=True),
"all_alternative_domains": StringAgg(
"alternative_domains__website", delimiter=delimiter, distinct=True
),
# Coerce the other contacts object to "{first_name} {last_name} {email}"
"all_other_contacts": StringAgg(
Concat(
@ -1642,7 +1716,8 @@ class DomainRequestDataFull(DomainRequestExport):
delimiter=delimiter,
distinct=True,
),
})
}
)
return computed_fields

View file

@ -13,13 +13,9 @@ from registrar.utility import csv_export
import logging
# ---Logger
import logging
from venv import logger
from registrar.management.commands.utility.terminal_helper import TerminalColors, TerminalHelper
logger = logging.getLogger(__name__)
class AnalyticsView(View):
def get(self, request):
thirty_days_ago = datetime.datetime.today() - datetime.timedelta(days=30)
@ -165,10 +161,7 @@ class ExportDataType(View):
class ExportDataTypeUser(View):
"""Returns a domain report for a given user on the request"""
TerminalHelper.colorful_logger(logger.info, TerminalColors.OKGREEN, f"ExportDataTypeUser")
def get(self, request, *args, **kwargs):
TerminalHelper.colorful_logger(logger.info, TerminalColors.OKGREEN, f"ExportDataTypeUser -- get")
# match the CSV example with all the fields
response = HttpResponse(content_type="text/csv")
response["Content-Disposition"] = 'attachment; filename="your-domains.csv"'