mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-16 09:37:03 +02:00
parameterize filters and sorts
This commit is contained in:
parent
0b947ce754
commit
47251d9edb
2 changed files with 30 additions and 36 deletions
|
@ -752,25 +752,24 @@ 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')
|
||||||
response['Content-Disposition'] = 'attachment; filename="data_export.csv"'
|
response['Content-Disposition'] = 'attachment; filename="domains-by-type.csv"'
|
||||||
csv_export.export_data_type_to_csv(response)
|
csv_export.export_data_type_to_csv(response)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def export_data_full(self, request):
|
def export_data_full(self, request):
|
||||||
# Smaller export based on 1
|
# Smaller export based on 1
|
||||||
response = HttpResponse(content_type='text/csv')
|
response = HttpResponse(content_type='text/csv')
|
||||||
response['Content-Disposition'] = 'attachment; filename="data_export.csv"'
|
response['Content-Disposition'] = 'attachment; filename="domains-current-full.csv"'
|
||||||
csv_export.export_data_full_to_csv(response)
|
csv_export.export_data_full_to_csv(response)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def export_data_federal(self, request):
|
def export_data_federal(self, request):
|
||||||
# Federal only
|
# Federal only
|
||||||
response = HttpResponse(content_type='text/csv')
|
response = HttpResponse(content_type='text/csv')
|
||||||
response['Content-Disposition'] = 'attachment; filename="data_export.csv"'
|
response['Content-Disposition'] = 'attachment; filename="domains-current-federal.csv"'
|
||||||
csv_export.export_data_federal_to_csv(response)
|
csv_export.export_data_federal_to_csv(response)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
|
@ -1,33 +1,31 @@
|
||||||
import csv
|
import csv
|
||||||
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
|
||||||
|
|
||||||
# TODO pass sort order and filter as arguments rather than domains
|
def export_domains_to_writer(writer, columns, sort_fields, filter_condition):
|
||||||
def export_domains_to_writer(writer, domains, columns):
|
|
||||||
# write columns headers to writer
|
# write columns headers to writer
|
||||||
writer.writerow(columns)
|
writer.writerow(columns)
|
||||||
|
|
||||||
for domain in Domain.objects.all().order_by('name'):
|
domainInfos = DomainInformation.objects.filter(**filter_condition).order_by(*sort_fields)
|
||||||
domain_information, _ = DomainInformation.objects.get_or_create(domain=domain)
|
for domainInfo in domainInfos:
|
||||||
security_contacts = domain.contacts.filter(contact_type=PublicContact.ContactTypeChoices.SECURITY)
|
security_contacts = domainInfo.domain.contacts.filter(contact_type=PublicContact.ContactTypeChoices.SECURITY)
|
||||||
|
|
||||||
# create a dictionary of fields to include
|
# create a dictionary of fields which can be included in output
|
||||||
FIELDS = {
|
FIELDS = {
|
||||||
'Domain name': domain.name,
|
'Domain name': domainInfo.domain.name,
|
||||||
'Domain type': domain_information.federal_type,
|
'Domain type': domainInfo.organization_type,
|
||||||
'Federal agency': domain_information.federal_agency,
|
'Federal agency': domainInfo.federal_agency,
|
||||||
'Organization name': domain_information.organization_name,
|
'Organization name': domainInfo.organization_name,
|
||||||
'City': domain_information.city,
|
'City': domainInfo.city,
|
||||||
'State': domain_information.state_territory,
|
'State': domainInfo.state_territory,
|
||||||
'AO': domain_information.authorizing_official.first_name + " " + domain_information.authorizing_official.last_name,
|
'AO': domainInfo.authorizing_official.first_name + " " + domainInfo.authorizing_official.last_name,
|
||||||
'AO email': domain_information.authorizing_official.email,
|
'AO email': domainInfo.authorizing_official.email,
|
||||||
'Submitter': domain_information.submitter.first_name + " " + domain_information.submitter.last_name,
|
'Submitter': domainInfo.submitter.first_name + " " + domainInfo.submitter.last_name,
|
||||||
'Submitter title': domain_information.submitter.title,
|
'Submitter title': domainInfo.submitter.title,
|
||||||
'Submitter email': domain_information.submitter.email,
|
'Submitter email': domainInfo.submitter.email,
|
||||||
'Submitter phone': domain_information.submitter.phone,
|
'Submitter phone': domainInfo.submitter.phone,
|
||||||
'Security Contact Email': security_contacts[0].email if security_contacts.exists() else " ",
|
'Security Contact Email': security_contacts[0].email if security_contacts.exists() else " ",
|
||||||
'Status': domain.state,
|
'Status': domainInfo.domain.state,
|
||||||
}
|
}
|
||||||
writer.writerow(
|
writer.writerow(
|
||||||
[FIELDS.get(column,'') for column in columns]
|
[FIELDS.get(column,'') for column in columns]
|
||||||
|
@ -53,9 +51,9 @@ def export_data_type_to_csv(csv_file):
|
||||||
'Status',
|
'Status',
|
||||||
# 'Expiration Date'
|
# 'Expiration Date'
|
||||||
]
|
]
|
||||||
# define domains to be exported
|
sort_fields = ['domain__name']
|
||||||
domains = Domain.objects.all().order_by('name')
|
filter_condition = {}
|
||||||
export_domains_to_writer(writer, domains, columns)
|
export_domains_to_writer(writer, columns, sort_fields, filter_condition)
|
||||||
|
|
||||||
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)
|
||||||
|
@ -69,10 +67,9 @@ def export_data_full_to_csv(csv_file):
|
||||||
'State',
|
'State',
|
||||||
'Security Contact Email',
|
'Security Contact Email',
|
||||||
]
|
]
|
||||||
# define domains to be exported
|
sort_fields = ['domain__name', 'federal_agency', 'organization_type']
|
||||||
# TODO order by fields in domain information
|
filter_condition = {}
|
||||||
domains = Domain.objects.all().order_by('name')
|
export_domains_to_writer(writer, columns, sort_fields, filter_condition)
|
||||||
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)
|
||||||
|
@ -86,8 +83,6 @@ def export_data_federal_to_csv(csv_file):
|
||||||
'State',
|
'State',
|
||||||
'Security Contact Email',
|
'Security Contact Email',
|
||||||
]
|
]
|
||||||
# define domains to be exported
|
sort_fields = ['domain__name', 'federal_agency', 'organization_type']
|
||||||
# TODO order by fields in domain information
|
filter_condition = {'organization_type__icontains': 'federal'}
|
||||||
# TODO filter by domain type
|
export_domains_to_writer(writer, columns, sort_fields, filter_condition)
|
||||||
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