Skip to content

Commit

Permalink
Merge branch 'develop' into Smithh-Co-patch-3
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-jameson authored Oct 12, 2023
2 parents 93d8829 + 281cad7 commit d660863
Show file tree
Hide file tree
Showing 4 changed files with 95 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, ParserError
from django.conf import settings
from django.utils.html import format_html

DOMAIN = settings.FRONTEND_BASE_URL

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)
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

def error_report_link(self, obj):
"""Return the link to the error report."""
pe_len = ParserError.objects.filter(file=obj).count()

filtered_parserror_list_url = f'{DOMAIN}/admin/parsers/parsererror/?file=' + str(obj.id)
# have to find the error id from obj
return format_html("<a href='{url}'>{field}</a>",
field="Parser Errors: " + str(pe_len),
url=filtered_parserror_list_url)

error_report_link.allow_tags = True

def data_file_summary(self, obj):
"""Return the data file summary."""
df = DataFileSummary.objects.get(datafile=obj)
return format_html("<a href='{url}'>{field}</a>",
field=f'{df.id}' + ":" + df.get_status(),
url=f"{DOMAIN}/admin/parsers/datafilesummary/{df.id}/change/")

list_display = [
'id',
'stt',
'year',
'quarter',
'section',
'version',
'data_file_summary',
'error_report_link',
]

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

@admin.register(LegacyFileTransfer)
Expand Down
14 changes: 14 additions & 0 deletions tdrs-backend/tdpservice/data_files/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
22 changes: 22 additions & 0 deletions tdrs-backend/tdpservice/data_files/test/test_admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Test DataFileAdmin methods."""
import pytest
from django.contrib.admin.sites import AdminSite

from tdpservice.data_files.admin import DataFileAdmin
from tdpservice.data_files.models import DataFile
from tdpservice.data_files.test.factories import DataFileFactory
from tdpservice.parsers.test.factories import DataFileSummaryFactory
from django.conf import settings

@pytest.mark.django_db
def test_DataFileAdmin_status():
"""Test DataFileAdmin status method."""
data_file = DataFileFactory()
data_file_summary = DataFileSummaryFactory(datafile=data_file)
data_file_admin = DataFileAdmin(DataFile, AdminSite())

assert data_file_admin.status(data_file) == data_file_summary.status
assert data_file_admin.case_totals(data_file) == data_file_summary.case_aggregates
DOMAIN = settings.FRONTEND_BASE_URL
assert data_file_admin.error_report_link(data_file) == \
f"<a href='{DOMAIN}/admin/parsers/parsererror/?file={data_file.id}'>Parser Errors: 0</a>"
4 changes: 3 additions & 1 deletion tdrs-frontend/cypress/e2e/accounts/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ Then('{string} sees a Request Access form', (username) => {

Then('{string} can see the hompage', (username) => {
cy.visit('/home')
cy.contains('You have been approved for access to TDP.').should('exist')
cy.wait(2000).then(() => {
cy.contains('You have been approved for access to TDP.').should('exist')
})
})

When('{string} is in begin state', (username) => {
Expand Down

0 comments on commit d660863

Please sign in to comment.