mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-16 17:47:02 +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"
|
||||
readonly_fields = ["state"]
|
||||
|
||||
# TODO file names and function names specific to report type
|
||||
def export_data_type(self, request):
|
||||
# match the CSV example with all the fields
|
||||
response = HttpResponse(content_type='text/csv')
|
||||
|
|
|
@ -3,11 +3,40 @@ from registrar.models.domain import Domain
|
|||
from registrar.models.domain_information import DomainInformation
|
||||
from registrar.models.public_contact import PublicContact
|
||||
|
||||
# TODO pass sort order and filter as arguments rather than domains
|
||||
def export_domains_to_writer(writer, domains, columns):
|
||||
# write columns headers to writer
|
||||
writer.writerow(columns)
|
||||
|
||||
for domain in Domain.objects.all().order_by('name'):
|
||||
domain_information, _ = DomainInformation.objects.get_or_create(domain=domain)
|
||||
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(
|
||||
[FIELDS.get(column,'') for column in columns]
|
||||
)
|
||||
|
||||
def export_data_type_to_csv(csv_file):
|
||||
writer = csv.writer(csv_file)
|
||||
# Write your data to the CSV here
|
||||
writer.writerow(
|
||||
[
|
||||
# define columns to include in export
|
||||
columns = [
|
||||
'Domain name',
|
||||
'Domain type',
|
||||
'Federal agency',
|
||||
|
@ -24,45 +53,41 @@ def export_data_type_to_csv(csv_file):
|
|||
'Status',
|
||||
# 'Expiration Date'
|
||||
]
|
||||
) # Include the appropriate headers
|
||||
# Loop through and write your data rows
|
||||
for domain in Domain.objects.all().order_by('name'):
|
||||
domain_information, _ = DomainInformation.objects.get_or_create(domain=domain)
|
||||
security_contacts = domain.contacts.filter(contact_type=PublicContact.ContactTypeChoices.SECURITY)
|
||||
|
||||
writer.writerow(
|
||||
[
|
||||
domain.name,
|
||||
domain_information.federal_type,
|
||||
domain_information.federal_agency,
|
||||
domain_information.organization_name,
|
||||
domain_information.city,
|
||||
domain_information.state_territory,
|
||||
domain_information.authorizing_official.first_name + " " + domain_information.authorizing_official.last_name,
|
||||
domain_information.authorizing_official.email,
|
||||
domain_information.submitter.first_name + " " + domain_information.submitter.last_name,
|
||||
domain_information.submitter.title,
|
||||
domain_information.submitter.email,
|
||||
domain_information.submitter.phone,
|
||||
security_contacts[0].email if security_contacts.exists() else " ",
|
||||
# domain.contacts.all().filter(contact_type=PublicContact.ContactTypeChoices.SECURITY)[0].email if len(domain.contacts.all().filter(contact_type=PublicContact.ContactTypeChoices.SECURITY)) else " ",
|
||||
domain.state,
|
||||
# domain.expiration_date,
|
||||
]
|
||||
) # Include the appropriate fields
|
||||
# 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):
|
||||
writer = csv.writer(csv_file)
|
||||
# Write your data to the CSV here
|
||||
writer.writerow(['Name', 'State', ...]) # Include the appropriate headers
|
||||
# Loop through and write your data rows
|
||||
for data_row in Domain.objects.all():
|
||||
writer.writerow([data_row.name, data_row.state, ...]) # Include the appropriate fields
|
||||
# define columns to include in export
|
||||
columns = [
|
||||
'Domain name',
|
||||
'Domain type',
|
||||
'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):
|
||||
writer = csv.writer(csv_file)
|
||||
# Write your data to the CSV here
|
||||
writer.writerow(['Name', 'State', ...]) # Include the appropriate headers
|
||||
# Loop through and write your data rows
|
||||
for data_row in Domain.objects.all():
|
||||
writer.writerow([data_row.name, data_row.state, ...]) # Include the appropriate fields
|
||||
# define columns to include in export
|
||||
columns = [
|
||||
'Domain name',
|
||||
'Domain type',
|
||||
'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