mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-16 01:27:03 +02:00
refactored some for separation of concerns, and fixing permissions in template
This commit is contained in:
parent
5fe2827565
commit
e4b3706d9c
3 changed files with 74 additions and 59 deletions
|
@ -1,4 +1,3 @@
|
|||
import csv
|
||||
import logging
|
||||
from django import forms
|
||||
from django.http import HttpResponse
|
||||
|
@ -11,8 +10,8 @@ from django.http.response import HttpResponseRedirect
|
|||
from django.urls import reverse
|
||||
from epplibwrapper.errors import ErrorCode, RegistryError
|
||||
from registrar.models.domain import Domain
|
||||
from registrar.models.domain_information import DomainInformation
|
||||
from registrar.models.utility.admin_sort_fields import AdminSortFields
|
||||
from registrar.utility import csv_export
|
||||
from . import models
|
||||
from auditlog.models import LogEntry # type: ignore
|
||||
from auditlog.admin import LogEntryAdmin # type: ignore
|
||||
|
@ -757,73 +756,21 @@ class DomainAdmin(ListHeaderAdmin):
|
|||
# match the CSV example with all the fields
|
||||
response = HttpResponse(content_type='text/csv')
|
||||
response['Content-Disposition'] = 'attachment; filename="data_export.csv"'
|
||||
writer = csv.writer(response)
|
||||
# Write your data to the CSV here
|
||||
writer.writerow(
|
||||
[
|
||||
'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():
|
||||
domain_information, _ = DomainInformation.objects.get_or_create(domain=domain)
|
||||
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,
|
||||
domain.security_contact.email if domain.security_contact else " ",
|
||||
domain.state,
|
||||
# domain.expiration_date,
|
||||
]
|
||||
) # Include the appropriate fields
|
||||
csv_export.export_data_type_to_csv(response)
|
||||
return response
|
||||
|
||||
|
||||
def export_data_full(self, request):
|
||||
# Smaller export based on 1
|
||||
response = HttpResponse(content_type='text/csv')
|
||||
response['Content-Disposition'] = 'attachment; filename="data_export.csv"'
|
||||
writer = csv.writer(response)
|
||||
# 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
|
||||
csv_export.export_data_full_to_csv(response)
|
||||
return response
|
||||
|
||||
def export_data_federal(self, request):
|
||||
# Federal only
|
||||
response = HttpResponse(content_type='text/csv')
|
||||
response['Content-Disposition'] = 'attachment; filename="data_export.csv"'
|
||||
writer = csv.writer(response)
|
||||
# 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
|
||||
csv_export.export_data_federal_to_csv(response)
|
||||
return response
|
||||
|
||||
def get_urls(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue