From af4926198fd36fb1f0e7379466ed5b24a9c08af2 Mon Sep 17 00:00:00 2001 From: Mo Sohani Date: Thu, 14 Sep 2023 09:15:45 -0400 Subject: [PATCH] added filter for data_file --- tdrs-backend/tdpservice/data_files/admin.py | 38 ++++++++++++++++++-- tdrs-backend/tdpservice/data_files/models.py | 14 ++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/tdrs-backend/tdpservice/data_files/admin.py b/tdrs-backend/tdpservice/data_files/admin.py index 42d7cce44..22ef2e10c 100644 --- a/tdrs-backend/tdpservice/data_files/admin.py +++ b/tdrs-backend/tdpservice/data_files/admin.py @@ -3,8 +3,9 @@ from ..core.utils import ReadOnlyAdminMixin from .models import DataFile, LegacyFileTransfer +from tdpservice.parsers.models import DataFileSummary -class DataFileSummaryListFilter(admin.SimpleListFilter): +class DataFileSummaryStatusFilter(admin.SimpleListFilter): """Admin class filter for file status (accepted, rejected) for datafile model""" title = 'status' @@ -25,10 +26,40 @@ def queryset(self, request, queryset): return queryset +class DataFileSummaryPrgTypeFilter(admin.SimpleListFilter): + """Admin class filter for Program Type on datafile model.""" + + title = 'Program Type' + parameter_name = 'program_type' + + def lookups(self, request, model_admin): + """Return a list of tuples.""" + return [ + ('TAN', 'TAN'), + ('SSP', 'SSP'), + ] + + def queryset(self, request, queryset): + """Return a queryset.""" + if self.value(): + return queryset.filter(prog_type=self.value()) + else: + return queryset + + @admin.register(DataFile) class DataFileAdmin(ReadOnlyAdminMixin, admin.ModelAdmin): """Admin class for DataFile models.""" + def status(self, obj): + """Return the status of the data file summary.""" + return DataFileSummary.objects.get(datafile=obj).status + + def case_totals(self, obj): + """Return the case totals.""" + return DataFileSummary.objects.get(datafile=obj).case_aggregates + + list_display = [ 'id', 'stt', @@ -36,6 +67,8 @@ class DataFileAdmin(ReadOnlyAdminMixin, admin.ModelAdmin): 'quarter', 'section', 'version', + 'status', + 'case_totals', ] list_filter = [ @@ -45,7 +78,8 @@ class DataFileAdmin(ReadOnlyAdminMixin, admin.ModelAdmin): 'user', 'year', 'version', - DataFileSummaryListFilter + DataFileSummaryStatusFilter, + DataFileSummaryPrgTypeFilter ] @admin.register(LegacyFileTransfer) diff --git a/tdrs-backend/tdpservice/data_files/models.py b/tdrs-backend/tdpservice/data_files/models.py index 9a954122c..e9bfd5207 100644 --- a/tdrs-backend/tdpservice/data_files/models.py +++ b/tdrs-backend/tdpservice/data_files/models.py @@ -152,6 +152,20 @@ class Meta: null=True ) + @property + def prog_type(self): + """Return the program type for a given section.""" + # e.g., 'SSP Closed Case Data' + if self.section.startswith('SSP'): + return 'SSP' + elif self.section.startswith('Tribal'): + return 'TAN' # problematic, do we need to infer tribal entirely from tribe/fips code? + else: + return 'TAN' + + # TODO: if given a datafile (section), we can reverse back to the program b/c the + # section string has "tribal/ssp" in it, then process of elimination we have tanf + @property def filename(self): """Return the correct filename for this data file."""