Skip to content

Commit

Permalink
- Updated function to prioritize querset based on file section
Browse files Browse the repository at this point in the history
- added secton check to download view
  • Loading branch information
elipe17 committed Dec 17, 2024
1 parent ae340de commit e21fc21
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 8 additions & 1 deletion tdrs-backend/tdpservice/data_files/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ParserErrorCategoryChoices(models.TextChoices):
HISTORICAL_CONSISTENCY = "6", _("Historical consistency")


def get_prioritized_queryset(parser_errors):
def get_prioritized_queryset(parser_errors, is_s3_s4):
"""Generate a prioritized queryset of ParserErrors."""
PRIORITIZED_CAT2 = (
("FAMILY_AFFILIATION", "CITIZENSHIP_STATUS", "CLOSURE_REASON"),
Expand All @@ -42,6 +42,13 @@ def get_prioritized_queryset(parser_errors):
Q(error_type=ParserErrorCategoryChoices.CASE_CONSISTENCY)
filtered_errors = parser_errors.filter(error_type_query)

# If we are a Stratum or Aggregate file, we want all cat2 and cat3 errors.
if is_s3_s4:
all_cat2_cat3 = Q(error_type=ParserErrorCategoryChoices.FIELD_VALUE) | \
Q(error_type=ParserErrorCategoryChoices.VALUE_CONSISTENCY)
filtered_errors = filtered_errors.union(parser_errors.filter(all_cat2_cat3))
return filtered_errors

for fields in PRIORITIZED_CAT2:
filtered_errors = filtered_errors.union(parser_errors.filter(
field_name__in=fields,
Expand Down
4 changes: 3 additions & 1 deletion tdrs-backend/tdpservice/data_files/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ def download_error_report(self, request, pk=None):
"""Generate and return the parsing error report xlsx."""
datafile = self.get_object()
all_errors = ParserError.objects.filter(file=datafile)
filtered_errors = get_prioritized_queryset(all_errors)
is_s3_s4 = (DataFile.Section.STRATUM_DATA in datafile.section or
DataFile.Section.AGGREGATE_DATA in datafile.section)
filtered_errors = get_prioritized_queryset(all_errors, is_s3_s4)

return Response(get_xls_serialized_file(all_errors, filtered_errors))

Expand Down

0 comments on commit e21fc21

Please sign in to comment.