mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-16 09:37:03 +02:00
modularization of reporting functions
This commit is contained in:
parent
e4b3706d9c
commit
0b947ce754
2 changed files with 78 additions and 52 deletions
|
@ -752,6 +752,7 @@ class DomainAdmin(ListHeaderAdmin):
|
||||||
change_list_template = "django/admin/domain_change_list.html"
|
change_list_template = "django/admin/domain_change_list.html"
|
||||||
readonly_fields = ["state"]
|
readonly_fields = ["state"]
|
||||||
|
|
||||||
|
# TODO file names and function names specific to report type
|
||||||
def export_data_type(self, request):
|
def export_data_type(self, request):
|
||||||
# match the CSV example with all the fields
|
# match the CSV example with all the fields
|
||||||
response = HttpResponse(content_type='text/csv')
|
response = HttpResponse(content_type='text/csv')
|
||||||
|
|
|
@ -3,66 +3,91 @@ from registrar.models.domain import Domain
|
||||||
from registrar.models.domain_information import DomainInformation
|
from registrar.models.domain_information import DomainInformation
|
||||||
from registrar.models.public_contact import PublicContact
|
from registrar.models.public_contact import PublicContact
|
||||||
|
|
||||||
def export_data_type_to_csv(csv_file):
|
# TODO pass sort order and filter as arguments rather than domains
|
||||||
writer = csv.writer(csv_file)
|
def export_domains_to_writer(writer, domains, columns):
|
||||||
# Write your data to the CSV here
|
# write columns headers to writer
|
||||||
writer.writerow(
|
writer.writerow(columns)
|
||||||
[
|
|
||||||
'Domain name',
|
|
||||||
'Domain type',
|
|
||||||
'Federal agency',
|
|
||||||
'Organization name',
|
|
||||||
'City',
|
|
||||||
'State',
|
|
||||||
'AO',
|
|
||||||
'AO email',
|
|
||||||
'Submitter',
|
|
||||||
'Submitter title',
|
|
||||||
'Submitter email',
|
|
||||||
'Submitter phone',
|
|
||||||
'Security Contact Email',
|
|
||||||
'Status',
|
|
||||||
# 'Expiration Date'
|
|
||||||
]
|
|
||||||
) # Include the appropriate headers
|
|
||||||
# Loop through and write your data rows
|
|
||||||
for domain in Domain.objects.all().order_by('name'):
|
for domain in Domain.objects.all().order_by('name'):
|
||||||
domain_information, _ = DomainInformation.objects.get_or_create(domain=domain)
|
domain_information, _ = DomainInformation.objects.get_or_create(domain=domain)
|
||||||
security_contacts = domain.contacts.filter(contact_type=PublicContact.ContactTypeChoices.SECURITY)
|
security_contacts = domain.contacts.filter(contact_type=PublicContact.ContactTypeChoices.SECURITY)
|
||||||
|
|
||||||
|
# create a dictionary of fields to include
|
||||||
|
FIELDS = {
|
||||||
|
'Domain name': domain.name,
|
||||||
|
'Domain type': domain_information.federal_type,
|
||||||
|
'Federal agency': domain_information.federal_agency,
|
||||||
|
'Organization name': domain_information.organization_name,
|
||||||
|
'City': domain_information.city,
|
||||||
|
'State': domain_information.state_territory,
|
||||||
|
'AO': domain_information.authorizing_official.first_name + " " + domain_information.authorizing_official.last_name,
|
||||||
|
'AO email': domain_information.authorizing_official.email,
|
||||||
|
'Submitter': domain_information.submitter.first_name + " " + domain_information.submitter.last_name,
|
||||||
|
'Submitter title': domain_information.submitter.title,
|
||||||
|
'Submitter email': domain_information.submitter.email,
|
||||||
|
'Submitter phone': domain_information.submitter.phone,
|
||||||
|
'Security Contact Email': security_contacts[0].email if security_contacts.exists() else " ",
|
||||||
|
'Status': domain.state,
|
||||||
|
}
|
||||||
writer.writerow(
|
writer.writerow(
|
||||||
[
|
[FIELDS.get(column,'') for column in columns]
|
||||||
domain.name,
|
)
|
||||||
domain_information.federal_type,
|
|
||||||
domain_information.federal_agency,
|
def export_data_type_to_csv(csv_file):
|
||||||
domain_information.organization_name,
|
writer = csv.writer(csv_file)
|
||||||
domain_information.city,
|
# define columns to include in export
|
||||||
domain_information.state_territory,
|
columns = [
|
||||||
domain_information.authorizing_official.first_name + " " + domain_information.authorizing_official.last_name,
|
'Domain name',
|
||||||
domain_information.authorizing_official.email,
|
'Domain type',
|
||||||
domain_information.submitter.first_name + " " + domain_information.submitter.last_name,
|
'Federal agency',
|
||||||
domain_information.submitter.title,
|
'Organization name',
|
||||||
domain_information.submitter.email,
|
'City',
|
||||||
domain_information.submitter.phone,
|
'State',
|
||||||
security_contacts[0].email if security_contacts.exists() else " ",
|
'AO',
|
||||||
# domain.contacts.all().filter(contact_type=PublicContact.ContactTypeChoices.SECURITY)[0].email if len(domain.contacts.all().filter(contact_type=PublicContact.ContactTypeChoices.SECURITY)) else " ",
|
'AO email',
|
||||||
domain.state,
|
'Submitter',
|
||||||
# domain.expiration_date,
|
'Submitter title',
|
||||||
]
|
'Submitter email',
|
||||||
) # Include the appropriate fields
|
'Submitter phone',
|
||||||
|
'Security Contact Email',
|
||||||
|
'Status',
|
||||||
|
# 'Expiration Date'
|
||||||
|
]
|
||||||
|
# define domains to be exported
|
||||||
|
domains = Domain.objects.all().order_by('name')
|
||||||
|
export_domains_to_writer(writer, domains, columns)
|
||||||
|
|
||||||
def export_data_full_to_csv(csv_file):
|
def export_data_full_to_csv(csv_file):
|
||||||
writer = csv.writer(csv_file)
|
writer = csv.writer(csv_file)
|
||||||
# Write your data to the CSV here
|
# define columns to include in export
|
||||||
writer.writerow(['Name', 'State', ...]) # Include the appropriate headers
|
columns = [
|
||||||
# Loop through and write your data rows
|
'Domain name',
|
||||||
for data_row in Domain.objects.all():
|
'Domain type',
|
||||||
writer.writerow([data_row.name, data_row.state, ...]) # Include the appropriate fields
|
'Federal agency',
|
||||||
|
'Organization name',
|
||||||
|
'City',
|
||||||
|
'State',
|
||||||
|
'Security Contact Email',
|
||||||
|
]
|
||||||
|
# define domains to be exported
|
||||||
|
# TODO order by fields in domain information
|
||||||
|
domains = Domain.objects.all().order_by('name')
|
||||||
|
export_domains_to_writer(writer, domains, columns)
|
||||||
|
|
||||||
def export_data_federal_to_csv(csv_file):
|
def export_data_federal_to_csv(csv_file):
|
||||||
writer = csv.writer(csv_file)
|
writer = csv.writer(csv_file)
|
||||||
# Write your data to the CSV here
|
# define columns to include in export
|
||||||
writer.writerow(['Name', 'State', ...]) # Include the appropriate headers
|
columns = [
|
||||||
# Loop through and write your data rows
|
'Domain name',
|
||||||
for data_row in Domain.objects.all():
|
'Domain type',
|
||||||
writer.writerow([data_row.name, data_row.state, ...]) # Include the appropriate fields
|
'Federal agency',
|
||||||
|
'Organization name',
|
||||||
|
'City',
|
||||||
|
'State',
|
||||||
|
'Security Contact Email',
|
||||||
|
]
|
||||||
|
# define domains to be exported
|
||||||
|
# TODO order by fields in domain information
|
||||||
|
# TODO filter by domain type
|
||||||
|
domains = Domain.objects.all().order_by('name')
|
||||||
|
export_domains_to_writer(writer, domains, columns)
|
Loading…
Add table
Add a link
Reference in a new issue