Skip to content

Commit

Permalink
404 if file does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
timoballard committed Oct 31, 2023
1 parent a697768 commit 128fef2
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions backend/audit/file_downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@

def get_filename(sac, file_type):
if file_type == "report":
file_obj = SingleAuditReportFile.objects.filter(sac=sac).latest("date_created")
return f"singleauditreport/{file_obj.filename}"
try:
file_obj = SingleAuditReportFile.objects.filter(sac=sac).latest(
"date_created"
)
return f"singleauditreport/{file_obj.filename}"
except SingleAuditReportFile.DoesNotExist:
raise Http404()
else:
file_obj = ExcelFile.objects.filter(sac=sac, form_section=file_type).latest(
"date_created"
)
return f"excel/{file_obj.filename}"
try:
file_obj = ExcelFile.objects.filter(sac=sac, form_section=file_type).latest(
"date_created"
)
return f"excel/{file_obj.filename}"
except ExcelFile.DoesNotExist:
raise Http404()


def file_exists(filename):
Expand Down

0 comments on commit 128fef2

Please sign in to comment.