mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-05 17:28:31 +02:00
Minor refactor
This commit is contained in:
parent
f347ff9c7f
commit
728a248d91
2 changed files with 24 additions and 13 deletions
|
@ -108,7 +108,7 @@ class BaseExport(ABC):
|
|||
return Q()
|
||||
|
||||
@classmethod
|
||||
def get_filter_conditions(cls, request=None, start_date=None, end_date=None):
|
||||
def get_filter_conditions(cls, **export_kwargs):
|
||||
"""
|
||||
Get a Q object of filter conditions to filter when building queryset.
|
||||
"""
|
||||
|
@ -144,7 +144,7 @@ class BaseExport(ABC):
|
|||
return queryset
|
||||
|
||||
@classmethod
|
||||
def write_csv_before(cls, csv_writer, start_date=None, end_date=None):
|
||||
def write_csv_before(cls, csv_writer, **export_kwargs):
|
||||
"""
|
||||
Write to csv file before the write_csv method.
|
||||
Override in subclasses where needed.
|
||||
|
@ -191,7 +191,7 @@ class BaseExport(ABC):
|
|||
return cls.update_queryset(queryset, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def export_data_to_csv(cls, csv_file, request=None, start_date=None, end_date=None):
|
||||
def export_data_to_csv(cls, csv_file, **export_kwargs):
|
||||
"""
|
||||
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(request, start_date, end_date)
|
||||
filter_conditions = cls.get_filter_conditions(**export_kwargs)
|
||||
computed_fields = cls.get_computed_fields()
|
||||
related_table_fields = cls.get_related_table_fields()
|
||||
|
||||
|
@ -226,7 +226,7 @@ class BaseExport(ABC):
|
|||
models_dict = convert_queryset_to_dict(annotated_queryset, is_model=False)
|
||||
|
||||
# Write to csv file before the write_csv
|
||||
cls.write_csv_before(writer, start_date, end_date)
|
||||
cls.write_csv_before(writer, **export_kwargs)
|
||||
|
||||
# Write the csv file
|
||||
cls.write_csv(writer, columns, models_dict)
|
||||
|
@ -273,6 +273,11 @@ class DomainExport(BaseExport):
|
|||
Second class in an inheritance tree of 3.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def export_data_to_csv(cls, csv_file, start_date=None, end_date=None):
|
||||
"""Pass in the start_date and end_date variables to the report"""
|
||||
super().export_data_to_csv(csv_file, start_date=start_date, end_date=end_date)
|
||||
|
||||
@classmethod
|
||||
def model(cls):
|
||||
# Return the model class that this export handles
|
||||
|
@ -549,7 +554,12 @@ class DomainDataTypeUser(DomainDataType):
|
|||
"""
|
||||
|
||||
@classmethod
|
||||
def get_filter_conditions(cls, request=None, start_date=None, end_date=None):
|
||||
def export_data_to_csv(cls, csv_file, request=None):
|
||||
"""Pass in the start_date and end_date variables to the report"""
|
||||
super().export_data_to_csv(csv_file, request=request)
|
||||
|
||||
@classmethod
|
||||
def get_filter_conditions(cls, request=None):
|
||||
"""
|
||||
Get a Q object of filter conditions to filter when building queryset.
|
||||
"""
|
||||
|
@ -616,7 +626,7 @@ class DomainDataFull(DomainExport):
|
|||
return ["domain"]
|
||||
|
||||
@classmethod
|
||||
def get_filter_conditions(cls, request=None, start_date=None, end_date=None):
|
||||
def get_filter_conditions(cls):
|
||||
"""
|
||||
Get a Q object of filter conditions to filter when building queryset.
|
||||
"""
|
||||
|
@ -711,7 +721,7 @@ class DomainDataFederal(DomainExport):
|
|||
return ["domain"]
|
||||
|
||||
@classmethod
|
||||
def get_filter_conditions(cls, request=None, start_date=None, end_date=None):
|
||||
def get_filter_conditions(cls):
|
||||
"""
|
||||
Get a Q object of filter conditions to filter when building queryset.
|
||||
"""
|
||||
|
@ -809,7 +819,7 @@ class DomainGrowth(DomainExport):
|
|||
return ["domain"]
|
||||
|
||||
@classmethod
|
||||
def get_filter_conditions(cls, request=None, start_date=None, end_date=None):
|
||||
def get_filter_conditions(cls, start_date=None, end_date=None):
|
||||
"""
|
||||
Get a Q object of filter conditions to filter when building queryset.
|
||||
"""
|
||||
|
@ -881,7 +891,7 @@ class DomainManaged(DomainExport):
|
|||
return ["permissions"]
|
||||
|
||||
@classmethod
|
||||
def get_filter_conditions(cls, request=None, start_date=None, end_date=None):
|
||||
def get_filter_conditions(cls, start_date=None, end_date=None):
|
||||
"""
|
||||
Get a Q object of filter conditions to filter when building queryset.
|
||||
"""
|
||||
|
@ -1016,7 +1026,7 @@ class DomainUnmanaged(DomainExport):
|
|||
return ["permissions"]
|
||||
|
||||
@classmethod
|
||||
def get_filter_conditions(cls, request=None, start_date=None, end_date=None):
|
||||
def get_filter_conditions(cls, start_date=None, end_date=None):
|
||||
"""
|
||||
Get a Q object of filter conditions to filter when building queryset.
|
||||
"""
|
||||
|
@ -1246,7 +1256,7 @@ class DomainRequestGrowth(DomainRequestExport):
|
|||
]
|
||||
|
||||
@classmethod
|
||||
def get_filter_conditions(cls, request=None, start_date=None, end_date=None):
|
||||
def get_filter_conditions(cls, start_date=None, end_date=None):
|
||||
"""
|
||||
Get a Q object of filter conditions to filter when building queryset.
|
||||
"""
|
||||
|
|
|
@ -163,7 +163,7 @@ class ExportDataTypeUser(View):
|
|||
# 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)
|
||||
csv_export.DomainDataTypeUser.export_data_to_csv(response, request=request)
|
||||
return response
|
||||
|
||||
class ExportDataFull(View):
|
||||
|
@ -225,6 +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"'
|
||||
# Note: start_date doesn't appear to be used in the underlying report - is ths intentional?
|
||||
csv_export.DomainManaged.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