mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-16 17:47:02 +02:00
formatting for readability
This commit is contained in:
parent
47251d9edb
commit
b72919a892
2 changed files with 93 additions and 65 deletions
|
@ -754,22 +754,26 @@ class DomainAdmin(ListHeaderAdmin):
|
||||||
|
|
||||||
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="domains-by-type.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="domains-current-full.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="domains-current-federal.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
|
||||||
|
|
||||||
|
@ -781,9 +785,21 @@ class DomainAdmin(ListHeaderAdmin):
|
||||||
info = self.model._meta.app_label, self.model._meta.model_name
|
info = self.model._meta.app_label, self.model._meta.model_name
|
||||||
|
|
||||||
my_url = [
|
my_url = [
|
||||||
path('export_data_type/', self.export_data_type, name='%s_%s_export_data_type' % info),
|
path(
|
||||||
path('export_data_full/', self.export_data_full, name='%s_%s_export_data_full' % info),
|
"export_data_type/",
|
||||||
path('export_data_federal/', self.export_data_federal, name='%s_%s_export_data_federal' % info),
|
self.export_data_type,
|
||||||
|
name="%s_%s_export_data_type" % info,
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"export_data_full/",
|
||||||
|
self.export_data_full,
|
||||||
|
name="%s_%s_export_data_full" % info,
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"export_data_federal/",
|
||||||
|
self.export_data_federal,
|
||||||
|
name="%s_%s_export_data_federal" % info,
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
return my_url + urlpatterns
|
return my_url + urlpatterns
|
||||||
|
|
|
@ -2,87 +2,99 @@ import csv
|
||||||
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_domains_to_writer(writer, columns, sort_fields, filter_condition):
|
def export_domains_to_writer(writer, columns, sort_fields, filter_condition):
|
||||||
# write columns headers to writer
|
# write columns headers to writer
|
||||||
writer.writerow(columns)
|
writer.writerow(columns)
|
||||||
|
|
||||||
domainInfos = DomainInformation.objects.filter(**filter_condition).order_by(*sort_fields)
|
domainInfos = DomainInformation.objects.filter(**filter_condition).order_by(
|
||||||
|
*sort_fields
|
||||||
|
)
|
||||||
for domainInfo in domainInfos:
|
for domainInfo in domainInfos:
|
||||||
security_contacts = domainInfo.domain.contacts.filter(contact_type=PublicContact.ContactTypeChoices.SECURITY)
|
security_contacts = domainInfo.domain.contacts.filter(
|
||||||
|
contact_type=PublicContact.ContactTypeChoices.SECURITY
|
||||||
|
)
|
||||||
|
|
||||||
# create a dictionary of fields which can be included in output
|
# create a dictionary of fields which can be included in output
|
||||||
FIELDS = {
|
FIELDS = {
|
||||||
'Domain name': domainInfo.domain.name,
|
"Domain name": domainInfo.domain.name,
|
||||||
'Domain type': domainInfo.organization_type,
|
"Domain type": domainInfo.organization_type,
|
||||||
'Federal agency': domainInfo.federal_agency,
|
"Federal agency": domainInfo.federal_agency,
|
||||||
'Organization name': domainInfo.organization_name,
|
"Organization name": domainInfo.organization_name,
|
||||||
'City': domainInfo.city,
|
"City": domainInfo.city,
|
||||||
'State': domainInfo.state_territory,
|
"State": domainInfo.state_territory,
|
||||||
'AO': domainInfo.authorizing_official.first_name + " " + domainInfo.authorizing_official.last_name,
|
"AO": domainInfo.authorizing_official.first_name
|
||||||
'AO email': domainInfo.authorizing_official.email,
|
+ " "
|
||||||
'Submitter': domainInfo.submitter.first_name + " " + domainInfo.submitter.last_name,
|
+ domainInfo.authorizing_official.last_name,
|
||||||
'Submitter title': domainInfo.submitter.title,
|
"AO email": domainInfo.authorizing_official.email,
|
||||||
'Submitter email': domainInfo.submitter.email,
|
"Submitter": domainInfo.submitter.first_name
|
||||||
'Submitter phone': domainInfo.submitter.phone,
|
+ " "
|
||||||
'Security Contact Email': security_contacts[0].email if security_contacts.exists() else " ",
|
+ domainInfo.submitter.last_name,
|
||||||
'Status': domainInfo.domain.state,
|
"Submitter title": domainInfo.submitter.title,
|
||||||
|
"Submitter email": domainInfo.submitter.email,
|
||||||
|
"Submitter phone": domainInfo.submitter.phone,
|
||||||
|
"Security Contact Email": security_contacts[0].email
|
||||||
|
if security_contacts.exists()
|
||||||
|
else " ",
|
||||||
|
"Status": domainInfo.domain.state,
|
||||||
}
|
}
|
||||||
writer.writerow(
|
writer.writerow([FIELDS.get(column, "") for column in columns])
|
||||||
[FIELDS.get(column,'') for column in columns]
|
|
||||||
)
|
|
||||||
|
|
||||||
def export_data_type_to_csv(csv_file):
|
def export_data_type_to_csv(csv_file):
|
||||||
writer = csv.writer(csv_file)
|
writer = csv.writer(csv_file)
|
||||||
# define columns to include in export
|
# define columns to include in export
|
||||||
columns = [
|
columns = [
|
||||||
'Domain name',
|
"Domain name",
|
||||||
'Domain type',
|
"Domain type",
|
||||||
'Federal agency',
|
"Federal agency",
|
||||||
'Organization name',
|
"Organization name",
|
||||||
'City',
|
"City",
|
||||||
'State',
|
"State",
|
||||||
'AO',
|
"AO",
|
||||||
'AO email',
|
"AO email",
|
||||||
'Submitter',
|
"Submitter",
|
||||||
'Submitter title',
|
"Submitter title",
|
||||||
'Submitter email',
|
"Submitter email",
|
||||||
'Submitter phone',
|
"Submitter phone",
|
||||||
'Security Contact Email',
|
"Security Contact Email",
|
||||||
'Status',
|
"Status",
|
||||||
# 'Expiration Date'
|
# 'Expiration Date'
|
||||||
]
|
]
|
||||||
sort_fields = ['domain__name']
|
sort_fields = ["domain__name"]
|
||||||
filter_condition = {}
|
filter_condition = {}
|
||||||
export_domains_to_writer(writer, columns, sort_fields, filter_condition)
|
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)
|
||||||
# define columns to include in export
|
# define columns to include in export
|
||||||
columns = [
|
columns = [
|
||||||
'Domain name',
|
"Domain name",
|
||||||
'Domain type',
|
"Domain type",
|
||||||
'Federal agency',
|
"Federal agency",
|
||||||
'Organization name',
|
"Organization name",
|
||||||
'City',
|
"City",
|
||||||
'State',
|
"State",
|
||||||
'Security Contact Email',
|
"Security Contact Email",
|
||||||
]
|
]
|
||||||
sort_fields = ['domain__name', 'federal_agency', 'organization_type']
|
sort_fields = ["domain__name", "federal_agency", "organization_type"]
|
||||||
filter_condition = {}
|
filter_condition = {}
|
||||||
export_domains_to_writer(writer, columns, sort_fields, filter_condition)
|
export_domains_to_writer(writer, columns, sort_fields, filter_condition)
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
# define columns to include in export
|
# define columns to include in export
|
||||||
columns = [
|
columns = [
|
||||||
'Domain name',
|
"Domain name",
|
||||||
'Domain type',
|
"Domain type",
|
||||||
'Federal agency',
|
"Federal agency",
|
||||||
'Organization name',
|
"Organization name",
|
||||||
'City',
|
"City",
|
||||||
'State',
|
"State",
|
||||||
'Security Contact Email',
|
"Security Contact Email",
|
||||||
]
|
]
|
||||||
sort_fields = ['domain__name', 'federal_agency', 'organization_type']
|
sort_fields = ["domain__name", "federal_agency", "organization_type"]
|
||||||
filter_condition = {'organization_type__icontains': 'federal'}
|
filter_condition = {"organization_type__icontains": "federal"}
|
||||||
export_domains_to_writer(writer, columns, sort_fields, filter_condition)
|
export_domains_to_writer(writer, columns, sort_fields, filter_condition)
|
Loading…
Add table
Add a link
Reference in a new issue