diff --git a/src/registrar/config/urls.py b/src/registrar/config/urls.py index af44fc237..edfe7619e 100644 --- a/src/registrar/config/urls.py +++ b/src/registrar/config/urls.py @@ -53,9 +53,8 @@ urlpatterns = [ "admin/logout/", RedirectView.as_view(pattern_name="logout", permanent=False), ), - path("admin/", admin.site.urls), - # path('export_data/', export_data, name='admin_export_data'), path('export_data/', ExportData.as_view(), name='admin_export_data'), + path("admin/", admin.site.urls), path( "application//edit/", views.ApplicationWizard.as_view(), diff --git a/src/registrar/forms/admin.py b/src/registrar/forms/admin.py index 78d359743..f0015027d 100644 --- a/src/registrar/forms/admin.py +++ b/src/registrar/forms/admin.py @@ -1,13 +1,5 @@ from django import forms class DataExportForm(forms.Form): - # start_date = forms.DateField(label='Start date', widget=forms.DateInput(attrs={'type': 'date'})) - # end_date = forms.DateField(label='End date', widget=forms.DateInput(attrs={'type': 'date'})) - - security_email = forms.EmailField( - label="Security email (optional)", - required=False, - error_messages={ - "invalid": 'dsas', - }, - ) \ No newline at end of file + start_date = forms.DateField(label='Start date', widget=forms.DateInput(attrs={'type': 'date'})) + end_date = forms.DateField(label='End date', widget=forms.DateInput(attrs={'type': 'date'})) diff --git a/src/registrar/templates/admin/export_data.html b/src/registrar/templates/admin/export_data.html deleted file mode 100644 index 589284c1b..000000000 --- a/src/registrar/templates/admin/export_data.html +++ /dev/null @@ -1,18 +0,0 @@ - -
- {% csrf_token %} - - - {% for field in form %} -
- {{ field.label_tag }} - {{ field }} - {% if field.errors %} -
{{ field.errors|join:", " }}
- {% endif %} -
- {% endfor %} - - - -
\ No newline at end of file diff --git a/src/registrar/templates/admin/index.html b/src/registrar/templates/admin/index.html index 82c881a9e..f74da2891 100644 --- a/src/registrar/templates/admin/index.html +++ b/src/registrar/templates/admin/index.html @@ -6,13 +6,20 @@

Welcome to the Custom Admin Homepage!

- {% comment %} {% include "export_data.html" %} {% endcomment %} + {% comment %} + Inputs of type date suck for accessibility. + We'll need to replace those guys with a django form once we figure out how to hook one onto this page. + The challenge is in the path definition in urls. Itdoes NOT like admin/export_data/ + + {% include "export_data.html" %} + {% endcomment %} + {% comment %} TODO: add a aria label or something {% endcomment %} Export
diff --git a/src/registrar/templates/export_data.html b/src/registrar/templates/export_data.html index 69b00c744..df6111c0d 100644 --- a/src/registrar/templates/export_data.html +++ b/src/registrar/templates/export_data.html @@ -1,8 +1,8 @@ -{% load static field_helpers%}
{% csrf_token %} +

The context test 1: {{ test }}

{% for field in form %}
@@ -14,6 +14,8 @@
{% endfor %} +

The context test 2: {{ test }}

