mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-14 16:47:02 +02:00
Add endpoint for report
This commit is contained in:
parent
b331f61d0d
commit
f347ff9c7f
4 changed files with 43 additions and 16 deletions
|
@ -19,6 +19,7 @@ from registrar.views.admin_views import (
|
|||
ExportDataUnmanagedDomains,
|
||||
AnalyticsView,
|
||||
ExportDomainRequestDataFull,
|
||||
ExportDataTypeUser,
|
||||
)
|
||||
|
||||
from registrar.views.domain_request import Step
|
||||
|
@ -119,6 +120,11 @@ urlpatterns = [
|
|||
name="analytics",
|
||||
),
|
||||
path("admin/", admin.site.urls),
|
||||
path(
|
||||
"reports/export_data_type_user/",
|
||||
ExportDataTypeUser.as_view(),
|
||||
name="export_data_type_user",
|
||||
),
|
||||
path(
|
||||
"domain-request/<id>/edit/",
|
||||
views.DomainRequestWizard.as_view(),
|
||||
|
|
|
@ -40,15 +40,13 @@
|
|||
</section>
|
||||
-->
|
||||
|
||||
<!-- Note: Uncomment below when this is being implemented post-MVP -->
|
||||
<!-- <section class="tablet:grid-col-11 desktop:grid-col-10">
|
||||
<section class="tablet:grid-col-11 desktop:grid-col-10">
|
||||
<h2 class="padding-top-1 mobile-lg:padding-top-3"> Export domains</h2>
|
||||
<p>Download a list of your domains and their statuses as a csv file.</p>
|
||||
<a href="{% url 'todo' %}" class="usa-button usa-button--outline">
|
||||
Export domains as csv
|
||||
</a>
|
||||
</section>
|
||||
-->
|
||||
|
||||
{% endblock %}
|
||||
</div>
|
||||
|
|
|
@ -108,7 +108,7 @@ class BaseExport(ABC):
|
|||
return Q()
|
||||
|
||||
@classmethod
|
||||
def get_filter_conditions(cls, start_date=None, end_date=None):
|
||||
def get_filter_conditions(cls, request=None, start_date=None, end_date=None):
|
||||
"""
|
||||
Get a Q object of filter conditions to filter when building queryset.
|
||||
"""
|
||||
|
@ -191,7 +191,7 @@ class BaseExport(ABC):
|
|||
return cls.update_queryset(queryset, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def export_data_to_csv(cls, csv_file, start_date=None, end_date=None):
|
||||
def export_data_to_csv(cls, csv_file, request=None, start_date=None, end_date=None):
|
||||
"""
|
||||
All domain metadata:
|
||||
Exports domains of all statuses plus domain managers.
|
||||
|
@ -204,7 +204,7 @@ class BaseExport(ABC):
|
|||
prefetch_related = cls.get_prefetch_related()
|
||||
exclusions = cls.get_exclusions()
|
||||
annotations_for_sort = cls.get_annotations_for_sort()
|
||||
filter_conditions = cls.get_filter_conditions(start_date, end_date)
|
||||
filter_conditions = cls.get_filter_conditions(request, start_date, end_date)
|
||||
computed_fields = cls.get_computed_fields()
|
||||
related_table_fields = cls.get_related_table_fields()
|
||||
|
||||
|
@ -543,6 +543,21 @@ class DomainDataType(DomainExport):
|
|||
"federal_agency__agency",
|
||||
]
|
||||
|
||||
class DomainDataTypeUser(DomainDataType):
|
||||
"""
|
||||
The DomainDataType report, but sliced on the current request user
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def get_filter_conditions(cls, request=None, start_date=None, end_date=None):
|
||||
"""
|
||||
Get a Q object of filter conditions to filter when building queryset.
|
||||
"""
|
||||
user_domain_roles = UserDomainRole.objects.filter(user=request.user)
|
||||
domain_ids = user_domain_roles.values_list("domain_id", flat=True)
|
||||
return Q(id__in=domain_ids)
|
||||
|
||||
|
||||
|
||||
class DomainDataFull(DomainExport):
|
||||
"""
|
||||
|
@ -601,7 +616,7 @@ class DomainDataFull(DomainExport):
|
|||
return ["domain"]
|
||||
|
||||
@classmethod
|
||||
def get_filter_conditions(cls, start_date=None, end_date=None):
|
||||
def get_filter_conditions(cls, request=None, start_date=None, end_date=None):
|
||||
"""
|
||||
Get a Q object of filter conditions to filter when building queryset.
|
||||
"""
|
||||
|
@ -696,7 +711,7 @@ class DomainDataFederal(DomainExport):
|
|||
return ["domain"]
|
||||
|
||||
@classmethod
|
||||
def get_filter_conditions(cls, start_date=None, end_date=None):
|
||||
def get_filter_conditions(cls, request=None, start_date=None, end_date=None):
|
||||
"""
|
||||
Get a Q object of filter conditions to filter when building queryset.
|
||||
"""
|
||||
|
@ -794,7 +809,7 @@ class DomainGrowth(DomainExport):
|
|||
return ["domain"]
|
||||
|
||||
@classmethod
|
||||
def get_filter_conditions(cls, start_date=None, end_date=None):
|
||||
def get_filter_conditions(cls, request=None, start_date=None, end_date=None):
|
||||
"""
|
||||
Get a Q object of filter conditions to filter when building queryset.
|
||||
"""
|
||||
|
@ -866,7 +881,7 @@ class DomainManaged(DomainExport):
|
|||
return ["permissions"]
|
||||
|
||||
@classmethod
|
||||
def get_filter_conditions(cls, start_date=None, end_date=None):
|
||||
def get_filter_conditions(cls, request=None, start_date=None, end_date=None):
|
||||
"""
|
||||
Get a Q object of filter conditions to filter when building queryset.
|
||||
"""
|
||||
|
@ -1001,7 +1016,7 @@ class DomainUnmanaged(DomainExport):
|
|||
return ["permissions"]
|
||||
|
||||
@classmethod
|
||||
def get_filter_conditions(cls, start_date=None, end_date=None):
|
||||
def get_filter_conditions(cls, request=None, start_date=None, end_date=None):
|
||||
"""
|
||||
Get a Q object of filter conditions to filter when building queryset.
|
||||
"""
|
||||
|
@ -1231,7 +1246,7 @@ class DomainRequestGrowth(DomainRequestExport):
|
|||
]
|
||||
|
||||
@classmethod
|
||||
def get_filter_conditions(cls, start_date=None, end_date=None):
|
||||
def get_filter_conditions(cls, request=None, start_date=None, end_date=None):
|
||||
"""
|
||||
Get a Q object of filter conditions to filter when building queryset.
|
||||
"""
|
||||
|
|
|
@ -157,6 +157,14 @@ class ExportDataType(View):
|
|||
csv_export.DomainDataType.export_data_to_csv(response)
|
||||
return response
|
||||
|
||||
class ExportDataTypeUser(View):
|
||||
"""Returns a domain report for a given user on the request"""
|
||||
def get(self, request, *args, **kwargs):
|
||||
# match the CSV example with all the fields
|
||||
response = HttpResponse(content_type="text/csv")
|
||||
response["Content-Disposition"] = 'attachment; filename="your-domains.csv"'
|
||||
csv_export.DomainDataTypeUser.export_data_to_csv(response, request)
|
||||
return response
|
||||
|
||||
class ExportDataFull(View):
|
||||
def get(self, request, *args, **kwargs):
|
||||
|
@ -194,7 +202,7 @@ class ExportDataDomainsGrowth(View):
|
|||
|
||||
response = HttpResponse(content_type="text/csv")
|
||||
response["Content-Disposition"] = f'attachment; filename="domain-growth-report-{start_date}-to-{end_date}.csv"'
|
||||
csv_export.DomainGrowth.export_data_to_csv(response, start_date, end_date)
|
||||
csv_export.DomainGrowth.export_data_to_csv(response, start_date=start_date, end_date=end_date)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -206,7 +214,7 @@ class ExportDataRequestsGrowth(View):
|
|||
|
||||
response = HttpResponse(content_type="text/csv")
|
||||
response["Content-Disposition"] = f'attachment; filename="requests-{start_date}-to-{end_date}.csv"'
|
||||
csv_export.DomainRequestGrowth.export_data_to_csv(response, start_date, end_date)
|
||||
csv_export.DomainRequestGrowth.export_data_to_csv(response, start_date=start_date, end_date=end_date)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -217,7 +225,7 @@ class ExportDataManagedDomains(View):
|
|||
end_date = request.GET.get("end_date", "")
|
||||
response = HttpResponse(content_type="text/csv")
|
||||
response["Content-Disposition"] = f'attachment; filename="managed-domains-{start_date}-to-{end_date}.csv"'
|
||||
csv_export.DomainManaged.export_data_to_csv(response, start_date, end_date)
|
||||
csv_export.DomainManaged.export_data_to_csv(response, start_date=start_date, end_date=end_date)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -228,6 +236,6 @@ class ExportDataUnmanagedDomains(View):
|
|||
end_date = request.GET.get("end_date", "")
|
||||
response = HttpResponse(content_type="text/csv")
|
||||
response["Content-Disposition"] = f'attachment; filename="unmanaged-domains-{start_date}-to-{end_date}.csv"'
|
||||
csv_export.DomainUnmanaged.export_data_to_csv(response, start_date, end_date)
|
||||
csv_export.DomainUnmanaged.export_data_to_csv(response, start_date=start_date, end_date=end_date)
|
||||
|
||||
return response
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue