From dac145f9c5f3169d255117fb75741803ae8cd80d Mon Sep 17 00:00:00 2001 From: thremilien Date: Fri, 23 Aug 2024 10:17:09 +0000 Subject: [PATCH 1/3] download file, had to remove the 'file display' for non pdf --- inginious/frontend/pages/tasks.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/inginious/frontend/pages/tasks.py b/inginious/frontend/pages/tasks.py index 6515465c7..89f3ad587 100644 --- a/inginious/frontend/pages/tasks.py +++ b/inginious/frontend/pages/tasks.py @@ -80,16 +80,16 @@ def GET(self, courseid, taskid, is_LTI): previous_taskid = None next_taskid = None else: - # Compute previous and next taskid index = ordered_task_list.index(taskid) previous_taskid = ordered_task_list[index - 1] if index > 0 else None next_taskid = ordered_task_list[index + 1] if index < len(ordered_task_list) - 1 else None self.user_manager.user_saw_task(username, courseid, taskid) - userinput = flask.request.args if "submissionid" in userinput and "questionid" in userinput: + print("Là ça télécharge") + # Download a previously submitted file submission = self.submission_manager.get_submission(userinput["submissionid"], user_check=not is_staff) if submission is None: @@ -98,14 +98,23 @@ def GET(self, courseid, taskid, is_LTI): if userinput["questionid"] not in sinput: raise NotFound() - if isinstance(sinput[userinput["questionid"]], dict): - # File uploaded previously + file_data = sinput[userinput["questionid"]] + if isinstance(file_data, dict): + filename = file_data['filename'] + file_content = file_data['value'] mimetypes.init() - mime_type = mimetypes.guess_type(urllib.request.pathname2url(sinput[userinput["questionid"]]['filename'])) - return Response(response=sinput[userinput["questionid"]]['value'], content_type=mime_type[0]) + mime_type = mimetypes.guess_type(urllib.request.pathname2url(filename)) + + # Forcer le téléchargement pour les fichiers non-PDF + if not filename.lower().endswith(".pdf"): + headers = { + 'Content-Disposition': f'attachment; filename="{filename}"' + } + return Response(response=file_content, content_type=mime_type[0], headers=headers) + + return Response(response=file_content, content_type=mime_type[0]) else: - # Other file, download it as text - return Response(response=sinput[userinput["questionid"]], content_type='text/plain') + return Response(response=file_data, content_type='text/plain') else: # Generate random inputs and save it into db random.seed(str(username if username is not None else "") + taskid + courseid + str( From 782c85c466047c1e3c6ec72ad503a969abd27838 Mon Sep 17 00:00:00 2001 From: thremilien Date: Fri, 23 Aug 2024 13:19:46 +0000 Subject: [PATCH 2/3] remove file preview for non pdf file + remove test print + comment translation --- inginious/frontend/pages/tasks.py | 3 +-- inginious/frontend/static/js/task.js | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/inginious/frontend/pages/tasks.py b/inginious/frontend/pages/tasks.py index 89f3ad587..067a8183c 100644 --- a/inginious/frontend/pages/tasks.py +++ b/inginious/frontend/pages/tasks.py @@ -88,7 +88,6 @@ def GET(self, courseid, taskid, is_LTI): userinput = flask.request.args if "submissionid" in userinput and "questionid" in userinput: - print("Là ça télécharge") # Download a previously submitted file submission = self.submission_manager.get_submission(userinput["submissionid"], user_check=not is_staff) @@ -105,7 +104,7 @@ def GET(self, courseid, taskid, is_LTI): mimetypes.init() mime_type = mimetypes.guess_type(urllib.request.pathname2url(filename)) - # Forcer le téléchargement pour les fichiers non-PDF + # Force download for non pdf files if not filename.lower().endswith(".pdf"): headers = { 'Content-Disposition': f'attachment; filename="{filename}"' diff --git a/inginious/frontend/static/js/task.js b/inginious/frontend/static/js/task.js index d469ac499..556441d43 100644 --- a/inginious/frontend/static/js/task.js +++ b/inginious/frontend/static/js/task.js @@ -762,7 +762,7 @@ function load_input_file(submissionid, key, input) var input_file = $('#download-input-file-' + key); input_file.attr('href', url ); input_file.css('display', 'block'); - if(allowed_exts.indexOf(".pdf") >= 0) { + if(input[key]["filename"].endsWith('.pdf')) { var input_file_pdf = $('#download-input-file-pdf-' + key); input_file_pdf.attr('data', url); input_file_pdf.find("embed").attr("src", url); From 286b0ec9c9f7525b1c2ed8bc3cd9c3ff0b090cb6 Mon Sep 17 00:00:00 2001 From: thremilien Date: Fri, 23 Aug 2024 13:27:35 +0000 Subject: [PATCH 3/3] add unintentionally removed comment --- inginious/frontend/pages/tasks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/inginious/frontend/pages/tasks.py b/inginious/frontend/pages/tasks.py index 067a8183c..ebefc04ed 100644 --- a/inginious/frontend/pages/tasks.py +++ b/inginious/frontend/pages/tasks.py @@ -80,6 +80,7 @@ def GET(self, courseid, taskid, is_LTI): previous_taskid = None next_taskid = None else: + # Compute previous and next taskid index = ordered_task_list.index(taskid) previous_taskid = ordered_task_list[index - 1] if index > 0 else None next_taskid = ordered_task_list[index + 1] if index < len(ordered_task_list) - 1 else None