diff --git a/tdrs-backend/tdpservice/data_files/admin.py b/tdrs-backend/tdpservice/data_files/admin.py index 1ac5b2b2c..b582c679a 100644 --- a/tdrs-backend/tdpservice/data_files/admin.py +++ b/tdrs-backend/tdpservice/data_files/admin.py @@ -3,12 +3,64 @@ from ..core.utils import ReadOnlyAdminMixin from .models import DataFile, LegacyFileTransfer +from tdpservice.parsers.models import DataFileSummary +class DataFileSummaryStatusFilter(admin.SimpleListFilter): + """Admin class filter for file status (accepted, rejected) for datafile model""" + + title = 'status' + parameter_name = 'status' + + def lookups(self, request, model_admin): + """Return a list of tuples.""" + return [ + ('Accepted', 'Accepted'), + ('Rejected', 'Rejected'), + ] + + def queryset(self, request, queryset): + """Return a queryset.""" + if self.value(): + return queryset.filter(datafilesummary__status=self.value()) + else: + 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(): + query_set_ids = [df.id for df in queryset if df.prog_type==self.value()] + return queryset.filter(id__in=query_set_ids) + #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', @@ -16,6 +68,8 @@ class DataFileAdmin(ReadOnlyAdminMixin, admin.ModelAdmin): 'quarter', 'section', 'version', + 'status', + 'case_totals', ] list_filter = [ @@ -25,6 +79,8 @@ class DataFileAdmin(ReadOnlyAdminMixin, admin.ModelAdmin): 'user', 'year', 'version', + DataFileSummaryStatusFilter, + DataFileSummaryPrgTypeFilter ] @admin.register(LegacyFileTransfer) diff --git a/tdrs-backend/tdpservice/data_files/models.py b/tdrs-backend/tdpservice/data_files/models.py index b4248a9cd..fc4f80de6 100644 --- a/tdrs-backend/tdpservice/data_files/models.py +++ b/tdrs-backend/tdpservice/data_files/models.py @@ -151,7 +151,21 @@ class Meta: blank=False, 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."""