Skip to content

Commit 6dffe91

Browse files
committed
Handle session specific report name
1 parent c1e087c commit 6dffe91

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

subjects/models_io.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,16 @@ def export_data(request, code, session_number, model):
4040
return response
4141

4242

43-
def export_report(request, code, report_path):
43+
def export_report(request, report_path, subject_code, session_number=None):
4444
"""
4545
Exports the report in a PDF file that is downloaded in a browser.
4646
4747
:param request: HTTP request
4848
:type request: Request
49-
:param code: code of the subject
50-
:type code: str
49+
:param subject_code: code of the subject
50+
:type subject_code: str
51+
:param session_number: number of the examination session
52+
:type session_number: str
5153
:param report_path: path to the report to be exported
5254
:type report_path: str
5355
:return: HTTP response for the report to be exported
@@ -58,7 +60,10 @@ def export_report(request, code, report_path):
5860
response = HttpResponse(content=open(report_path, 'rb'), content_type='application/pdf')
5961

6062
# Prepare the file name for the attachment
61-
file_name = f'report-{code}.pdf'
63+
if session_number:
64+
file_name = f'report-{subject_code}_session_{session_number}.pdf'
65+
else:
66+
file_name = f'report-{subject_code}.pdf'
6267

6368
# Set the content disposition (to be downloaded by a browser)
6469
response['Content-Disposition'] = f'attachment; filename="{file_name}"'

subjects/views.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ def export_subject_report(request, code):
756756
report_path = create_subject_report(request, Subject.get_subject(code=code))
757757

758758
# Export the report
759-
return export_report(request, code, report_path)
759+
return export_report(request, report_path=report_path, subject_code=code)
760760

761761

762762
def export_session_report(request, code, session_number):
@@ -770,4 +770,4 @@ def export_session_report(request, code, session_number):
770770
report_path = session_subject_report(request, subject, session)
771771

772772
# Export the report
773-
return export_report(request, code, report_path)
773+
return export_report(request, report_path=report_path, subject_code=code, session_number=session_number)

0 commit comments

Comments
 (0)