@@ -40,14 +40,16 @@ def export_data(request, code, session_number, model):
40
40
return response
41
41
42
42
43
- def export_report (request , code , report_path ):
43
+ def export_report (request , report_path , subject_code , session_number = None ):
44
44
"""
45
45
Exports the report in a PDF file that is downloaded in a browser.
46
46
47
47
:param request: HTTP request
48
48
: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
51
53
:param report_path: path to the report to be exported
52
54
:type report_path: str
53
55
:return: HTTP response for the report to be exported
@@ -58,7 +60,10 @@ def export_report(request, code, report_path):
58
60
response = HttpResponse (content = open (report_path , 'rb' ), content_type = 'application/pdf' )
59
61
60
62
# 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'
62
67
63
68
# Set the content disposition (to be downloaded by a browser)
64
69
response ['Content-Disposition' ] = f'attachment; filename="{ file_name } "'
0 commit comments