Skip to content

Commit

Permalink
added the filters for datafile progtype
Browse files Browse the repository at this point in the history
  • Loading branch information
raftmsohani committed Sep 20, 2023
1 parent 40324b4 commit 02f022a
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
56 changes: 56 additions & 0 deletions tdrs-backend/tdpservice/data_files/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,73 @@

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',
'year',
'quarter',
'section',
'version',
'status',
'case_totals',
]

list_filter = [
Expand All @@ -25,6 +79,8 @@ class DataFileAdmin(ReadOnlyAdminMixin, admin.ModelAdmin):
'user',
'year',
'version',
DataFileSummaryStatusFilter,
DataFileSummaryPrgTypeFilter
]

@admin.register(LegacyFileTransfer)
Expand Down
16 changes: 15 additions & 1 deletion tdrs-backend/tdpservice/data_files/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit 02f022a

Please sign in to comment.