- + +
\ No newline at end of file diff --git a/src/registrar/utility/csv_export.py b/src/registrar/utility/csv_export.py index 5ceb49cd2..563983e3c 100644 --- a/src/registrar/utility/csv_export.py +++ b/src/registrar/utility/csv_export.py @@ -5,6 +5,7 @@ from registrar.models.domain_information import DomainInformation from registrar.models.public_contact import PublicContact from django.db.models import Value from django.db.models.functions import Coalesce +from itertools import chain def export_domains_to_writer(writer, columns, sort_fields, filter_condition): @@ -13,14 +14,20 @@ def export_domains_to_writer(writer, columns, sort_fields, filter_condition): print(f"filter_condition {filter_condition}") + domainInfos = DomainInformation.objects.filter(**filter_condition).order_by(*sort_fields) + if 'domain__created_at__gt' in filter_condition: - domainInfos = DomainInformation.objects.filter(domain__state=Domain.State.DELETED).order_by("domain__deleted_at") + deleted_domainInfos = DomainInformation.objects.filter(domain__state=Domain.State.DELETED).order_by("domain__deleted_at") print(f"filtering by deleted {domainInfos}") + + # Combine the two querysets into a single iterable + all_domainInfos = list(chain(domainInfos, deleted_domainInfos)) else: - domainInfos = DomainInformation.objects.filter(**filter_condition).order_by(*sort_fields) + all_domainInfos = list(domainInfos) + - for domainInfo in domainInfos: + for domainInfo in all_domainInfos: security_contacts = domainInfo.domain.contacts.filter(contact_type=PublicContact.ContactTypeChoices.SECURITY) print(f"regular filtering {domainInfos}") # For linter @@ -153,14 +160,16 @@ def export_data_growth_to_csv(csv_file, start_date, end_date): else: # Handle the case where start_date is missing or empty print('ON NO') + # TODO: use Nov 1 2023 start_date_formatted = None # Replace with appropriate handling if end_date: end_date_formatted = datetime.strptime(end_date, "%Y-%m-%d") - print(f'start_date_formatted {end_date_formatted}') + print(f'end_date_formatted {end_date_formatted}') else: # Handle the case where start_date is missing or empty print('ON NO') + # TODO: use now end_date_formatted = None # Replace with appropriate handling writer = csv.writer(csv_file) @@ -172,11 +181,11 @@ def export_data_growth_to_csv(csv_file, start_date, end_date): "Organization name", "City", "State", - "Security contact email", + "Status", "Created at", + "Deleted at", "Expiration date", ] - # Coalesce is used to replace federal_type of None with ZZZZZ sort_fields = [ "created_at", "domain__name", @@ -186,7 +195,7 @@ def export_data_growth_to_csv(csv_file, start_date, end_date): Domain.State.UNKNOWN, Domain.State.DELETED, ], - "domain__expiration_date__lt": end_date_formatted, + "domain__created_at__lt": end_date_formatted, "domain__created_at__gt": start_date_formatted, } export_domains_to_writer(writer, columns, sort_fields, filter_condition) diff --git a/src/registrar/views/admin_views.py b/src/registrar/views/admin_views.py index 6c6aa6616..83e49954f 100644 --- a/src/registrar/views/admin_views.py +++ b/src/registrar/views/admin_views.py @@ -21,17 +21,20 @@ import logging logger = logging.getLogger(__name__) -def export_data(self): - """CSV download""" - print('VIEW') - # Federal only - response = HttpResponse(content_type="text/csv") - response["Content-Disposition"] = 'attachment; filename="current-federal.csv"' - csv_export.export_data_growth_to_csv(response) - return response class ExportData(View): + template_name = "admin/index.html" + form_class = DataExportForm + + + def get_context_data(self, **kwargs): + print('VIE VIE VIE') + context = super().get_context_data(**kwargs) + context['form'] = self.form_class() + context['test'] = 'testing the context' + return context + def get(self, request, *args, **kwargs): # Get start_date and end_date from the request's GET parameters start_date = request.GET.get('start_date', '') @@ -52,23 +55,5 @@ class ExportData(View): # csv_export.export_data_growth_to_csv(response) return response - - -# class ExportData(TemplateView): -# """Django form""" - -# template_name = "export_data.html" -# form_class = DataExportForm - -# def form_valid(self, form): -# print('Form is valid') -# # Form is valid, perform data export logic here -# return JsonResponse({'message': 'Data exported successfully!'}, content_type='application/json') -# def form_invalid(self, form): -# print('Form is invalid') -# # Form is invalid, return error response -# return JsonResponse({'error': 'Invalid form data'}, status=400, content_type='application/json') - - \ No newline at end of file